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/
Related
Using the Google Developer Api Tool I have been able to execute a blank query and return a list of contact groups, exactly as expected. When using the same cURL request from my PHP app I don't get anything but some system contact groups (and not all overlap with the tool's response). I can't figure out why this would be the case, am I missing something really obvious?
The Curl Request c&p'd from the google developer tool:
curl \
'https://people.googleapis.com/v1/contactGroups?key=[YOUR_API_KEY]' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--compressed
And my php cURL request:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://people.googleapis.com/v1/contactGroups");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
$headers = ["Authorization: Bearer {$access_token}", "Accept: application/json"];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$data = curl_exec($ch);
$result = json_decode($data, true);
var_dump($result); die();
The returned outputs of the requests are in the same format, just the content differs. Does anyone have experience trying to get a list of contact groups/labels from the people api?
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.
I have tried the following code and receive a message saying my particular request is not supported, I cannot find any solutions that are not python for the v20 api. any help would be appreciated on what to use or where im going wrong
My error message is:
{"errorMessage":"Requested HTTP method is not supported for supplied
endpoint."}
<?php
$ch = curl_init();
$vars = "price=B&granularity=M5&count=20";
curl_setopt($ch, CURLOPT_URL,"https://api-fxpractice.oanda.com/v3/instruments/EUR_USD/candles");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$vars); //Post Fields
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = [
'Content-Type: application/json',
'Authorization: Bearer access-token',
];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$server_output = curl_exec ($ch);
curl_close ($ch);
print $server_output ;
?>
My goal here is to successfully connect and get the response from the endpoint containing data. I have no python experience which is why im trying curl or even a javascript solution would work. Am i just not understanding this API at all?
Two things that stand out in the code are:
that there is no actual authorisation code. I don’t know if you have removed it for security while posting, or if you don’t realise you need to create a practice account and get an authorisation code for it? Both are free.
Your code curl_setopt($ch, CURLOPT_POST, 1); suggests you are trying a POST, whereas a GET is required for the \instruments endpoint.
But the simplest thing I can suggest that might help is to look at the following Github bash script that has taken OANDA's V1 API bash cURL example, and updated it for the v2 rest API.
https://github.com/p-burke/oanda-REST-v2-API-bash-script
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
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 */