Skip to content

Creating sponsored products reports fails #18

Closed

Description

@SaturnFromTitan

Hi! First off: Thanks for this SDK, I very much like it so far!

Describe the bug
Requesting a sponsored products campaigns report fails for me. When building the request myself with requests I can get it to work, so it's definitely not an issue with the API or with my credentials.

To Reproduce
When I run the following script

credentials = {'refresh_token': refresh_token, 'client_id': client_id, 'client_secret': client_secret, 'profile_id': profile_id}
client = Reports(marketplace=Marketplaces.EU, credentials=credentials)

body = {
    "reportDate": "20220101",
    "metrics": "campaignId,impressions,clicks,cost",
}
res = client.post_report(recordType="campaigns", body=body)
print(res)

I receive the following error:

{'headers': ...,
 'next_token': None,
 'payload': {'code': '422',
             'details': "Unrecognized token 'reportDate': was expecting",
             'requestId': '1H1P1JK3PJ70DD33WRY3'}}

Expected behaviour
Receive a 202 response

Solution
I managed to find the source of the bug when building my own request with requests:

Instead of using request.post's data parameter, you need to pass body to json.

I.e. this line: https://github.com/denisneuf/python-amazon-ad-api/blob/main/ad_api/api/sp/reports.py#L33

needs to be changed to
return self._request(fill_query_params(kwargs.pop('path'), recordType), json=kwargs.pop('body'), params=kwargs)

Then everything should be working fine.

I'm happy to provide a PR to fix this. I wait for a reply here first though ✌️

Activity

  1. Repository owner locked and limited conversation to collaborators on Feb 7, 2022
  2. converted this issue into a discussion #21 on Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions