0

Hello I am using a simple code to get the shipping fee of a product from USA to Canada. I am using python-sp-api library.

I have searched the docs for appropiate body for this post request and you can find below the content I am sending

Here is the code I am using:

    from sp_api.api import Shipping
    from sp_api.base import Marketplaces
     
    credentials=dict(
        
            refresh_token='*******',
            lwa_app_id='********',
            lwa_client_secret='******',
            aws_secret_key='*****',
            aws_access_key='****',
            role_arn='arn:aws:iam::882****:role/FTSPAPIRole'
        )
     
    ship_obj = Shipping(credentials=credentials, marketplace=Marketplaces.CA)
    rates = ship_obj.get_rates(body={
      "shipTo": {
        "name": "Ellen Adams",
        "addressLine1": "8 Industrial Rd",
        "addressLine2": "",
        "addressLine3": "",
        "stateOrRegion": "MA",
        "city": "Milford",
        "countryCode": "US",
        "postalCode": "01757",
        "email": "testmainmail@gmail.com",
        "copyEmails": [
          "testmail@gmail.com"
        ],
        "phoneNumber": "917066033"
      },
      "shipFrom": {
        "name": "Jack Williams",
        "addressLine1": "38 Wellington St",
        "addressLine2": "",
        "addressLine3": "",
        "stateOrRegion": "Ontario",
        "city": "St Thomas",
        "countryCode": "CA",
        "postalCode": "N5R 2P4",
        "email": "testmail2@gmail.com",
        "copyEmails": [
          "testmail3@gmail.com"
        ],
        "phoneNumber": "5196144583"
      },
      "serviceTypes": [
        "Amazon Shipping Ground"
      ],
      "shipDate": "2019-08-24T14:15:22Z",
      "containerSpecifications": [
        {
          "dimensions": {
            "length": 23.62,
            "width": 20.83,
            "height": 2.29,
            "unit": "CM"
          },
          "weight": {
            "unit": "g",
            "value": 204
          }
        }
      ]
})

Here is the response I am getting:

[
   {
      "code":"InvalidInput",
      "message":"Invalid input.",
      "details":"4 validation errors detected: Value null at 'containerSpecifications' failed to satisfy constraint: Member must not be null; Value at 'shipFrom' failed to satisfy constraint: Member must not be null; Value null at 'serviceTypes' failed to 
satisfy constraint: Member must not be null; Value at 'shipTo' failed to satisfy constraint: Member must not be null"
   }
]

Any Idea how I can fix this?

  • I'm not entirely sure, but from https://developer-docs.amazon.com/sp-api/docs/shipping-api-v1-reference#address, it looks like the addressLines have a minLength of 1. Try putting ```" "``` for the ```addressLine2```, etc.. Though the complaint of the ```containerSpecifications``` is a little strange. – ewokx Jun 08 '22 at 00:12

1 Answers1

0

I know this is old, but I ran into the same issue exactly. Here's what fixed it for me:

Instead of:

get_rates(body={...})

do this:

get_rates(**{...})

This passes the request dictionary as kwargs as described here: Converting Python dict to kwargs?