views:

200

answers:

2

I am trying to connect to the FedEx shipping webservice v8.

Everything works fine when I only have one RequestedPackageLineItems set. When I add two items I get the following error.

"Invalid package count or invalid package sequence number."

My Code is as follows

ProcessShipmentRequest request = CreatePendingShipmentRequest();
ShipService service = new ShipService();
ProcessShipmentReply reply = service.processShipment(request);
...

private static ProcessShipmentRequest CreatePendingShipmentRequest()
{
    ProcessShipmentRequest request = new ProcessShipmentRequest();

    request.WebAuthenticationDetail = new WebAuthenticationDetail();
    request.WebAuthenticationDetail.UserCredential = new WebAuthenticationCredential();
    request.WebAuthenticationDetail.UserCredential.Key = "XXX"; 
    request.WebAuthenticationDetail.UserCredential.Password = "XXX";            
    request.ClientDetail = new ClientDetail();
    request.ClientDetail.AccountNumber = "XXX";
    request.ClientDetail.MeterNumber = "XXX"; 

    request.TransactionDetail = new TransactionDetail();
    request.TransactionDetail.CustomerTransactionId = "*** Ground Domestic Shipping Request v8 using C# ***";
    request.Version = new VersionId();

    //Inside this method I set request.RequestedShipment.PackageCount = "2";
    SetShipmentDetails(request);
    SetPackageLineItems(request);

    return request;
}

private static void SetPackageLineItems(ProcessShipmentRequest request)
{                   
    request.RequestedShipment.RequestedPackageLineItems = new RequestedPackageLineItem[2];
    request.RequestedShipment.RequestedPackageLineItems[0] = new RequestedPackageLineItem();
    request.RequestedShipment.RequestedPackageLineItems[0].SequenceNumber = "1";
    request.RequestedShipment.RequestedPackageLineItems[0].Weight = new Weight();
    request.RequestedShipment.RequestedPackageLineItems[0].Weight.Value = 50.0M;
    request.RequestedShipment.RequestedPackageLineItems[0].Weight.Units = WeightUnits.LB;
    request.RequestedShipment.RequestedPackageLineItems[0].ItemDescription = "Item";
    request.RequestedShipment.RequestedPackageLineItems[0].Dimensions = new Dimensions();
    request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Length = "108";
    request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Width = "5";
    request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Height = "5";
    request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Units = LinearUnits.IN;

    request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences = new CustomerReference[3];
    request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[0] = new CustomerReference();
    request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[0].CustomerReferenceType = CustomerReferenceType.CUSTOMER_REFERENCE;
    request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[0].Value = "[LOT NUMBER]";
    request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[1] = new CustomerReference();
    request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[1].CustomerReferenceType = CustomerReferenceType.INVOICE_NUMBER;
    request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[1].Value = "45646";
    request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[2] = new CustomerReference();
    request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[2].CustomerReferenceType = CustomerReferenceType.P_O_NUMBER;
    request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[2].Value = "456446";

    request.RequestedShipment.RequestedPackageLineItems[1] = new RequestedPackageLineItem();
    request.RequestedShipment.RequestedPackageLineItems[1].SequenceNumber = "2";
    request.RequestedShipment.RequestedPackageLineItems[1].Weight = new Weight();
    request.RequestedShipment.RequestedPackageLineItems[1].Weight.Value = 50.0M;
    request.RequestedShipment.RequestedPackageLineItems[1].Weight.Units = WeightUnits.LB;
    request.RequestedShipment.RequestedPackageLineItems[1].ItemDescription = "Item";
    ....
}
A: 

Found out how to do this.

In order to get multiple shipping labels into one pdf the process is as follows.

  1. Create a request
  2. Fill in the shipping info
  3. Post and get a reply.
  4. Save that replay and the byte array and MasterShippingID
  5. Create a new request and assign the master shipping id to it.
  6. Added shipping weight and dimensions
  7. Post and get reply
  8. Save byte array with the other
  9. Continue until all shipments are generated (max 200 per master shipping id)
  10. Merge all the pdfs returned from FedEx into one pdf.
  11. Do a happy dance.
MIchael Grassman
+1  A: 

Michael, I see your answer. Doesn't that get sticky when doing alot of packages in one shippment? i mean if you have 10 packages, does that mean you need 10 web service calls? Isn't there a way to roll it all together in one or two calls? Thanks

Elliot
If you can find a way that would be awesome the code from fedex requires multiple calls. It seems bizarre to me also.I'm marking your response up because that would be the best way to deal with it in my opinion.
MIchael Grassman
If you have 10 packages, then you need 10 Web service calls, yes. I know that the API seems to have room for multiple line items, but it simply does not work and the documentation advises you to make the separate requests (passing in the master ID for requests 2-10). It is really that stupid, but I don't see them changing it anytime soon. The only improvements they seem to make are randomly rearranging and renaming elements in the schema every few months. (Just take a look at V9 and sob.)
Nicholas Piasecki