1

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.

Ben Rhys-Lewis
  • 3,118
  • 8
  • 34
  • 45

1 Answers1

0

Once I had the same error. The solution is : use ' -apostrophe - and . -dot- before and after the variable. Like this:

/deliveries/'.$delivery_id.'/cancel

Mahmut Salman
  • 111
  • 1
  • 10