How to Print Fedex Shipping label via API call in PHP

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

Use you FedEx test developer account for label generation. You can not use direct production account access for label generation. Because FedEx did not allow this and give an authentication error. When you print shipping label using test account than pass label format to FedEx for evaluation. Fedex will check your label format and provided information and than approve it for production account.

You need to certified fedex account for use production access for shipping and label generation.

Steps to print fedex shipping label via API in PHP:

Step 1: We are using soap client request for FedEx label. For this you need to include “ShipService_v19.wsdl” file.

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


After using this file label image will show on screen. You can also create custom fedex shipping label as per your requirement. Follow this Fedex Developer Guide Reference.

Also Read This:

How to Create Fedex Multiple Package Shipment Label using API Call in PHP
How to Add New Product in Bigcommerce via API V2
How to Insert New Lead Data in Zoho CRM Through API
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.

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

  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.

    • Have you change shiptimestamp with next shipping date in request ? Still facing issue, mail me info on this id “codefixup@gmail.com”

  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’
    )

    • 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.

  3. 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

    • 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.

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

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

  5. 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.

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

  7. 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.

    • 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

      • 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).

    • 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’
      )
      )

  8. 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.

    • 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

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

      • 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.

  9. 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?

    • 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

    • 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 codefixup@gmail.com.

      Thanks

    • 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

  10. 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

    • 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 : codefixup@gmail.com

      Thanks

  11. 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’
    )
    )
    )

    • I also tried this:

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

Leave a Comment