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 = "https://esi.evetech.net/latest/ui/autopilot/waypoint/";
        
        
        $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); 
        curl_close($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 https://esi.evetech.net/ui/#/User%20Interface/post_ui_autopilot_waypoint, 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

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://esi.evetech.net/v2/ui/autopilot/waypoint/?add_to_beginning=true&clear_other_waypoints=true&destination_id=123",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_HTTPHEADER => array(
    "Authorization: Bearer TOKEN"
  ),
));

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

curl_close($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.

https://insomnia.rest/ is also nice.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.