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
Related
Triggering Jenkins job via following PHP script:
<?php
$testrun_id = "1744";
$cmd = "curl -X POST http://build:f9280f75396f83a0#mobile-jenkins.domain.com:8080/job/android-test/build --data-urlencode json='{\"parameter\": [{\"name\":\"POST_RESULTS\", \"value\":\"true\"}, {\"name\":\"RUN_ID\", \"value\":\"{$testrun_id}\"}, {\"name\":\"CHECK_NAME\", \"value\":\"SampleAutomatedPlan\"}]}'";
exec($cmd,$result);
?>
This script runs successfully on Mac and the jenkins job does get triggered. How do I make this script to work on Windows? I am getting following error when I run above PHP script on Windows?
curl is already installed on windows machine. Also, is there a better way to do cURL in PHP? Looking at this: http://php.net/manual/en/book.curl.php, can someone point me towards an example based on my curl command in the above PHP script(for Windows)? An example based on the curl command in my script would be ideal.
you should check examples from here http://php.net/manual/en/curl.examples.php
Bellow is the code for you case,
$url = "http://build:f9280f75396f83a0#mobile-jenkins.domain.com:8080/job/android-test/buildWithParameters";
$data = "POST_RESULTS=true&RUN_ID=".$testrun_id."&CHECK_NAME=SampleAutomatedPlan";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
// $output contains the output string
$output = curl_exec($ch);
// close curl resource to free up system resources
curl_close($ch);
You need to set the content type for JSON
curl -H "Content-Type: application/json" -X POST http://build:f9280f75396f83a0#mobile-jenkins.domain.com:8080/job/android-test/build --data-urlencode json='{\"parameter\": [{\"name\":\"POST_RESULTS\", \"value\":\"true\"}, {\"name\":\"RUN_ID\", \"value\":\"{$testrun_id}\"}, {\"name\":\"CHECK_NAME\", \"value\":\"SampleAutomatedPlan\"}]}'";
Just make sure you don't have any mix matched values.
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
I am very new to the curl and i need to send the POST request to the following url:
curl -X POST https://connect.stripe.com/oauth/token \
-d client_secret=Secret key \
-d code=AUTHORIZATION_CODE \
-d grant_type=authorization_code
in the response i will be receiving the access token from the stripe.
please let me know how can create the function in php to do the same using the php - cURL.
Thanks for your help.
Stripe would probably advise to use their libraries but this is a curl tool I've been playing with here this morning; I prefer curl over libraries that wrap around it any day:
$post = 'client_secret='.$system['stipe']['client_secret'].'&grant_type=authorization_code&code='.$_GET['code'];
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $system['stipe']['token_url']);
curl_setopt($ch,CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
You just need to wrap it up as a function and json_decode the values returned.
This works for me whereas the code in the docs / gist didn't as they were lacking the false flag on the SSL verify peer which in my dev setup here made things prang.
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 */
I'm integrating with a 3rd party's API, I have to POST some XML and I get some XML back.
On the CLI this works, I get a positive response.
curl -X POST -d #/tmp/file http://url/to/endpoint --header "Content-Type:application/x-www-form-urlencoded"
This, however, does not work, the response contains an error telling me my that my request XML is invalid.
$ch = curl_init();
$post = array(
'file' => '#/tmp/file'
);
curl_setopt($ch, CURLOPT_URL, 'http://url/to/endpoint');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type:application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$this->responseBody = curl_exec($ch);
curl_close($ch);
It's the same file in both cases and it's on the same server. the file is just plain text XML. The only difference that I can see is that I'm specifying a fieldname in my HTTP headers on the PHP version.
How do I send that file over using PHP to exactly replicate the CLI version, e.g. without the formdata/fieldname bit?
FWIW I can't go back to the developer of the API for a few days to ask what he's defining as 'bad XML'
Try passing the file as raw data, not in an array, by for example using file_get_contents().
So instead of:
$post = array('file' => '#/tmp/file');
Like this:
$post = file_get_contents('#/tmp/file');