To show Fedex business shipping rates on your web application, use Fedex shipping rates api. In this tutorial, we will explain you how to send XML request to get FEDEX shipping rates.
In below example, we have created an XML API request using PHP CURL. First create a XML request parameter which included all required information to generate fedex shipping rates.
Fedex Shipping Rate XML Request in PHP:
Create a PHP file, and copy paste below code in it. Must add your Fedex API account access in xml parameter request.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
<?php $xml = '<?xml version="1.0" encoding="UTF-8"?>'; $xml .= '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://fedex.com/ws/rate/v13">'; $xml .= '<SOAP-ENV:Body>'; $xml .= '<ns1:RateRequest>'; $xml .= '<ns1:WebAuthenticationDetail>'; $xml .= '<ns1:UserCredential>'; $xml .= '<ns1:Key>FEDEX TEST KEY</ns1:Key>'; // Use your Fedex Test Key Here $xml .= '<ns1:Password>FEDEX PASSWORD</ns1:Password>'; //// Use your Fedex Test Password Here $xml .= '</ns1:UserCredential>'; $xml .= '</ns1:WebAuthenticationDetail>'; $xml .= '<ns1:ClientDetail>'; $xml .= '<ns1:AccountNumber>876453585</ns1:AccountNumber>'; $xml .= '<ns1:MeterNumber>1435364008</ns1:MeterNumber>'; $xml .= '</ns1:ClientDetail>'; $xml .= '<ns1:TransactionDetail>'; $xml .= '<ns1:CustomerTransactionId> *** Rate Request v13 using PHP ***</ns1:CustomerTransactionId>'; $xml .= '</ns1:TransactionDetail>'; $xml .= '<ns1:Version>'; $xml .= '<ns1:ServiceId>crs</ns1:ServiceId>'; $xml .= '<ns1:Major>13</ns1:Major>'; $xml .= '<ns1:Intermediate>0</ns1:Intermediate>'; $xml .= '<ns1:Minor>0</ns1:Minor>'; $xml .= '</ns1:Version>'; $xml .= '<ns1:ReturnTransitAndCommit>true</ns1:ReturnTransitAndCommit>'; $xml .= '<ns1:RequestedShipment>'; $xml .= '<ns1:DropoffType>REGULAR_PICKUP</ns1:DropoffType>'; $xml .= '<ns1:PackagingType>YOUR_PACKAGING</ns1:PackagingType>'; $xml .= '<ns1:TotalInsuredValue>'; $xml .= '<ns1:Currency>USD</ns1:Currency>'; $xml .= '</ns1:TotalInsuredValue>'; $xml .= '<ns1:Shipper>'; $xml .= '<ns1:Contact>'; $xml .= '<ns1:PersonName>Shipper Test Address</ns1:PersonName>'; $xml .= '<ns1:CompanyName>Sample Company</ns1:CompanyName>'; $xml .= '<ns1:PhoneNumber>800-5435-6789</ns1:PhoneNumber>'; $xml .= '</ns1:Contact>'; $xml .= '<ns1:Address>'; $xml .= '<ns1:StreetLines>1300 Basswood Road</ns1:StreetLines>'; $xml .= '<ns1:City></ns1:City>'; $xml .= '<ns1:StateOrProvinceCode>IL</ns1:StateOrProvinceCode>'; $xml .= '<ns1:PostalCode>60173</ns1:PostalCode>'; $xml .= '<ns1:CountryCode>US</ns1:CountryCode>'; $xml .= '</ns1:Address>'; $xml .= '</ns1:Shipper>'; $xml .= '<ns1:Recipient>'; $xml .= '<ns1:Contact>'; $xml .= '<ns1:PersonName>Harish</ns1:PersonName>'; $xml .= '<ns1:CompanyName>Test</ns1:CompanyName>'; $xml .= '<ns1:PhoneNumber>98656789130</ns1:PhoneNumber>'; $xml .= '</ns1:Contact>'; $xml .= '<ns1:Address>'; $xml .= '<ns1:StreetLines>32 wall street albany</ns1:StreetLines>'; $xml .= '<ns1:City>Atlanta</ns1:City>'; $xml .= '<ns1:StateOrProvinceCode>GA</ns1:StateOrProvinceCode>'; $xml .= '<ns1:PostalCode>30318</ns1:PostalCode>'; $xml .= '<ns1:CountryCode>US</ns1:CountryCode>'; $xml .= '<ns1:Residential>true</ns1:Residential>'; $xml .= '</ns1:Address>'; $xml .= '</ns1:Recipient>'; $xml .= '<ns1:ShippingChargesPayment>'; $xml .= '<ns1:PaymentType>SENDER</ns1:PaymentType>'; $xml .= '<ns1:Payor>'; $xml .= '<ns1:ResponsibleParty>'; $xml .= '<ns1:AccountNumber>876453585</ns1:AccountNumber>'; $xml .= '</ns1:ResponsibleParty>'; $xml .= '</ns1:Payor>'; $xml .= '</ns1:ShippingChargesPayment>'; $xml .= '<ns1:RateRequestTypes>PREFERRED</ns1:RateRequestTypes>'; $xml .= '<ns1:PackageCount>1</ns1:PackageCount>'; $xml .= '<ns1:RequestedPackageLineItems>'; $xml .= '<ns1:SequenceNumber>1</ns1:SequenceNumber>'; $xml .= '<ns1:GroupPackageCount>1</ns1:GroupPackageCount>'; $xml .= '<ns1:Weight>'; $xml .= '<ns1:Units>LB</ns1:Units>'; $xml .= '<ns1:Value>45</ns1:Value>'; $xml .= '</ns1:Weight>'; $xml .= '<ns1:Dimensions>'; $xml .= '<ns1:Length>12</ns1:Length>'; $xml .= '<ns1:Width>9</ns1:Width>'; $xml .= '<ns1:Height>8</ns1:Height>'; $xml .= '<ns1:Units>IN</ns1:Units>'; $xml .= '</ns1:Dimensions>'; $xml .= '</ns1:RequestedPackageLineItems>'; $xml .= '</ns1:RequestedShipment>'; $xml .= '</ns1:RateRequest>'; $xml .= '</SOAP-ENV:Body>'; $xml .= '</SOAP-ENV:Envelope>'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, '<a href="https://wsbeta.fedex.com/web-services/rate">https://wsbeta.fedex.com/web-services/rate</a>'); 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); $result_xml = str_replace(array(':','-'), '', $result_xml); $result = @simplexml_load_string($result_xml); echo "<pre>"; print_r($result); ?> |
This API code gives you Fedex business shipping rate list based on the Item Weight. If you need only one lowest shipping rate, than use ACCOUNT in RateRequestTypes instead of ‘LIST’ parameter value in above XML request.
Also Read This:
Generate Fedex Multiple Shipment Label using API Call
Also must change Shipper and Recipient Address with your own Test Development Key Address. This address you got when you receive Developer Test key from Fedex. This is very much required otherwise you did not get Success Response. If facing any issue feel free to contact me. Thanks