'Could not complete call Rate from Fedex Freight Rate

I am trying to call Fedex Freight API. I tried to find the complete working service for 3 days but no luck. Also read all the XML, PDF docs but still could not call it.

I downloaded php file from their Fedex Developer portal and replaced my information in the fedex-common.php5.

I hope FedEx developer portal published complete working file. Please point where I made mistake.

Thank you

In short here is the error:

Severity: ERROR
Source: crs
Code: 2103
Message: FreightLineItemId for Freight shipment line item 1 is missing or invalid.
LocalizedMessage: FreightLineItemId for Freight shipment line item 1 is missing or invalid.
Id: FREIGHT_SHIPMENT_LINE_ITEM
Value: 1

In details: Here is my RateWebServiceClient.php file:

<?php
// Copyright 2009, FedEx Corporation. All rights reserved.
// Version 12.0.0

require_once('../../fedex-common.php5');

$newline = "<br />";
//The WSDL is not included with the sample code.
//Please include and reference in $path_to_wsdl variable.
$path_to_wsdl = "../wsdl/RateService_v31.wsdl";

ini_set("soap.wsdl_cache_enabled", "0");

$client = new SoapClient($path_to_wsdl, array('trace' => 1)); // Refer to http://us3.php.net/manual/en/ref.soap.php for more information

$request['WebAuthenticationDetail'] = array(
    'ParentCredential' => array(
        'Key' => getProperty('parentkey'),
        'Password' => getProperty('parentpassword')
    ),
    'UserCredential' => array(
        'Key' => getProperty('key'),
        'Password' => getProperty('password')
    )
);
$request['ClientDetail'] = array(
    'AccountNumber' => getProperty('shipaccount'),
    'MeterNumber' => getProperty('meter')
);
$request['TransactionDetail'] = array('CustomerTransactionId' => ' *** Rate Request using PHP ***');
$request['Version'] = array(
    'ServiceId' => 'crs',
    'Major' => '31',
    'Intermediate' => '0',
    'Minor' => '0'
);
$request['ReturnTransitAndCommit'] = true;
$request['RequestedShipment']['DropoffType'] = 'REGULAR_PICKUP'; // valid values REGULAR_PICKUP, REQUEST_COURIER, ...
$request['RequestedShipment']['ShipTimestamp'] = date('c');
$request['RequestedShipment']['ServiceType'] = 'FEDEX_FREIGHT_ECONOMY'; // valid values STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, ...
$request['RequestedShipment']['PackagingType'] = 'YOUR_PACKAGING'; // valid values FEDEX_BOX, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING, ...
$request['RequestedShipment']['Shipper'] = getProperty('shipper');
$request['RequestedShipment']['Recipient'] = addRecipient();
$request['RequestedShipment']['ShippingChargesPayment'] = addShippingChargesPayment();
$request['RequestedShipment']['FreightShipmentDetail'] = array(
    'FedExFreightAccountNumber' => getProperty('freightaccount'),
    'FedExFreightBillingContactAndAddress' => getProperty('freightbilling'),
    'Role' => 'SHIPPER',
    'PaymentType' => 'PREPAID',
    'CollectTermsType' => 'STANDARD',
    'LineItems' => array(
        'FreightClass' => 'CLASS_050',
        'Weight' => array(
            'Value' => 777.0,
            'Units' => 'LB'
        ), 'Dimensions' => array(
    'Length' => 44,
    'Width' => 44,
    'Height' => 2,
    'Units' => 'IN'
),
    )
);
$request['RequestedShipment']['RateRequestTypes'] = 'ACCOUNT';
$request['RequestedShipment']['RateRequestTypes'] = 'LIST';
$request['RequestedShipment']['PackageCount'] = '1';


try {
    if (setEndpoint('changeEndpoint')) {
        $newLocation = $client->__setLocation(setEndpoint('endpoint'));
    }

    $response = $client->getRates($request);
    if ($response->HighestSeverity != 'FAILURE' && $response->HighestSeverity != 'ERROR') {
        $rateReply = $response->RateReplyDetails;
        echo '<table border="1">';
        echo '<tr><th>Rate Details</th><th>&nbsp;</th></tr>';
        trackDetails($rateReply, '');
        echo '</table>';

        printSuccess($client, $response);
    } else {
        printError($client, $response);
    }

    writeToLog($client);    // Write to log file   
} catch (SoapFault $exception) {
    printFault($exception, $client);
}


function addRecipient()
{
    $recipient = array(
        'Contact' => array(
            'PersonName' => 'Sender Name',
            'CompanyName' => 'Sender Company Name',
            'PhoneNumber' => '1234567890'
        ),
        'Address' => array(
            'StreetLines' => array('12148 Jollyville Rd'),
            'City' => 'Austin',
            'StateOrProvinceCode' => 'TX',
            'PostalCode' => '78759',
            'CountryCode' => 'US'
        )
    );
    return $recipient;
}

function addShippingChargesPayment()
{
    $shippingChargesPayment = array(
        'PaymentType' => 'SENDER', // valid values RECIPIENT, SENDER and THIRD_PARTY
        'Payor' => array(
            'ResponsibleParty' => array(
                'AccountNumber' => getProperty('freightaccount'),
                'CountryCode' => 'US')
        )
    );
    return $shippingChargesPayment;
}

function addShipper()
{
    $shipper = array
    (
        'Contact' => array
        (
            'PersonName' => 'Rubaiet M',
            'CompanyName' => 'ELS',
            'PhoneNumber' => '019130191355'
        ),
        'Address' => array(
            'StreetLines' => array('1100 E Howard Ln'),
            'City' => 'Austin',
            'StateOrProvinceCode' => 'TX',
            'PostalCode' => '78753',
            'CountryCode' => 'US'
        )
    );
    return $shipper;
} // end of function addShipper

?>

Here is the Response from Fedex XML

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><RateReply xmlns="http://fedex.com/ws/rate/v31"><HighestSeverity>ERROR</HighestSeverity><Notifications><Severity>ERROR</Severity><Source>crs</Source><Code>2103</Code><Message>FreightLineItemId for Freight shipment line item 1 is missing or invalid.</Message><LocalizedMessage>FreightLineItemId for Freight shipment line item 1 is missing or invalid.</LocalizedMessage><MessageParameters><Id>FREIGHT_SHIPMENT_LINE_ITEM</Id><Value>1</Value></MessageParameters></Notifications><TransactionDetail><CustomerTransactionId> *** Rate Request using PHP ***</CustomerTransactionId></TransactionDetail><Version><ServiceId>crs</ServiceId><Major>31</Major><Intermediate>0</Intermediate><Minor>0</Minor></Version></RateReply></SOAP-ENV:Body></SOAP-ENV:Envelope>


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source