Creating a HTTP Post Call for FedEx Web Services

Viewed 1671

FedEx Web Services docs state:

FedEx offers a plain XML web services solution that you can use to send transactions without having to use tools that provide SOAP protocol support for web services.

And here is an example they've used in their docs as well:

Example 3: HTTP POST
The following HTTP POST example is a valid working example. It is not guaranteed to work for all
programming languages, applications, and host systems:
POST /xml HTTP/1.0
Referrer: YourCompanyNameGoesHere
Host: ws.fedex.com
Port: 443
Accept: image/gif, image/jpeg, image/pjpeg, text/plain, text/html, */*
Content-Type: text/xml
Content-length: %d
Your FedEx Transaction

------------------------

Each line is followed by one new line character except Content-length and the FedEx transaction. Two new
line characters follow the Content-length line. The FedEx transaction has no extra characters. The Content length line should have the length of the FedEx transaction in place of the %d variable.

If I wanted to set up a plain xml transaction using an HTTP post call in kotlin, what would that entail of?

Here is the SOAP WSDL I'd like to send. Tracking a shipment via passing in a tracking number

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v18="http://fedex.com/ws/track/v18">
   <soapenv:Header/>
   <soapenv:Body>
      <v18:TrackRequest>
         <v18:WebAuthenticationDetail>
            <v18:ParentCredential>
               <v18:Key>INPUT YOUR INFORMATION</v18:Key>
               <v18:Password>INPUT YOUR INFORMATION</v18:Password>
            </v18:ParentCredential>
            <v18:UserCredential>
               <v18:Key>INPUT YOUR INFORMATION</v18:Key>
               <v18:Password>INPUT YOUR INFORMATION</v18:Password>
            </v18:UserCredential>
         </v18:WebAuthenticationDetail>
         <v18:ClientDetail>
            <v18:AccountNumber>INPUT YOUR INFORMATION</v18:AccountNumber>
            <v18:MeterNumber>INPUT YOUR INFORMATION</v18:MeterNumber>
            <v18:Localization>
               <v18:LanguageCode>EN</v18:LanguageCode>
            </v18:Localization>
         </v18:ClientDetail>
         <v18:TransactionDetail>
            <v18:CustomerTransactionId>Track By Number_v18</v18:CustomerTransactionId>
            <v18:Localization>
               <v18:LanguageCode>EN</v18:LanguageCode>
               <v18:LocaleCode>US</v18:LocaleCode>
            </v18:Localization>
         </v18:TransactionDetail>
         <v18:Version>
            <v18:ServiceId>trck</v18:ServiceId>
            <v18:Major>18</v18:Major>
            <v18:Intermediate>0</v18:Intermediate>
            <v18:Minor>0</v18:Minor>
         </v18:Version>
         <v18:SelectionDetails>
            <v18:CarrierCode>FDXE</v18:CarrierCode>
            <v18:PackageIdentifier>
               <v18:Type>TRACKING_NUMBER_OR_DOORTAG</v18:Type>
               <v18:Value>INPUT YOUR INFORMATION</v18:Value>
            </v18:PackageIdentifier>
            <v18:ShipmentAccountNumber/>
            <v18:SecureSpodAccount/>
            <v18:Destination>
               <v18:GeographicCoordinates>rates evertitque aequora</v18:GeographicCoordinates>
            </v18:Destination>
         </v18:SelectionDetails>
      </v18:TrackRequest>
   </soapenv:Body>
</soapenv:Envelope>
1 Answers

I recently managed to successfully send a request and get a response back from Fedex. After you do your initial set up on the dev portal (get key, etc.), build and XML that looks something like this (Sample process shipment request).

The key missing piece though is the endpoint. You will not be able to work with the SOAP endpoint. Instead use https://wsbeta.fedex.com:443/xml

Also, change the following headers - as recommended by Fedex

Accept = image/gif, image/jpeg, image/pjpeg, text/plain, text/html, */*;

Content-Type = text/xml

Good luck!!

<?xml version="1.0" encoding="UTF-8"?>
<ProcessShipmentRequest xmlns="http://fedex.com/ws/ship/v26">
    <WebAuthenticationDetail>
        <UserCredential>
            <Key>Input your Key</Key>
            <Password>Input your pwd</Password>
        </UserCredential>
    </WebAuthenticationDetail>
    <ClientDetail>
        <AccountNumber>Input your Account Number</AccountNumber>
        <MeterNumber>Input your meter number</MeterNumber>
    </ClientDetail>
    <!-- <TransactionDetail>
        <CustomerTransactionId>Express Shipment Example</CustomerTransactionId>
    </TransactionDetail> -->
    <Version>
        <ServiceId>ship</ServiceId>
        <Major>26</Major>
        <Intermediate>0</Intermediate>
        <Minor>0</Minor>
    </Version>
    <RequestedShipment>
        <ShipTimestamp>2020-09-01T11:30:40.574Z</ShipTimestamp>
        <DropoffType>REGULAR_PICKUP</DropoffType>
        <ServiceType>FEDEX_GROUND</ServiceType>
        <PackagingType>YOUR_PACKAGING</PackagingType>
        <Shipper>
            <Contact>
                <PersonName>John Doe</PersonName>
                <CompanyName>FedEx</CompanyName>
                <PhoneNumber>9015551234</PhoneNumber>
            </Contact>
            <Address>
                <StreetLines>3610 Hacks Cross Road</StreetLines>
                <StreetLines>First Floor</StreetLines>
                <City>Memphis</City>
                <StateOrProvinceCode>TN</StateOrProvinceCode>
                <PostalCode>38125</PostalCode>
                <CountryCode>US</CountryCode>
            </Address>
        </Shipper>
        <Recipient>
            <Contact>
                <PersonName>Joe Customer</PersonName>
                <CompanyName>ABC Widget Co</CompanyName>
                <PhoneNumber>3305551234</PhoneNumber>
            </Contact>
            <Address>
                <StreetLines>1234 Main Street</StreetLines>
                <StreetLines>Suite 200</StreetLines>
                <City>Akron</City>
                <StateOrProvinceCode>OH</StateOrProvinceCode>
                <PostalCode>44333</PostalCode>
                <CountryCode>US</CountryCode>
                <Residential>false</Residential>
            </Address>
        </Recipient>
        <ShippingChargesPayment>
            <PaymentType>SENDER</PaymentType>
            <Payor>
                <ResponsibleParty>
                    <AccountNumber>Enter Account Number</AccountNumber>
                    <Contact />
                </ResponsibleParty>
            </Payor>
        </ShippingChargesPayment>
        <LabelSpecification>
            <LabelFormatType>COMMON2D</LabelFormatType>
            <ImageType>PDF</ImageType>
            <LabelStockType>PAPER_4X6</LabelStockType>
        </LabelSpecification>
        <PackageCount>1</PackageCount>
        <RequestedPackageLineItems>
            <SequenceNumber>1</SequenceNumber>
            <Weight>
                <Units>LB</Units>
                <Value>10.0</Value>
            </Weight>
            <Dimensions>
                <Length>5</Length>
                <Width>5</Width>
                <Height>5</Height>
                <Units>IN</Units>
            </Dimensions>
            <CustomerReferences>
                <CustomerReferenceType>CUSTOMER_REFERENCE</CustomerReferenceType>
                <Value>ref1234</Value>
            </CustomerReferences>
        </RequestedPackageLineItems>
    </RequestedShipment>
</ProcessShipmentRequest>
Related