I have spent countless hours trying to get the Attachment Resource API(s) to work with no avail. I have referred to the docs here: http://docs.getzephyr.apiary.io/#executionresourceapis
But they are not much help and Zephyr support has not responded to any of my questions in the last 3 months.
Here is my curl call:
curl -D- -u user:pass -X POST -H "Content-Type: multipart/form-data" -H "X- Atlassian-Token: nocheck" -F "file=/home/jared/apiautomation/output.html" "https://jiraurl/rest/zapi/latest/attachment?entityId=3019&entityType=execution"
I have also tried php:
<?php
$url = "http://jiraurl/rest/zapi/latest/attachment?entityId=3091&entityType=execution";
$upass="";
$curl = curl_init();
curl_setopt($curl, CURLOPT_USERPWD, $upass);
$file_name_with_full_path = realpath("/home/jared/postman/authentication/output.html");
$post = array("file=#.$file_name_with_full_path; filename=output.html;");
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('X-Atlassian-Token: nocheck'));
$response = curl_exec($curl);
curl_close ($curl);
?>
for both examples i get unsupported media type. which doesnt make sense because I can attach it through Jira. Im completely lost at this point. Ive referenced:
https://answers.atlassian.com/questions/268253/add-attachment-to-test-execution-using-zapi
Please help. :)
This was answered on Atlassian Answers but here is a copy for this question here.
1) entityType
This is the item you will be attaching to. Currently the only types are 'Execution' and 'TestStepResult'
2) entityId
This is the actual Id of the item whose type you chose. If it is an Execution type, you will need a 'scheduleId'. If it is a TestStepResult, you will need a 'testStepId'
The CURL for adding an attachment via ZAPI is formatted as:
curl -D- -u : -X POST -H "X-Atlassian-Token: nocheck" -F "file=#name_map.jpg" "http://192.168.100.144:9122/rest/zapi/latest/attachment?entityId=&entityType="
Note: "X-Atlassian-Token: nocheck" is required
For sample code in Python of attaching to a entity of type 'Execution', please see our Community Forum post here:
http://community.yourzephyr.com/viewtopic.php?f=21&t=1382
Regards
Related
we have an API existing with a distributor.
Our software is running under PHP 7.3.6 / Apache 2.4.38
We already successfully did some other actions: creating new purchase orders, retrieving orders, ...
We have a problem to retrieve invoices.
We are using for our API tests a software called POSTMAN.
We input all the informations (api key, ....)
Using POSTMAN, it works perfectly. There is an option in POSTMAN to obtain the code in different langage. For our needs, we took the PHP generated code. The problem is that it is not working.
We also used https://reqbin.com/curl and it works perfectly. But same problem, the generated code in PHP is not working.
For example, in postman or reqbin, this CURL code is working
curl -X GET https://url.com/Invoices?startDate="01-01-2019"&endDate="01-31-2023" \
-H 'Accept: application/json' \
-H 'Authorization: Bearer generatedtokenzzzzzzzzzzzzzzzzzzzzzzzzzzz' \
-H 'Content-Type: application/json' \
-H 'zzzzzzzzz-API-Key: generatedapikeyzzzzzzzzzzzzzz'
when we click on generate PHP code we have this code:
<?php
$url = "https://url.com/Invoices?startDate="01-01-2019"&endDate="01-31-2023";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array(
"Accept: application/json",
"Authorization: Bearer generatedtokenzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"Content-Type: application/json",
"zzzzzzzzz-API-Key: generatedapikeyzzzzzzzzzzzzzz",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
//for debug only!
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);
?>
Because it didn't work , we tried to add some options like
CURLOPT_CUSTOMREQUEST => 'GET',
and it still don't work.
We are getting crazy, we are on this problem for more than a week....
Any help would be very usefull.
Many thanks by advance....
We find the bug.
it was not in the part of this code but it was above.
a parameter was not passed correctly, and the error message {message": "list index out of range} was in fact wrong.
Here is my problem. I'm running a service on a remote machine working perfectly. The way to get the results from the machine is via api.
curl -X GET http://ip:777/api \
-d "r=request"
It works perfectly on the terminal. Moreover, it works perfectly, if the request query is short. But, it turns into a huge problem once, it passes some length(1800-2000 characters and I need 7k-8k chars).
However, I can't "transliterate" the curl code into PHP. If there is anyone with any idea how to do it please show me the way. As much as, I'm aware, this is a curl GET method with REQUEST BODY.
$long_query = "r=" . $request;
// set the api
curl_setopt($ch, CURLOPT_URL, 'http://ip:777/api');
// i want to get the return
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// 2min+ timeout as to make sure that I get a result
curl_setopt($ch, CURLOPT_TIMEOUT, 140);
// Set request method to GET by 0'ing the POST method
curl_setopt($ch, CURLOPT_POST, 0);
// Set query data here with CURLOPT_POSTFIELDS
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($long_query));
$content = curl_exec($ch);
curl_close($ch);
echo $content;
What am I doing wrong in here? If someone knows, please explain as if you are teaching a year old. Thanks in advance!
I think the following doc would help you understand how GET method works. This is from RFC 7231
A payload within a GET request message has no defined semantics; sending a payload body on a GET request might cause some existing implementations to reject the request.
For more details, please refer to this answer.
Alright, here we go with the proper answer.
on terminal,
curl -X GET http://ip:777/api \
-d "r=request"
works perfectly. However, the problem with converting that to php curl is quite troublesome while very easy at the same time.
I've read through every stack problem regarding this and no-one has provided a clear answer to the problem. I'm not sure the reason behind it but as a generous person I'll give out the code so that anyone in the future facing this rare problem will solve it out easily.
Long story short,
curl -X GET -d is the same as curl -X POST -H "X-HTTP-Method-Override: GET".
The actual request is POST but THE SERVER will consider it as a GET. This way you won't face the LONG URI problem.
$long_query = "r=" . $request;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"ip:777/api");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $long_query); //Post Fields
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = [
'X-HTTP-Method-Override: GET',
];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$server_output = curl_exec ($ch);
curl_setopt($ch, CURLOPT_TIMEOUT, 140);
curl_close ($ch);
var_dump($server_output);
I've set the timeout to 140 as the query is long and it takes a bit of time for the server to go through it and respond (in my case its a json). Nevertheless, I've added var_dump so that anyone who uses it in the future might see if its a serialized array or whatever.
Good luck!
I have a curl request to get some information about database and stuff, but since some user need to query many bases and most of them are not familiar with any kind of shell,
we are trying to build a small page to e"xecute the query and be more user friendly
we got pretty much everything working (form and stuff) but we got really figure how to build the uery in php
here is the original working curl request we made:
curl -s - X POST -H 'Content-type:application/json' -H
'Accept:application/json' -d '{"param1":"value1","param2":"value2"} -k
https:myurl -u user:password
and here is the code with the request we are trying to build:
<?php
$data = array('param1' => 'value1',
'param2' => 'value2'
);
$ch = curl_init();
$url = "https://myurl";
curl_setopt($ch, curlopt_url, $url);
curl_setopt($ch,curlopt_userpwd, "user:password" );
curl_setopt($ch,curlopt_post, 1);
curl_setopt($ch,curlopt_postfuelds, $data);
curl_setopt($ch,curlopt_returntransfer, true);
curl_setopt($ch,curlopt_ssl_verifypeer, false);
curl_setopt($ch,curlopt_httpheader,
array ("Content-type:application/json"));
$output = curl_exec($ch);
curl_close($ch);
I cannot really figure whats wrong? can you help me?
I rather not use shell_exec with the curl inside because the server hosting is on windows, and we don't have curl.exe available
thanks
You have a typo: curlopt_postfuelds should be curlopt_postfields
I've been able to use PHP in order to generate JIRA issues, but was wondering if it is possible to also create Confluence wiki pages that link back to the JIRA issue. I haven't been able to make this work yet. Does anyone have any examples on how this is accomplished?
With this code in php, you can create Confluence Pages:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://localhost:8090/rest/api/content/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"type\":\"page\",\"title\":\"inserttitle\",\"space\":{\"key\":\"insertspace\"},\"ancestors\":[{\"type\":\"page\",\"id\":insertancestor}],\"body\":{\"storage\":{\"value\":\"<p>This is a new page</p>\",\"representation\":\"storage\"}}}");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, "insertusername" . ":" . "insertpassword");
$headers = array();
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
?>
You can easily create a new Confluence page using the REST API. Here's an example using curl:
curl -u admin:admin -X POST -H 'Content-Type: application/json' -d'{"type":"page","title":"new page","space":{"key":"TST"},"body":{"storage":{"value":"<p>This is a new page</p>","representation":"storage"}}}' http://localhost:8080/confluence/rest/api/content/
The next thing to do would be for PHP to call that. Check the following for examples:
PHP curl post
Basic authentication in PHP curl
Having done that, you could also embed a JIRA macro in the Confluence page for extra zing. That would mean that the original curl would add the JIRA macro as the storage format (in a Confluence page, click on Tools (or "..." now) and select View Storage Format for an example.
Here's an example of the JIRA macro:
<ac:structured-macro ac:name="jira">
<ac:parameter ac:name="server">Example JIRA</ac:parameter>
<ac:parameter ac:name="serverId">fdsafds-68es-3615-a6f7-71427b983092</ac:parameter>
<ac:parameter ac:name="key">XYZ057-172</ac:parameter>
</ac:structured-macro>
You'll need to figure out your server name, serverId & JIRA issue key yourself.
This would mean the original curl looks like this:
curl -u admin:admin -X POST -H 'Content-Type: application/json' -d'{"type":"page","title":"new page","space":{"key":"TST"},"body":{"storage":{"value":"<p>This is a new page with a JIRA macro added:</p><ac:structured-macro ac:name="jira"><ac:parameter ac:name="server">Example JIRA</ac:parameter><ac:parameter ac:name="serverId">fdsafds-68es-3615-a6f7-71427b983092</ac:parameter><ac:parameter ac:name="key">XYZ057-172</ac:parameter></ac:structured-macro>","representation":"storage"}}}' http://localhost:8080/confluence/rest/api/content/
Evening folks,
I am attempting to load data from a .json file into parse.com backend. I can get the rest api to load manually added json as per the example provided from Parse.com from the terminal on my Mac:
curl -X POST \
-H "X-Parse-Application-Id: removed" \
-H "X-Parse-REST-API-Key: removed" \
-H "Content-Type: application/json" \
-d '{"score":1337,"playerName":"Sean Plott","cheatMode":false}' \
https://api.parse.com/1/classes/Test
This works fine.
How can I read a saved .Json file with only these three parameters(Json is validated fine) and send the data to my Parse backend?
"score":1337,"playerName":"Sean Plott","cheatMode":false
I believe I have the option to use PHP/Jquery etc. however I have not used any of these languages extensively and a quick code example would be very much appreciated.
Thanks,
Gerard
Here is pure PHP solution:
$url = 'https://api.parse.com/1/classes/Test';
$fields_string = file_get_contents('file.json');
//open connection
$ch = curl_init();
//set the url, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
/* End of first request */