I want to update a page in confluence with some php-variables. So here's my PHP Code to update the page:
$curl = curl_init();
$post = "{\"id\":\"65604\",\"type\":\"page\",\"title\":\"page\",\"space\":{\"key\":\"***\"},\"body\":{\"storage\":{\"value\":\"<p>Here comes the other variable: $product_response </p>\",\"representation\":\"storage\"}},\"version\":{\"number\":11}}";
curl_setopt_array($curl, array(
CURLOPT_PORT => "6003",
CURLOPT_URL => "http://localhost:6003/rest/api/content/65604",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => $post,
CURLOPT_COOKIE => "JSESSIONID=3A16CBFE8B99E619D62BD4CD6573F184",
CURLOPT_HTTPHEADER => array(
"authorization: Basic xyYS123_test_test-45Sdasds==",
"content-type: application/json"
),
));
For your information:
If i print the $post in another script, the variable value show up
without the variable, the curl session works and I can update the page
Thats the error:
{"statusCode":500,"message":"org.codehaus.jackson.JsonParseException: Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value\n at [Source: com.atlassian.confluence.plugins.restapi.filters.LimitingRequestFilter$1#5dff62ce; line: 1, column: 119]","reason":"Internal Server Error"}
The json values for post that you are forming is incorrectly formed, Why dont you use json_encode(); by declaring all the values inside an array, you can change your code like this:
$curl = curl_init();
$post = array(
"id"=>"65604",
"type"=>"page",
"title"=>"page",
"space"=>["key"=>"***"],
"body" =>["storage"=>["value"=>"<p>Here comes the other variable: ".$product_response." </p>", "representation"=>"storage"]],
"version"=>["number"=>11]
);
curl_setopt_array($curl, array(
CURLOPT_PORT => "6003",
CURLOPT_URL => "http://localhost:6003/rest/api/content/65604",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode($post),
CURLOPT_COOKIE => "JSESSIONID=3A16CBFE8B99E619D62BD4CD6573F184",
CURLOPT_HTTPHEADER => array(
"authorization: Basic xyYS123_test_test-45Sdasds==",
"content-type: application/json",
'Accept: application/json'
),
));
Related
I am trying to pass the Variable into Curl But It's Not Working as I am trying to Call JSON API I Tried all The Possible Ways But Ntg Worked.
$name = "SAI";
$amount = "42000";
$user = "1643031393";
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.interakt.ai/v1/public/track/events/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS =>"{\"userId\":\"1643031393\",\"event\":\"SEVA BILL GENRATED\",\"traits\": {\"donated\":\"YES\",\"seva_name\":\"$name\",\"seva_amount\":\"$amount\",\"Seva Date\":\"12-22-2022\",\"E-Receipt URL\":\"https://ack.saaa.org"},\"createdAt\": \"2022-01-24T13:26:52.926Z\"}",
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
"Authorization: Basic gfdsds"
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;````
The value of CURLOPT_POSTFIELD option must be JSON format!
Like this:
$data = json_encode(array(
"name" => "Steve",
"amount" => 12345,
"user" => 123456789
));
$curl = curl_init();
curl_setopt_array($curl, array(
...
CURLOPT_POSTFIELDS => $data,
...
));
I am trying to upload a document using the project API and it's giving an empty response with status 201. Due to an empty response, I am unable to get the id and name of the file uploaded.
curl_setopt_array($curl, array(
CURLOPT_URL => $link,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => array('uploaddoc'=> new CURLFILE($path)),
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer '.$access_token,
"Accept: application/json"
),
));
Link:
https://www.zoho.com/projects/help/rest-api/documents-api.html#alink3
hope someone can help with this code ...
I have a PHP CURL code to post to URL ... the issue is
If I posted a text with single line then the text will delivered
If I posted a text with multiple lines then it will not be deliver
Blockquote
curl_setopt_array($curl, [
CURLOPT_URL => "http://example.com/sendText",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => '{ "sessionName":"'.$row_ch["phone"].'","number": "'.$row_outmsg["tonum"].'","text":"'.$row_outmsg["body"].'"}',
CURLOPT_HTTPHEADER => [
"Accept: application/json",
"Content-Type: application/json"
],
]);
Can some help me fixing the multi lines posting? .. please .
The json with new line is incorrect format
Use
CURLOPT_POSTFIELDS => json_encode(array(
"sessionName" => $row_ch["phone"],
"number" => $row_outmsg["tonum"],
"text" => $row_outmsg["body"]
))
i want to delete one item from the following database:
But I didn't find any way to make a reference to -MDn__nRYb10hBAybUDM - item. The only code I found is:
curl_setopt_array($curl, array(
CURLOPT_URL => FIREBASE_URL . "RiderOrdersList/" . $rider_id . "/PendingOrders/.json",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "DELETE",
CURLOPT_POSTFIELDS => json_encode($curl_data2),
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: application/json",
"postman-token: 6b83e517-1eaf-2013-dab4-29b19c86e09e"
),
));
Can anyone help me out, please
Does any here have experience with Knack API(https://www.knack.com/) here?
I'm using PHP curl to post an image.
When I use POSTMAN, the image successfully uploads. But when I copy the code from POSTMAN(postman option to copy the source code) and add it to my source code, knack returns empty object error("Please select a file to upload").
Knack API documentation: https://www.knack.com/developer-documentation/#file-image-uploads
The POSTMAN source code below
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.knack.com/v1/applications/app-id/assets/file/upload",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"files\"; filename=\"C:\\Users\\shavk\\Pictures\\292937.jpg\"\r\nContent-Type: image/jpeg\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--",
CURLOPT_HTTPHEADER => array(
"Cache-Control: no-cache",
"Content-Type: application/x-www-form-urlencoded",
"Postman-Token: fe1f4eea-b2b5-2d43-2c3c-c262438866d4",
"X-Knack-Application-Id: id",
"X-Knack-REST-API-Key: key",
"content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
Any help is highly appreciated.
Postman's PHP/curl code generator isn't very good. to upload files in the multipart/form-data-format, use CURLFile.
the code should be
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.knack.com/v1/applications/app-id/assets/file/upload",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
'files' => new CURLFile("C:\\Users\\shavk\\Pictures\\292937.jpg")
),
CURLOPT_HTTPHEADER => array(
"X-Knack-Application-Id: id",
"X-Knack-REST-API-Key: key",
),
));
$response = curl_exec($curl);
if you are a customer of Postman (using the pro/whatever version), i suggest you make a complaint to customer support about the terrible code generated by the PHP code generator.