PARTIALLY SOLVED - I changed the request from
requests.post(url, headers = headers, data = data)
to:
requests.post(url, headers = headers, json = data)
and now it works. I am not sure why...
Original Post:
The code I am using below continues to provide a response:
{"code":"422","details":"Unrecognized token 'adGroupId': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false'"}
I am able to get a successful response with POSTMAN, and am failing to see the difference between this and my requests
vscode attempts. FWIW, I simply copy the request body from the IDE and pasted it into POSTMAN as 'raw'.
My 'request' library failing attempts in the IDE:
headers = {
"Amazon-Advertising-API-ClientId": clientid,
"Authorization": access,
"Amazon-Advertising-API-Scope":scope,
"Content-Type": "application/json"
}
data = {
"adGroupId":adgroupid,
"keywords": [
{
"keyword": "mini bricks",
"matchType": "exact"
}
]
}
response = requests.post(
'https://advertising-api.amazon.com/v2/sp/keywords/bidRecommendations',
headers = headers,
data = data
)
print(response.text)
My successful POSTMAN request headers and body:
Request Headers
Amazon-Advertising-API-ClientId: ...
Authorization: ...
Amazon-Advertising-API-Scope: ...
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: ...
Request Body
{
"adGroupId":...,
"keywords": [
{
"keyword": "mini bricks",
"matchType": "exact"
}
]
}