Search code examples
jsonrestpostmanfedex

Restful FedEx Trade Document Upload API - Can't upload signature or letterhead images


I am working on the integration of FedEx Restful APIs. I have to call uploading images API so that I can use customized letterhead and signature in Ship API when requesting FedEx commercial invoice with ETD.

FedEx Trade Document Upload API: https://developer.fedex.com/api/en-us/catalog/upload-documents/v1/docs.html

FedEx provides two testing upload API endpoints:

  1. Upload document: https://documentapitest.prod.fedex.com/sandbox/documents/v1/etds/upload

  2. Upload images: https://documentapitest.prod.fedex.com/sandbox/documents/v1/lhsimages/upload

I was able to send the request successfully through Postman for first one (upload documents) but the second one is failed. Also, I found the request body in FedEx developer portal example is different from document.

I am using Postman to send the request to test the API and here is how my request looks like (key-value)

  • Header

    • x-customer-transaction-id: "12345"
    • Content-Type: "multipart/form-data"
    • Accept: application/json
    • Authorization: Bearer {{FedEx_Token}}
  • Body (form-data)

    • attachment: "file"
    • document: {"referenceId":"12345","name":"IMAGE_1_LETTERHEAD.PNG","contentType":"image/png","rules":{"workflowName":"LetterheadSignature"},"meta":{"imageType":"LETTERHEAD","imageIndex":"IMAGE_1"}}

The document value JSON is converted from this:

{
  "referenceId": "12345",
  "name": "IMAGE_1_LETTERHEAD.PNG",
  "contentType": "image/png",
  "rules": {
    "workflowName": "LetterheadSignature"
  },
  "meta": {
    "imageType": "LETTERHEAD",
    "imageIndex": "IMAGE_1"
  }
}

Response Error:

{
    "customerTransactionId": "123456",
    "errors": {
        "code": "1001",
        "message": "Invalid request: invalid input : WorkFlow Name"
    }
}

sandbox example FedEx provided

I also tried to use sandbox example FedEx provided and the payload like this:

document: {"document": {"referenceId": "1234", "name": "LH2.PNG",    "contentType": "image/png",    "meta": { "imageType": "SIGNATURE","imageIndex": "IMAGE_1"}},"rules": {"workflowName": "LetterheadSignature" }}
attachment: file.PNG

However, I still got the same error code saying workflow name is invalid, so please help me I am trying but I don't really know what I missed. Thank you!


Solution

  • So, being working on exactly the same subject and after trial and error and contacting a Fedex Tech Support agent, I finally managed to find what's causing the error.

    That is the order of the parameters in the request. You have to put the "document" param before the "attachment" param.

    Also, the correct payload is the one in the sandbox console and not the one in the doc. Next is an example of a working "document" field :

    {
        "document": {
            "referenceId": "Test",
            "name": "IMAGE_1.png",
            "contentType": "image/png",
            "meta": {
                "imageType": "SIGNATURE",
                "imageIndex": "IMAGE_1"
            }
        },
        "rules": {
            "workflowName": "LetterheadSignature"
        }
    }
    

    Hope it helps !