FEDEX Ship API returns compressed information about certain errors
P粉549986089
P粉549986089 2023-09-01 15:04:12
0
1
444
<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粉549986089
P粉549986089

reply all(1)
P粉919464207

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!