I am using PHP OAuth2.0 Adobesign API for sending pdf to user for e-signature purpose.
I successfully generate auth token and refresh token by following basic OAuth2 steps.
Now I am facing issue while trying to send pdf transientDocuments using curl code. Below is my sample code:
define("CALLBACK_URL", "https://www.getdadstrong.com/vipin/test.php");
define("AUTH_URL", "https://api.in1.echosign.com/api/rest/v6/transientDocuments");
define("ACCESS_TOKEN_URL", "http://api.in1.echosign.com/oauth/token");
define("CLIENT_ID", "MY_CLIENT_ID");
define("CLIENT_SECRET", "MY_CLIENT_SECRET");
define("SCOPE", "agreement_send:account"); // optional
function getToken(){
$curlFILE = curl_init();
$params = array(
CURLOPT_URL => AUTH_URL,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_NOBODY => false,
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer MY_SECURE_TOKEN",
"cache-control: no-cache",
"content-type: multipart/form-data",
"Content-Disposition: form-data; name='file'; filename='MyPDF.pdf'",
),
CURLOPT_POSTFIELDS => array (
// 'filename' => new CURLFile('./MyPDF.pdf')
'filename' => new CURLFile('./MyPDF.pdf','application/pdf','MyFile')
),
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_SSL_VERIFYHOST => FALSE
);
curl_setopt_array($curlFILE, $params);
$response = curl_exec($curlFILE);
curl_close($curlFILE);
$err = curl_error($curlFILE);
if ($err) {
echo "<br/> cURL Error #01: " . $err;
}
echo '<pre>';
var_dump($err);
var_dump($response);
echo '<pre>';
}
getToken();
Output:
{
"code": "NO_FILE_CONTENT",
"message": "Must provide file body"
}
Finally I come to know Adobe Esign with V6 having some issue with this method. So I switch to V5 and make some little modification in my code. It is working for me.
<?php
define("AUTH_URL", "https://api.na2.echosign.com/api/rest/v5/transientDocuments");
$url = AUTH_URL;
$header =array(
"Authorization: Bearer 3AAAB6hBTt666543359kgBzroaNxqyezwBRdsdsdssssssssss6767gGy7CNdERHxqz1r5lOzmyxI7hfQ22zsyCDvnG_HRc8m9B7UBRJuGy",
"cache-control: no-cache",
"content-type: multipart/form-data",
"Content-Disposition: form-data; name='File'; filename='MyPDF.pdf'",
);
$filePath= '#'.file_get_contents('MyPDF.pdf');
$fields = array('File' => $filePath,'Mime-Type' => 'application/pdf', 'File-Name' => 'MyPDF.pdf');
$resource = curl_init();
curl_setopt_array($resource, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $fields,
CURLOPT_HTTPHEADER => $header
));
$res = curl_exec($resource);
$result = json_decode($res,true);
echo "<pre>";
print_r($result);
echo "</pre>";
curl_close($resource);
?>
Output:
Array
(
[transientDocumentId] => 3AA777777777777gwxctQX8kTYj2e3Esgc5_HbvKgKK_oaIccNqr2JwWJK8bUXn779OMvyFMJG2VONbbbMqO-bo_GoKJP-wfYszcQtg7tbJ8sc8YxTwQPm3kV77777ThgQy5ZoeHb_km-zmitgdSkf7sLYp0vCO8CAbvYQVzd3OpU6zJ-Mv54VoVKvsYUFsfhfhgK]epKpCHnvKWvn37fghfg777876rV2QYyh9bkApotXvSzxndXNQbUTmAcpP1Jq-WlXsVdGleKjHoEMoDgfhfghIOYQFxy5eeOtctqwtxC9MUWjioGV6FW6ZtoGm0ijqGU*
)
I had a little play in some free time and the following seemed to work on my test system. The function targets a very simple php endpoint rather than a remote url/api endpoint.
$file=sprintf('%s%slamb_vindaloo.pdf', __DIR__, DIRECTORY_SEPARATOR );
define( 'BEARER_TOKEN', '74e793ea86b6e06d5d971454a955c48012a422d7694d3463c23f69ef758f62db' );
define( 'AUTH_URL', 'https://sentinel/demo/stack/pdf-receiver.php' );
define( 'CA_CERTIFICATE', 'c:/wwwroot/cacert.pem' );
function getToken( $file=false ){
if( !$file )return;
$curl = curl_init();
$params = array(
CURLOPT_URL => AUTH_URL,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_POST => true,
CURLOPT_NOBODY => false,
CURLOPT_HTTPHEADER => array(
sprintf( "Authorization: Bearer %s", BEARER_TOKEN ),
"Cache-Control: no-cache",
"Content-Type: application/octet-stream", # <----- set the content-type
sprintf("Content-Disposition: form-data; name='file'; filename='%s'", $file ),
),
CURLOPT_POSTFIELDS => array (
'filename' => new CURLFile( $file, mime_content_type( $file ), pathinfo( $file, PATHINFO_FILENAME ) )
),
CURLOPT_CAINFO => CA_CERTIFICATE, # <------ if the endpoint is SSL it is advisable to use a valid cacert.pem file!!
CURLOPT_SSL_VERIFYPEER => false, # <------ if possible set this to true
CURLOPT_SSL_VERIFYHOST => 2 # <------ true/false are not options for this
);
curl_setopt_array( $curl, $params );
/*
Return an object with the various return values
rather than doing any printing from within the
function
*/
$res=(object)array(
'response' => curl_exec( $curl ),
'info' => (object)curl_getinfo( $curl ),
'errors' => curl_error( $curl )
);
curl_close( $curl );
return $res;
}
/* call the function */
$results=getToken( $file );
/* process the response accordingly */
if( $results->info->http_code==200 ){
printf('<pre>%s</pre>', $results->response );
}
The simple PHP endpoint is:
<?php
#
# PDF File Receiver for curlFile Tests....
#
$data=file_get_contents( 'php://input' );
echo base64_encode( $data );
?>
The response, to highlight success was as follows:
LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS02NGQ5ZGYyYTE3ZmE1MGNkDQpDb250ZW50LURpc3Bvc...etc etc
Related
I am trying to submit a php response to the following PlayFab API: https://learn.microsoft.com/en-us/rest/api/playfab/admin/account-management/reset-password?view=playfab-rest
This is my first ever php script and I have been working with this for quite some time and being able to run my script without errors but it seems like I have no payload.
The echo in the code:
echo ' The resp: ' .$resp;
...response from the above echo is:
The resp: string(0) ""
Unfortunately I really do not know what is wrong and how to fix it as there is not error messages. I have tried to echo $options array to control if there is a payload but not succeeded. I realise I need help and would really appreciate that.
$url = "https://titleId.playfabapi.com/Admin/ResetPassword/json/";
$data = array('Password' => $pw1, 'Token' => $params['token']);
$options = array(
'http' => array(
'method' => 'POST',
'content' => http_build_query($data),
'header' => 'X-SecretKey: xxxxxxxxxxxx\r\n',
'ignore_errors' => true
)
);
$context = stream_context_create($options);
$resp = file_get_contents($url, false, $context);
echo ' The resp: ' .$resp;
var_dump($resp);
Ok here is the solution. I was able to get this to work in Postman and when I test the code it works.
Here is the snippet that work:
echo '>>>>>>>>>> TEST <<<<<<<<<<';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://99999.playfabapi.com/Admin/ResetPassword?Password=pekapeka&Token=1B5A9C01EFD5DB69',
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_HTTPHEADER => array(
'X-SecretKey: xxxxxxx',
'Content-Type: application/json\\'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
print_r($response);
echo '<br>========== END ==========';
Hi im trying to use a custom form on my website to add a new contact to our marketing list, each contact will contain an email and first name.
Im trying to follow this documentation but am having no success:
https://sendgrid.api-docs.io/v3.0/contacts/add-or-update-a-contact
I have tried using their tool but it always says incorrect JSON but when i use an online validator it says correct, I can't figure out how to match theirs to get my request to post.
This is my current code:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.sendgrid.com/v3/marketing/contacts",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => "{\"list_ids\":[\"bf3ce5bd-14a2-414b-9b81-*****8e8ea62\"],\"contacts\":[{\"email\":\"$email\",\"first_name\":\"$first_name\"]}",
CURLOPT_HTTPHEADER => array(
"authorization: Bearer SG.OCFHb********P3iuikQ.bqKdM-da7X609ZNo9UT7y*********u5fDlfQo80o",
"content-type: application/json"
),
));
You just should be added } chars after $first_name.
This is valid JSON:
CURLOPT_POSTFIELDS => "{\"list_ids\":[\"bf3ce5bd-14a2-414b-9b81-*****8e8ea62\"],\"contacts\":[{\"email\":\"$email\",\"first_name\":\"$first_name\"}]}",
You can check it with https://jsonformatter.curiousconcept.com/ validator website.
One little trick to not have to deal with all the backslashes and escaping is to use a pre-defined object literal in PHP, by using arrays with (object) in front of them, to define the objects nested in the structures.
make an object, turn it into JSON with json_encode
enter the encoded JSON object into the CURLOPT_POSTFIELDS in the cURL request.
<?php
// make custom fields object for entry into the cURL later on:
// THERE IS NO OBJECT LITERAL IN PHP, but using (object) in front of an array, voila
$contact_info = (object)[
"list_ids" => [
"eeee-eeee-eeee-eeee-eeeeexample" // array of list ids here.
],
"contacts" => [ // this is an array of objects (array[object]), according to the api-docs.
(object)[
"email" => "email#example.com",
"country" => "the country",
"city" => "the city",
"custom_fields" => (object)[
"e1_T" => "sign-up-page-name", // only custom fields use ids as the key.
"e2_T" => "next-custom-field" // keep adding custom fields in this array.
]
]
]
];
// now all we have to do is to encode the object into JSON:
$json_contact_data = json_encode($contact_info);
// now add the contact:
$curl = curl_init();
// update the contact
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.sendgrid.com/v3/marketing/contacts",
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_contact_data, // here we enter the pre-configured json from above.
CURLOPT_HTTPHEADER => array(
"authorization: Bearer " . $your_api_key . "",
"content-type: application/json"
)
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
$decoded = json_decode($response, true); // decode into associative array.
if ($err) {
echo "cURL Error #: " . $err;
} else {
print_r($decoded); // print the decoded json message.
}
?>
This is the best way:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.sendgrid.com/v3/marketing/contacts',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_POSTFIELDS =>'{"list_ids": ["list-ID"], "contacts": [{"email": "' . $_GET["email"] . '"}]}',
CURLOPT_HTTPHEADER => array(
': ',
'Authorization: Bearer SG.000000000',
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
die();
I've been trying to create customer in Acumatica contract-based REST API following TIM RODMAN method and a little tweak of code
and all I'm getting is an error
{"message":"An error has occurred."}
I have tried to get data (GET all data) has been successful, but when I try to create new data customer, purchase order or else i got an error appears as above
Note: The same create in Postman didn't work, but start from login, get data, and logout work fine.
See the code below for my latest version of simplified code
function login_acumatica($cookie_jar, $curl){
// Login to Acumatica REST API
curl_setopt_array($curl, array(
CURLOPT_URL => "http://111.11.111.11/AcumaticaMMI/entity/auth/login",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_COOKIESESSION => 1,
CURLOPT_COOKIEJAR => $cookie_jar,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\r\n \"name\": \"admin\",\r\n \"password\": \"1112345\",\r\n \"company\": \"DUMMY USER\"\r\n}",
CURLOPT_HTTPHEADER => array( "cache-control: no-cache", "content-type: application/json"),
));
$response = curl_exec($curl);
$err = curl_error($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
}
function logout_acumatica($cookie_jar, $curl){
// Logout of Acumatica REST API
curl_setopt_array($curl, array(
CURLOPT_URL => "http://111.11.111.11/AcumaticaMMI/entity/auth/logout",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_COOKIESESSION => 1,
CURLOPT_COOKIEFILE => $cookie_jar,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => array( "cache-control: no-cache", "content-type: application/json"),
));
$response = curl_exec($curl);
$err = curl_error($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
// Close Connection
curl_close($curl);
// Remove Cookie Jar
unlink($cookie_jar) or die("Can't unlink $cookie_jar");
}
switch ($_GET['query']) {
case 'create_customer':
// Add Cookie Jar
$cookie_jar = tempnam('/tmp','cookie.txt');
// Initiate Connection
$curl = curl_init();
login_acumatica($cookie_jar, $curl);
curl_setopt_array($curl, array(
CURLOPT_URL => "http://111.11.111.11/AcumaticaMMI/entity/Default/6.00.001/CUstomer",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => "{\n\t\"CustomerID\": {\"value\":\"C-00023\"},\n\t\"CustomerName\": {\"value\":\"Cust Test 1\"}\n}",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
logout_acumatica($cookie_jar, $curl);
break;
default:
echo dirname(__FILE__) . '/cookie.txt';
break;
}
sorry for my bad english. thanks in advance
Unless you're using OAuth (which you are not), Acumatica requires cookies for the authentication to work. Postman handles cookies autimatically. As far as I can see, you don't transfer cookies between login call and subsequent calls, which is why your setup doesn't work.
Try something like this from Tim Rodman
// Add Cookie Jar
$cookie_jar = tempnam('/tmp','cookie');
// Initiate Connection
$curl = curl_init();
// Login to Acumatica REST API
echo "START <br><br>";
curl_setopt_array($curl, array(
CURLOPT_URL => "http://111.11.111.11/AcumaticaIII/entity/auth/login",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_COOKIESESSION => 1,
CURLOPT_COOKIEJAR => $cookie_jar,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\r\n \"name\": \"admin\",\r\n \"password\": \"123\",\r\n }",
CURLOPT_HTTPHEADER => array( "cache-control: no-cache", "content-type: application/json", "postman-token: e0a0ff40-8d46-4c5f-106b-960ad1aafba8"
),
));
I have tried below code in PHP to get the defect details from ALM but its not showing any response in browser. But the same is working in POSTMAN . Can someone help me here
Here is the document of REST API USAGE REST DOCUMENT FROM ALM
I have already tried existing posts from Stackoverflow
HP ALM REST API login using PHP CURL
ALM REST API v12.50 error 401
Nothing is helping so posted a new question
Note : Due to security purpose header value is kept as encoded value
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://hostname/qcbin/api/domains/domainname/projects/projectname/defects/?limit=10",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"authorization: Basic encoded value",
"cache-control: no-cache",
"postman-token: a8a2398d-7a0a-0ebd-a586-58a40e524a9a"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?>
I have finally found the solution and below is the approach
First we need get to LWSSO_COOKIE_KEY,QCSession,ALM_USER,XSRF_TOKEN values from the ALM Authentication link then we should use the values for subsequent calls
Below is the complete working code to get the list of defects by entering ALM Credentials
<?php
$curl = curl_init();
Header('Content-type: application/json');
$credentials = "username:password";
curl_setopt_array($curl, array(
CURLOPT_URL => "https://host:port/qcbin/api/authentication/sign-in",
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HEADER => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"authorization: Basic " . base64_encode($credentials) ,
"cache-control: no-cache"
) ,
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err)
{
echo "cURL Error #:" . $err;
}
else
{
// If there is no error then get the response to form the array of headers to get the different values required
$array_start = explode(';', $response);
foreach ($array_start as $key => $value) {
$remove_from_string = ['HTTP/1.1 200 OK','Path=/','HTTPOnly','HttpOnly','Content-Length',': 0'];
$replace_array = ['','','','','',''];
$value = str_replace($remove_from_string,$replace_array,$value);
$value = trim(preg_replace(('/Expires: [a-zA-Z]+, [0-9]+ [a-zA-Z]+ [0-9]+ [0-9]+:[0-9]+:[0-9]+ [a-zA-Z]+/'), '', $value));
$value = trim(preg_replace(('/Server: [a-zA-Z0-9.\(\)]+/'),'',$value));
if (!empty($value)) {
$almheaders[trim(explode('=',$value)[0])] = explode('=',$value)[1];
}
}
$LWSSO_COOKIE_KEY = $almheaders['Set-Cookie: LWSSO_COOKIE_KEY'];
$QCSession = $almheaders['Set-Cookie: QCSession'];
$ALM_USER = $almheaders['Set-Cookie: ALM_USER'];
$XSRF_TOKEN = $almheaders['Set-Cookie: XSRF-TOKEN'];
// Now form the Cookie value from the above values.
$cookie = "Cookie: JSESSIONID=33eyr1y736486zcnl0vtmo12;XSRF-TOKEN=$XSRF_TOKEN;QCSession=$QCSession;ALM_USER=$ALM_USER;LWSSO_COOKIE_KEY=$LWSSO_COOKIE_KEY";
// echo $cookie;
$curl = curl_init();
Header('Content-type: application/json');
curl_setopt_array($curl, array(
CURLOPT_URL => "https://host:port/qcbin/api/domains/CET_NTD/projects/BILLING_OPERATIONS/defects",
// CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"authorization: Basic " . base64_encode($credentials) ,
"cache-control: no-cache",
"Accept: application/json",
$cookie
) ,
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err)
{
echo "cURL Error #:" . $err;
}
else
{
echo $response;
}
}
?>
I want to pass a variable in CURLOPT_URL, here is my code
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.postmates.com/v1/customers/cus_KtQih0aARUZXdk/deliveries/$delivery_id/cancel",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => array(
'pickup_address' => $_POST["pickup_address"],
'pickup_phone_number' => $_POST["pickup_phone_number"],
'pickup_name' => $_POST["pickup_name"],
'dropoff_address' => $_POST["dropoff_address"],
'dropoff_phone_number' => $_POST["dropoff_phone_number"],
'dropoff_name' => $_POST["dropoff_name"],
'manifest' => $_POST["manifest"]
),
CURLOPT_HTTPHEADER => array(
"authorization: Basic MjhiMDU0ODktNjdkYS00M2VhLTg0NmMtYWQ1MWQ2MGNmMDA1Og==",
"cache-control: no-cache",
"content-type: multipart/form-data; boundary=---011000010111000001101001",
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
$delivery_id = trim($_POST['show_name']);
curl_close($curl);
$response = json_decode($response);
$timestamp = json_decode($dateJSON, true);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response->fee;
}
I want to add the variable $delivery_id in the url, but I am not too familiar with cURL and the above written code is not working. Please show me the way to include this variable in my url.
Once I had the same error. The solution is : use ' -apostrophe - and . -dot- before and after the variable. Like this:
/deliveries/'.$delivery_id.'/cancel