question

morielhezi avatar image
0 Likes"
morielhezi asked

Unable to use Analytics API from Python

Can anyone spot any issue in the following code- resulting with Response [401] - no additional text...

user_token is the token returned

timespan = "[20220401..20220406]"

metrics_trafficreport = 'CLICK_THROUGH_RATE,LISTING_IMPRESSION_SEARCH_RESULTS_PAGE, LISTING_IMPRESSION_STORE,LISTING_IMPRESSION_TOTAL,LISTING_VIEWS_SOURCE_DIRECT,LISTING_VIEWS_SOURCE_OFF_EBAY,LISTING_VIEWS_SOURCE_OTHER_EBAY,LISTING_VIEWS_SOURCE_SEARCH_RESULTS_PAGE,LISTING_VIEWS_SOURCE_STORE,LISTING_VIEWS_TOTAL,SALES_CONVERSION_RATE,TRANSACTION'

dimension_trafficreport = 'DAY'

url_trafficreport = 'https://api.ebay.com/sell/analytics/v1/traffic_report'

querystring = {"filter":str("marketplace_ids:{EBAY_US},date_range:"+str(timespan)),

"dimension":dimension_trafficreport,

'metric':metrics_trafficreport}

headers = {

'Authorization': str('Bearer ' +str(user_token)),

"X-EBAY-C-MARKETPLACE-ID": 'EBAY_US'

}

response = requests.request("GET", url_trafficreport, headers=headers, params=querystring)

analytics api
10 |600

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

engywookmedia avatar image
0 Likes"
engywookmedia answered

https://capture.dropbox.com/NemwfhVaeUnEM7o3

I think you're missing the Accept : application/json

,

I use this:


ebayheaders = {

'Accept' : 'application/json',

'X-EBAY-C-MARKETPLACE-ID' : 'EBAY_US',

'Content-Type' : 'application/json'

}

ebayheaders['Authorization'] = "Bearer " + oauth_user_token

10 |600

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

morielhezi avatar image
0 Likes"
morielhezi answered

Hi,Thnx for your suggestion. I have tried to add the Accept and the Content-Type but getting the same Response 401

10 |600

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

morielhezi avatar image
0 Likes"
morielhezi answered

My header looks like that (print output):

In your case, does the Bearer looks similar?

Headers= {'Accept': 'application/json', 'Authorization': 'Bearer {"access_token": "v^1....QAAA==", "expires_in": "2022-04-09T02:30:34:973427"}', 'X-EBAY-C-MARKETPLACE-ID': 'EBAY_US', 'Content-Type': 'application/json'}

10 |600

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

morielhezi avatar image
0 Likes"
morielhezi answered

I think that there might be an issue with my Bearer

In your case, do you use the authorization code or the the access token

1. the authorization code

2.After calling exchange_code_for_access_token

3. Further, after calling get_access_token


10 |600

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

morielhezi avatar image
0 Likes"
morielhezi answered

OK, my issue was related to the token. I had to concatenate to the Bearer only the value of the access_token element in the token disctionary.

THANK YOU!

10 |600

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.