EVE ESI Post waypoint


(Xadi Senga) #1

Hello Capuleers,

Im trying something relatively easy but im missing something. Im trying to set a waypoint for a character where i have the accessToken for. Bottom is my code but im getting the error

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

This is the code that i have for it, the curl works for the authorization codes perfectly.

public function setWaypoint($accessToken, $destination) {
        
        $url = ESIURL."ui/autopilot/waypoint/";
        $header = 'Authorization: Bearer '.$accessToken;
        $fields = array (
                'add_to_beginning' => 'true',
                'clear_other_waypoints' =>  'true',
                'destination_id' => (string)$destination
            );
               
       if($result = CURL::execute($url, $header, $fields)) {
            
            return $result;
            
        } else {
            
            return false;
            
        }

And the curl function:

public static function execute($url, $header = null, $fields = null) {
        
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_USERAGENT, CRESTUserAgent); # Defined in config
        if($header != null) { 
            curl_setopt($ch, CURLOPT_HTTPHEADER, array($header));
        }
        
        # If fields need to be send aswell
        if($fields != null) {
            
            curl_setopt($ch, CURLOPT_POST, count($fields));
            curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
            
        }
        
        curl_setopt($ch, CURLOPT_ENCODING, '');  # Enable Gzip
        curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 ); # Only do ipv4
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        $result = curl_exec($ch);
        
        return $result;        
        
    }   

Note: im just a hobby ‘programmer’ and any help is appreciated! Thanks in advance :slight_smile:


(Blacksmoke16) #2

CURLOPT_POST try setting that to true. Main issue seems to be its not actually setting the query params you’re passing it.


(Xadi Senga) #3

Thanks for your reply i set the following, but the error still remains :frowning:

curl_setopt($ch, CURLOPT_POST, true);


(Blacksmoke16) #4

Darn. The issue is deff curl isnt including/setting the query params. I’d try to reduce the code bit by bit to see if you can narrow it down.


(Xadi Senga) #5

Anything else still have an idea, banging my head against this one…


(Brock Khans) #6

Have you debugged $fields to make sure they are correctly set inside this? Just to be 100% certain they are being passed down into the function correctly


(Snitch Ashor) #7

Try to add the following header:

'Content-Type: application/x-www-form-urlencoded'

(Xadi Senga) #8

Hey Guys,

Thanks for responding, had a little vacation in the meantime. None of the suggesting options worked unfortunatly. I ran a verbose on the curl and the bottom is the result;

* About to connect() to esi.evetech.net port 443 (#1)
*   Trying 52.208.79.249...
* Connected to esi.evetech.net (52.208.79.249) port 443 (#1)
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
* SSL connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate:
* 	subject: CN=esi.evetech.net
* 	start date: Feb 27 00:00:00 2018 GMT
* 	expire date: Mar 27 12:00:00 2019 GMT
* 	common name: esi.evetech.net
* 	issuer: CN=Amazon,OU=Server CA 1B,O=Amazon,C=US
> POST /latest/ui/autopilot/waypoint/ HTTP/1.1
User-Agent: INFINIZO ESI
Host: esi.evetech.net
Accept: */*
Accept-Encoding: deflate, gzip
Authorization: Bearer eyJhbGciO..........removed
Content-Length: 113
Content-Type: application/x-www-form-urlencoded

* upload completely sent off: 113 out of 113 bytes
< HTTP/1.1 400 Bad Request
< Date: Sun, 30 Dec 2018 11:25:07 GMT
< Content-Type: application/json; charset=UTF-8
< Content-Length: 109
< Connection: keep-alive
< Access-Control-Allow-Credentials: true
< Access-Control-Allow-Headers: Content-Type,Authorization,If-None-Match,X-User-Agent
< Access-Control-Allow-Methods: POST,OPTIONS
< Access-Control-Allow-Origin: *
< Access-Control-Expose-Headers: Content-Type,Warning,ETag,X-Pages,X-ESI-Error-Limit-Remain,X-ESI-Error-Limit-Reset
< Access-Control-Max-Age: 600
< Allow: OPTIONS,POST
< Strict-Transport-Security: max-age=31536000
< X-Esi-Error-Limit-Remain: 99
< X-Esi-Error-Limit-Reset: 53
< X-Esi-Request-Id: a575cecb-cb0e-4903-a903-47235a1c8d7d
< 
* Connection #1 to host esi.evetech.net left intact

error is still the same, i just dont get it :frowning:


(Snitch Ashor) #9

This doesnt really help because curl, will not print post data in verbose mode. Did you try to print the fields data in your curl function? Headers obviously get used.

If you want to debug post data, you could create a file on your server sth like test.php with the following content:

<?php
file_put_contents("post.log",print_r($_POST,true));
?>

And then change the esi url to https://(yourdomain)/test.php