search

Home  >  Q&A  >  body text

FEDEX Ship API returns compressed information about certain errors

<p>I have implemented the Fedex API using the Check Rates API and can create labels using the Ship API. Both worked fine in the sandbox, so I got my label certified and went live. The API should return JSON. Sometimes, in live and sandbox, API calls using cURL return non-JSON responses. You will never have a problem getting a good json response using OAuth or check rate API calls. However, the Ship API can return good json, but it can also return compressed responses. </p> <p>This is my curl request. </p> <pre class="brush:php;toolbar:false;">function fedexRequest($endpoint, $post, $header = null) { //$ch = curl_init('https://apis-sandbox.fedex.com/' . $endpoint); // sandbox $ch = curl_init('https://apis.fedex.com/' . $endpoint); // live curl_setopt_array($ch, [ CURLOPT_SSL_VERIFYPEER => true, CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_POSTFIELDS => $post, ]); if ($header) curl_setopt($ch, CURLOPT_HTTPHEADER, $header); return curl_exec($ch); }</pre> <p>I got json and compressed response using this code. $post is the json payload I send them. Spoiler alert! The error is usually the details of something in the payload. The first mistake is setting PackagingType = FEDEX_PAK for items weighing more than 20 pounds. Another approach is to use CM instead of IN for the size units. </p> <p>My calls to Fedex Web Services support are having difficulty diagnosing non-json error responses. The response looks like the code in the browser: black diamond vs white? and random spaces, letters, and numbers. </p> <p>The first person to tell me exactly what they saw when looking at my account api calls, tell me the cause and solution for the error, and even see my good tags in real time after I implemented their setup Responses are admired. Hopefully I'll get a direct line call back from him. Also made a few support calls today but no one could provide the same diagnostic help. The last one says, you are receiving a compressed response, so deal with it. They said their manager said it was my code that was causing the compressed response. </p> <p>This is confusing, and while in the sandbox I do see errors in good json responses and build methods to parse them appropriately for the end user. Also seen these code responses. I thought it was just a known bug from their sandbox, but apparently some of their bugs were squashed. </p> <p>So, I have a few questions.</p> <p>Is the compression caused by my cURL request? </p> <p>If I set CURLOPT_ENCODING in the request, will it handle these responses more appropriately? </p> <p>If I receive a compressed response, is gzread or ZipArchive the best way to decompress it and get the actual error code? Suppose it's there? </p>
P粉549986089P粉549986089460 days ago498

reply all(1)I'll reply

  • P粉919464207

    P粉9194642072023-09-02 11:14:10

    It appears that cURL requests to Fedex can return both compressed and uncompressed responses. Adding CURLOPT_ENCODING => "" to the cURL setopt array automatically decompresses gzip responses.

    reply
    0
  • Cancelreply