How to Print Fedex Shipping label via API call in PHP

In this post, we will explain to you how we use FedEx api to create a shipping label in PHP. First, you have to send the shipment request to confirm shipping then print the shipping label.

First use your FedEx Test developer access to generate your first label. You can not use production account access directly for label generation, this will gives you an authentication error.

To get production account access, first you have to generate some FeDex labels like Ground Label, Label with Signature, COD etc. Then have to send these labels to Fedex support for evaluation purpose. They will review your labels and verify it.

Then they will actiavte your Live Fedex Shipping API access, just replace with test account access and use it for live transactions on your application.

Generate FedEx shipping label via API in PHP:

Step 1: We are using a PHP soap client request to generate FedEx label.

You can download official Fedex Soap Request library from fedex developer account.

Firstly include “ShipService_v19.wsdl” file in your PHP file. Make sure that API Eeb Request URL point to test fedex api server in WSDL file. (For Production account, change it with live API web request URL).

Step 2: Create a Label.php file using the below code. Which call the FedEx test API request url.

After this request, success response will shows on screen, along with the Fedex Label Image code. You can create label image using that response code.

You can also create a custom fedex shipping label as per your requirement. Follow this Fedex Developer Guide Reference.

Also Read This:

Create Fedex Multiple Package Shipment Label
How to Install Magento Security Patch via Putty

We can also use simple xml request parameter for creating FedEx api label in php using curl method. Although above method is quite easy to implement on website.

 

Recommended Posts For You

About Harish

I am professional web developer and blogger. Use this blog to share own api and other web development experience with you. I do accept paid work. Write to me at - [email protected]

View all posts by Harish

