Skip to content
Advertisement

API FedEX “INVALID.INPUT.EXCEPTION”,”message”:”Invalid field value in the input”

I’m trying to validade an address in FedEX API using Python 3.8 and it returns an error of invalid field value

First I connect to the Auth API

payload={"grant_type": "client_credentials",'client_id':Client_id,'client_secret':Client_secret}
url = "https://apis-sandbox.fedex.com/oauth/token"
headers = {'Content-Type': "application/x-www-form-urlencoded"}
response=requests.post(url, data=(payload), headers=headers)

And it returns a message with the Auth token correctly

{"access_token":"eyJhbGciOiJSUzI1NiIsInRM5U0F2eUs1ZVFBVTFzS5k","token_type":"bearer","expires_in":3599,"scope":"CXS SECURE"}

Then I just get the token to use it in next transactions

token = json.loads(response.text)['access_token']

Then I prepare the next payload for address validation API

payload_valid_address = {
    "addressesToValidate": [
        {
    "address":
            {
            "streetLines": ["7372 PARKRIDGE BLVD"],
            "city": "Irving",
            "stateOrProvinceCode": "TX",
            "postalCode": "75063-8659",
            "countryCode": "US"
            }
        }
    ]
}

And send the request to the new endpoint with the given token

url = "https://apis-sandbox.fedex.com/address/v1/addresses/resolve"
headers = {
    'Content-Type': "application/json",
    'X-locale': "en_US",
    'Authorization': 'Bearer '+ token
    }

response = requests.post(url, data=payload_valid_address, headers=headers)

print(response.text)

and get the error

<Response [422]>
{"transactionId":"50eae03e-0fec-4ec7-b068-d5c456b64fe5","errors":[{"code":"INVALID.INPUT.EXCEPTION","message":"Invalid field value in the input"}]}

I have made inumerous tests and I don’t get the invalid field. Anyone know what is happening and can help?

Advertisement

Answer

payload = json.dumps({input payload}) this works to prevent the response error 422 <Response [422]>

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement