title: FedEx Shipping API using PHP
body: <p>I am trying to Integrating fedex api using php but there are some errors .i am using following code:</p>
  
  <pre><code>  &lt;?php
  
     $url = 'https://sandbox-api.postmen.com/v3/rates';
     $method = 'POST';
     $headers = array(
         "content-type: application/json",
         "postmen-api-key: 6ea35e71-385c-8cda-5729-f7d02c1ceb5a"
     );
     $body = '{"async":false,"shipper_accounts":[{"id":"00000000-0000-0000-0000-000000000000"}],"is_document":false,"shipment":{"ship_from":{"contact_name":"Elmira Zulauf","company_name":"Kemmer-Gerhold","street1":"662 Flatley Manors","country":"HKG","type":"business"},"ship_to":{"contact_name":"Dr. Moises Corwin","phone":"1-140-225-6410","email":"Giovanna42@yahoo.com","street1":"28292 Daugherty Orchard","city":"Beverly Hills","postal_code":"90209","state":"CA","country":"USA","type":"residential"},"parcels":[{"description":"Food XS","box_type":"custom","weight":{"value":2,"unit":"kg"},"dimension":{"width":20,"height":40,"depth":40,"unit":"cm"},"items":[{"description":"Food Bar","origin_country":"USA","quantity":2,"price":{"amount":3,"currency":"USD"},"weight":{"value":0.6,"unit":"kg"},"sku":"imac2014"}]}]}}';
  
     $curl = curl_init();
  
     curl_setopt_array($curl, array(
         CURLOPT_RETURNTRANSFER =&gt; true,
         CURLOPT_URL =&gt; $url,
         CURLOPT_CUSTOMREQUEST =&gt; $method,
         CURLOPT_HTTPHEADER =&gt; $headers,
       CURLOPT_POSTFIELDS =&gt; $body
     ));
  
     $response = curl_exec($curl);
     $err = curl_error($curl);
  
     curl_close($curl);
  
     if ($err) {
       echo "cURL Error #:" . $err;
     } else {
       echo $response;
     }
  </code></pre>
  
  <p>This is the result I get from the code :</p>
  
  <pre><code>  {"meta":{"code":4105,"message":"Invalid URL or API key.","details":[],"retryable":false},"data":{}}
  </code></pre>
  
  <p>And i have using some other code is :</p>
  
  <pre><code>    &lt;?php
              //your account details here
              $key = '';
              $password = ' ';
              $account_number = '';
              $meter_number = '';
  
              $xml = '&lt;?xml version="1.0" encoding="UTF-8"?&gt;
              &lt;SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://fedex.com/ws/rate/v13"&gt;&lt;SOAP-ENV:Body&gt;&lt;ns1:RateRequest&gt;
              &lt;ns1:WebAuthenticationDetail&gt;
              &lt;ns1:UserCredential&gt;
              &lt;ns1:Key&gt;'.$key.'&lt;/ns1:Key&gt;
              &lt;ns1:Password&gt;'.$password.'&lt;/ns1:Password&gt;
              &lt;/ns1:UserCredential&gt;&lt;/ns1:WebAuthenticationDetail&gt; 
              &lt;ns1:ClientDetail&gt;
              &lt;ns1:AccountNumber&gt;'.$account_number.'&lt;/ns1:AccountNumber&gt;
              &lt;ns1:MeterNumber&gt;'.$meter_number.'&lt;/ns1:MeterNumber&gt;
              &lt;/ns1:ClientDetail&gt;
              &lt;ns1:TransactionDetail&gt;&lt;ns1:CustomerTransactionId&gt; *** Rate Request v13 using PHP ***&lt;/ns1:CustomerTransactionId&gt;&lt;/ns1:TransactionDetail&gt;&lt;ns1:Version&gt;&lt;ns1:ServiceId&gt;crs&lt;/ns1:ServiceId&gt;&lt;ns1:Major&gt;13&lt;/ns1:Major&gt;&lt;ns1:Intermediate&gt;0&lt;/ns1:Intermediate&gt;&lt;ns1:Minor&gt;0&lt;/ns1:Minor&gt;&lt;/ns1:Version&gt;&lt;ns1:ReturnTransitAndCommit&gt;true&lt;/ns1:ReturnTransitAndCommit&gt;&lt;ns1:RequestedShipment&gt;
              &lt;ns1:DropoffType&gt;REGULAR_PICKUP&lt;/ns1:DropoffType&gt;
              &lt;ns1:ServiceType&gt;FEDEX_EXPRESS_SAVER&lt;/ns1:ServiceType&gt;
              &lt;ns1:PackagingType&gt;YOUR_PACKAGING&lt;/ns1:PackagingType&gt;
              &lt;ns1:TotalInsuredValue&gt;&lt;ns1:Currency&gt;USD&lt;/ns1:Currency&gt;&lt;/ns1:TotalInsuredValue&gt;
              &lt;ns1:Shipper&gt;&lt;ns1:Contact&gt;&lt;ns1:PersonName&gt;Sender Name&lt;/ns1:PersonName&gt;&lt;ns1:CompanyName&gt;Sender Company Name&lt;/ns1:CompanyName&gt;&lt;ns1:PhoneNumber&gt;&lt;/ns1:PhoneNumber&gt;&lt;/ns1:Contact&gt;&lt;ns1:Address&gt;&lt;ns1:StreetLines&gt;&lt;/ns1:StreetLines&gt;&lt;ns1:City&gt;&lt;/ns1:City&gt;&lt;ns1:StateOrProvinceCode&gt;&lt;/ns1:StateOrProvinceCode&gt;
              &lt;ns1:PostalCode&gt;94040&lt;/ns1:PostalCode&gt;&lt;ns1:CountryCode&gt;US&lt;/ns1:CountryCode&gt;&lt;/ns1:Address&gt;&lt;/ns1:Shipper&gt;
              &lt;ns1:Recipient&gt;&lt;ns1:Contact&gt;&lt;ns1:PersonName&gt;Recipient Name&lt;/ns1:PersonName&gt;&lt;ns1:CompanyName&gt;Company Name&lt;/ns1:CompanyName&gt;&lt;ns1:PhoneNumber&gt;&lt;/ns1:PhoneNumber&gt;&lt;/ns1:Contact&gt;&lt;ns1:Address&gt;&lt;ns1:StreetLines&gt;&lt;/ns1:StreetLines&gt;&lt;ns1:City&gt;&lt;/ns1:City&gt;&lt;ns1:StateOrProvinceCode&gt;&lt;/ns1:StateOrProvinceCode&gt;
              &lt;ns1:PostalCode&gt;98052&lt;/ns1:PostalCode&gt;
              &lt;ns1:CountryCode&gt;US&lt;/ns1:CountryCode&gt;&lt;ns1:Residential&gt;false&lt;/ns1:Residential&gt;&lt;/ns1:Address&gt;&lt;/ns1:Recipient&gt;&lt;ns1:ShippingChargesPayment&gt;&lt;ns1:PaymentType&gt;SENDER&lt;/ns1:PaymentType&gt;&lt;ns1:Payor&gt;
              &lt;ns1:ResponsibleParty&gt;
              &lt;ns1:AccountNumber&gt;'.$account_number.'&lt;/ns1:AccountNumber&gt;
              &lt;/ns1:ResponsibleParty&gt;
              &lt;/ns1:Payor&gt;&lt;/ns1:ShippingChargesPayment&gt;
              &lt;ns1:RateRequestTypes&gt;ACCOUNT&lt;/ns1:RateRequestTypes&gt;&lt;ns1:PackageCount&gt;1&lt;/ns1:PackageCount&gt;&lt;ns1:RequestedPackageLineItems&gt;&lt;ns1:SequenceNumber&gt;1&lt;/ns1:SequenceNumber&gt;
              &lt;ns1:GroupPackageCount&gt;1&lt;/ns1:GroupPackageCount&gt;
              &lt;ns1:Weight&gt;&lt;ns1:Units&gt;LB&lt;/ns1:Units&gt;&lt;ns1:Value&gt;20&lt;/ns1:Value&gt;&lt;/ns1:Weight&gt;
              &lt;ns1:Dimensions&gt;
              &lt;ns1:Length&gt;10&lt;/ns1:Length&gt;
              &lt;ns1:Width&gt;10&lt;/ns1:Width&gt;
              &lt;ns1:Height&gt;10&lt;/ns1:Height&gt;
              &lt;ns1:Units&gt;IN&lt;/ns1:Units&gt;
              &lt;/ns1:Dimensions&gt;
              &lt;/ns1:RequestedPackageLineItems&gt;
              &lt;/ns1:RequestedShipment&gt;&lt;/ns1:RateRequest&gt;&lt;/SOAP-ENV:Body&gt;&lt;/SOAP-ENV:Envelope&gt;';
  
              $ch = curl_init();
              curl_setopt($ch, CURLOPT_URL, 'https://wsbeta.fedex.com:443/web-services');
              curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
              curl_setopt($ch, CURLOPT_VERBOSE, 1);
              curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
              curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
              curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
              curl_setopt($ch, CURLOPT_POST, 1);
              $result_xml = curl_exec($ch);
  
              // remove colons and dashes to simplify the xml
              $result_xml = str_replace(array(':','-'), '', $result_xml);
               $result = @simplexml_load_string($result_xml);
              //$array_data = json_decode(json_encode(simplexml_load_string($result_xml)), true);
              // print_r($result); die();
  
  
              print '&lt;pre&gt;';
              print 'Rate: $';
              //echo  $result-&gt;Amount;
              //echo $array_data-&gt;SOAPENVBody;
              print '&lt;hr/&gt;';
              echo $array_data-&gt;Amount;
              print_r($result);
  </code></pre>
  
  <p>That will show the following error</p>
  
  <pre><code>                       [v13Severity] =&gt; ERROR
                          [v13Source] =&gt; prof
                          [v13Code] =&gt; 1000
                          [v13Message] =&gt; Authentication Failed
  </code></pre>
  
  <p>Anyone can help me please.I am trying to find solution from last 2 days.
  can one have any idea about this or have any api regarding fedex shiping rate. I have to to find only shipping rate with this api.</p>
  
  <p>Thanks in advance.</p>