PHP ESI Curl error

Hello Scripting Master, i need your assitance on a esi.setwaypoint. Im using the code below. I have tried alot of things but none seem to work and give the exact same error over and over.

What am i doing wrong

Error i get:

{"error":"'add_to_beginning' is required, 'clear_other_waypoints' is required, 'destination_id' is required"}

cURL i use for this.

 $url = "";
        $fields = array (
                'add_to_beginning' => 'true',
                'clear_other_waypoints' => 'true',
                'datasource' => 'tranquility',
                'destination_id' => '30000267'
        $header = array(
            'Authorization: Bearer '.$accessToken,
            'Accept: application/json'
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,$url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
        $result = curl_exec($ch); 

        //Server response json decode & display

        return $result; 

The two things that come to mind without actually trying anything would be:

  1. Use the proper data types in your $fields array. I.e. true instead of 'true'
  2. Replace the Accept header with Content-Type

It’s prob #2 since without that header the server is prob looking for JSON data that isn’t there as its being read as form data.

Hi @Blacksmoke16,

Thanks for answering. Unfortunatly with the changes you asked i still get the same error.
One (maybe) interesting thing is that i always get the error twice while i only echo it once.

$fields = array (
                'add_to_beginning' => true,
                'clear_other_waypoints' => true,
                'datasource' => 'tranquility',
                'destination_id' => '30000267'
        $header = array(
            'Authorization: Bearer '.$accessToken,
			'Content-Type: application/json'

Oh I remember this issue. If you look at, you should be sending all of these as query params not in the POST body.

I did try this before with the following code:

curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));

But then it shoudnt be a post (and json) cURL anymore right? If its not to much trouble could you help me along with this.

Edit: also if i make one big URL with all the datafields as a GET i get the error “Method not allowed”

Something like this should work


$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "",
    "Authorization: Bearer TOKEN"

$response = curl_exec($curl);
$err = curl_error($curl);


if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;

Is just what Postman generated.

Oh my it works, thank you so much!

Dont know why my URl woudnt wanna work, but you generated this with Postman? What is that?

It’s just an HTTP client. Basically adds a UI on top of doing requests and such. is also nice.