Discussions

Ask a Question
Back to All

Request rates (/rates) endpoint not working for sandbox

The request rates endpoint works with with production but not with a sandbox api key:

https://developers.easyship.com/reference/rates_request#

The sandbox environment always responds with this error:

{"error": {"code": "invalid_content",
"details": ["Sorry, we couldn't find any shipping solutions based on the information provided."],
"message": "The request body content is not valid.", "request_id": "4d7ff1fa9f0168996c05d2cd94b1be58",
"type": "invalid_request_error"}}

Here is the python requests code that is not working in the sandbox environment but working in production:

import requests

url = "https://api.easyship.com/2023-01/rates"

payload = {
"origin_address": {
"line_1": "123 E Main St",
"state": "PA",
"city": "Dallastown",
"postal_code": "17313",
"country_alpha2": "US",
"contact_name": "Bob",
"contact_email": "[email protected]"
},
"destination_address": {
"line_1": "123 Test Street",
"state": "CA",
"city": "Beverly HIlls",
"postal_code": "90210",
"country_alpha2": "US",
"contact_name": "Foo Bar",
"contact_email": "[email protected]"
},
"incoterms": "DDU",
"insurance": {"is_insured": False},
"courier_selection": {"apply_shipping_rules": True},
"shipping_settings": {"units": {
"weight": "kg",
"dimensions": "cm"
}},
"parcels": [
{
"box": {
"length": 2,
"width": 2,
"height": 2
},
"items": [
{
"quantity": 1,
"origin_country_alpha2": "US",
"declared_currency": "USD",
"declared_customs_value": 1,
"hs_code": "19019095",
"contains_liquids": "false",
"contains_battery_pi966": "false",
"sku": "sku-1234",
"actual_weight": 1
}
],
"total_actual_weight": 1
}
]
}
headers = {
"accept": "application/json",
"content-type": "application/json",
"authorization": "my_api_key"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)