77 thoughts on “How to Print Fedex Shipping label via API call in PHP”

    1. Hello Kausik,
      Which service type you use for generate shipping label ? Can you share your soap request code ?

        1. Hi Ahmad,

          I think you should check the error response first. If you getting label image data in response than it should be problem in convert it into an image.

  1. Hi Harish,

    I simply uploaded ShipService_v17.wsdl and label.php with your code under a folder and tried to execute the php file. Do I need to do any thing else? If you share your email id, I can share test key and other details.

  2. Hi again,
    in your code what are parent and user credential? IN FEDX php code also I don’t see any such reference. Can you please explain?

    $request[‘WebAuthenticationDetail’] = array(
    ‘ParentCredential’ => array(
    ‘Key’ => ‘EPLkBjBoWJL4gWDz’,
    ‘Password’ => ‘6RrOFaG3V9hP2tRwll58Tunb0’
    ),
    ‘UserCredential’ => array(
    ‘Key’ => ‘EPLkBjBoWJL4gWDz’,
    ‘Password’ => ‘6RrOFaG3V9hP2tRwll58Tunb0’
    )

  3. Dear Harish,

    I mailed you the file with code in the morning, did you get chance to check it?

    Regards,
    Kausik

    1. Hi Kausik,
      I tried your code with my fedex test account access. Its work fine. You should change Shipper Address and Recipient address by own developer test address.

      When you create fedex development key, they will mail you test address for using fedex services.

  4. sir i need some help to integrate fedex api to my website
    ,i want to check availiability of service of fedex depend on postal code

    1. Hello sandeep,

      I think for this you need to run Fedex Postal Code Inquiry api. Which give result shipping available on particular post code or not.

  5. I used same Test key & password in credentials
    but I am getting this error

    Severity: ERROR
    Source: prof
    Code: 1000
    Message: Authentication Failed

    1. Hi Tut,

      You must use Test Development Access, which you got at the time of registration in fedex account.

      Also for label request change shipper and recipient address as per your fedex account.

  6. Hello Harish ,
    I did all chages suggested by you still it shows authentication failed error.Please check my attached file on your mail and suggest me appropriate changes.

  7. Which account number is used in script?
    That is define in Test password mail.Or that are defined in shipper and recipient address.

    1. Hi Rohit,

      Authentication error comes when you trying to create fedex label using production account access without evaluation process. Are you using right developer access in it ?

  8. Hi Harish,

    I am doing integration of fedex api in php, I use rate available api to get list of services. But can you help to for next step. i think we have to place shipping order to get tracking code.

    So, it will be helpful if you provide some information on it.

    1. Hi sam,

      You have to write Fedex Shipping label code to get tracking code. Just place a test order with fedex service type to create shipping label. I hope this post will help to do this.

      Thanks

      1. Thanks for your prompt reply, as in create shipment there are different folders and each have shipment file init. so which one i use as i want to create shipment for india. (like: form india to india).

        1. Yes exactly , i also wants same.. when using india to india address,, fedexp apj not supported at all.

    1. Hi Rohit,

      If you are using FEDEX_GROUND service type than COD parameter is required in label request. For print Non COD Fedex label for other service, just remove these request parameter from label request code.

      ‘SpecialServicesRequested’ => array(
      ‘SpecialServiceTypes’ => ‘COD’,
      ‘CodDetail’ => array(
      ‘CodCollectionAmount’ => array(
      ‘Currency’ => ‘USD’,
      ‘Amount’ => ‘10.0’
      ),
      ‘CollectionType’ => ‘ANY’
      )
      )

  9. I have used this code , but when i enter indian address . i have received following error;
    [Notifications] => stdClass Object
    (
    [Severity] => ERROR
    [Source] => ship
    [Code] => 2449
    [Message] => Customs Clearance Detail is required
    [LocalizedMessage] => Customs Clearance Detail is required
    )

    but when i use outside india .. its working ..
    so my concern is that , why i receiving that customclearance error in india address.

    1. Hi Piyush,

      Fedex have different policies for each country. If custom clearance is required for India country than you should pass those parameters in API request. This given code belong to US country.

      Thanks

    1. Hello , Could you please send me code that is related to india.. ? please send Label.php according to india shipping label format.

      1. Well, currently i don’t have Fedex shipping code for India country basis. You should check Fedex api documentation to create an request for it.

  10. I have used your code but I am unable to generate label. So can you please let me know how can I generate the fedex label in png format?

    1. Hi,

      Have you check label generation API call response. Should cross check it, it must parameter issue.

      For png label, change parameter value in LabelSpecification parameter. Follow Fedex official developer documentation for valid parameters and corresponding values.

      Thanks

    1. Hi Karan,

      I have explained here how to execute FedEX api call and print shipping label. You should follow fedex official documentation to create API request as per your need. If you need my service to create FedEX APIs call, inbox me on [email protected].

      Thanks

    1. Hi Mustafa,

      This is a valid function, above mentioned Fedex API code is valid. I have tested so many times.

      What issue you facing ? Please tell me.

      Thanks

    1. Hi Philipp,

      I think you should check the response first. Something not right in your API request. In API response you will get the error detail.

      Just print_r($response); this.

      Thanks

      1. Thanks for the hint! 🙂 There was something wrong with the Zip Code. Now it works.

        Best Regards

        Philipp

  11. Hello,

    I am new for fedex system. I want to implement fedex API for generate shipping label. Can you provide me working code for testing purpose.

    Please reply me as soon as possible.

    Thanks
    Ansari Umair

    1. Hi Umair,

      I have mentioned working code here. You can implement using it. What problem you facing to use it ?

      If you need my service to create fedex shipping label code, please inbox me : [email protected]

      Thanks

  12. Hello,

    I am running into an issue with creating a Return Label. I am getting PHP errors rather than it giving me XML output error. Uncaught SoapFault exception: [SOAP-ENV:Server] SoapClient->__call(‘processShipment’, Array)

    All I changed was this:
    ‘SpecialServicesRequested’ => array(
    ‘SpecialServiceTypes’ => ‘RETURN_SHIPMENT’,
    ‘ReturnShipmentDetail’ => array(
    ‘ReturnType’ => ‘FEDEX_TAG’,
    ‘Rma’ => array(
    ‘Number’ => ‘012’,
    ‘Reason’ => ‘reason’
    )
    )
    )

    1. I also tried this:

      ‘SpecialServicesRequested’ => array(
      ‘SpecialServiceTypes’ => array(‘RETURN_SHIPMENT’),
      ‘ReturnShipmentDetail’ => ‘ReturnType’,
      ‘Value’ => ‘PRINT_RETURN_LABEL’
      )

  13. Hi,

    I have liked the page on facebook for unblock the Label.php content, But Still I am not able to see the content code of Label.php, So can you please provide the code for Label.php.

    Thanks.

    1. Hi Vince,

      I already mentioned code details above, you can make your own script using it. If you facing issues, i will make Fedex API script for you, but this is paid service.

      Thanks

  14. Hi Harish,

    thanks for your great script. we have extended the script that we can generate commercial invoices for international shipments. we would like to integrate our own company logo like it is when we generate the invoice by the fedex webpage.

    do you have any sample code or a tip?

    Thanks.

    1. Hi,

      I don’t have ready code for this, but I think you can do this in two ways, First from the FedEx account setting and second you have to find the relevant parameter in shipment create API documentation for this.

  15. Hi Harish
    I tried your code but getting some issues regarding credentials showing when i tried to call file on the frontend.
    I had sent you a mail regarding this issue yesterday.pls review that and help me
    ERROR: SOAP Fault: (faultcode: Client, faultstring: SOAP-ERROR: Encoding: object has no ‘UserCredential’ property) in /var/www/html/Label.php on line 140
    Thanks

  16. Hi Harish,
    I tried your code and a response is coming but the label image is not generated.
    ex:

    [Label] => stdClass Object
    (
    [Type] => OUTBOUND_LABEL
    [ShippingDocumentDisposition] => RETURNED
    [ImageType] => PDF
    [Resolution] => 200
    [CopiesToPrint] => 1
    [Parts] => stdClass Object
    (
    [DocumentPartSequenceNumber] => 1
    [Image] => %PDF-1.4

    Thanks

    1. Hi Komal, i think this is becuase of incorrect parameters request. Please cross check it again Or i suggest to buy working Fedex Shipping Label code from my website.

  17. Hi Harish,
    I tried your code and a response is coming and the image also generating but getting a warning
    “Unable to obtain courtesy rates”.

    pls, help me on this why it is showing warning earlier it does not show any warning.

  18. stdClass Object
    (
    [HighestSeverity] => ERROR
    [Notifications] => stdClass Object
    (
    [Severity] => ERROR
    [Source] => ship
    [Code] => 2467
    [Message] => shippingChargesPayment is required
    [LocalizedMessage] => shippingChargesPayment is required
    )

    [TransactionDetail] => stdClass Object
    (
    [CustomerTransactionId] => ProcessShip_Basic
    )

    [Version] => stdClass Object
    (
    [ServiceId] => ship
    [Major] => 19
    [Intermediate] => 0
    [Minor] => 0
    )

    )

    Hello please tell me what should i do
    what i miss

    1. Hi, you have missed ‘ShippingChargesPayment’ parameter in create shipment API request. Use below parameters:

      ‘ShippingChargesPayment’ => array(
      ‘PaymentType’ => ‘SENDER’,
      ‘Payor’ => array(
      ‘ResponsibleParty’ => array(
      ‘AccountNumber’ => ‘********’, // enter your Fedex Account Number
      ‘Contact’ => null,
      ‘Address’ => array(
      ‘CountryCode’ => ‘IN’
      )
      )
      )
      )

Leave a Reply to Chris Cancel Reply

Your email address will not be published. Required fields are marked *