I am using Laravel framework (PHP) - I can able to create issue or task using Rest API V3 and its created successfully, but when try to add the attachment for that particular issue or task using [ISSUE-KEY] i can't able to attache the files. In the API Reference documentation there is no proper sample codes. I am using CURL to attach or create the issue.
Can anyone please suggest me to get this done. Below having my code
$ch= curl_init ();
$username = "XXXX-XXX-XXX" ;
$pasword = "*********";
$path = "filepath.txt";
$url = 'https://domainname.atlassian.net/rest/api/3/issue/'.$result['key'].'/attachments';
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, ['file'=>'@'.realpath($path) ]);
curl_setopt ( $ch, CURLOPT_POST, 1 );
$headers = array ();
$headers [] = 'X-Atlassian-Token: no-check';
curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers );
curl_setopt ( $ch, CURLOPT_USERPWD, $username . ":" . $password );
$Arr = [];
$resultt = curl_exec ( $ch);
Thanks for your suggesstion Ravi Sagar. Will convert above CURL to PHP and let me try.
You have to use the multipart/form-data for sending the file. I once wrote a small Drupal module to upload files in Jira but I can't find a simple php example. However let me share my shell script.
#! /bin/bash
$JIRATUTORIAL_AUTH="sfhskfskdfgwiurgwe"
curl -s -i -X POST \ -H "Authorization:Basic $JIRATUTORIAL_AUTH" \ -H "X-Atlassian-Token:no-check" \ -F "file=@/home/ravisagar/jiraissues.csv" \ 'https://jirawhatever.atlassian.net/rest/api/3/issue/an-233/attachments' \
Try this in your shell and if it works then hopefully you will get an idea about what headers to pass. I believe there should be libraries in PHP to do this for you (my PHP skills are fading :( sorry).
I hope it helps.
Ravi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.