Unable to get reports with API

Solved
Highlighted
New Member
5 0 0

If I enter to the section Analytics -> Reports I can see several reports. Some of them automatic reports (for example sales over time, customers over time, etc). However I want to access to this information via Python, so I am using the API, like this

 

import requests

APIkey = "myAPYkey"
APIversion = "2019-04"
Pass = "myPass"hostname = "myHost"
response = requests.get("https://{}:{}{}/admin/api/{}/reports.json".format(APIkey,Pass,hostname,APIversion))

print(response.text)

 

However I get

{"reports":[]}

Why is that? 

 

On the other hand, I do not know where I can find the ID of the reports.

 

0 Likes

Success.

Shopify Partner
798 75 111

The API is for creating and publishing reports that are then available to the merchant in the dashboard. You cannot query/see existing reports created by other apps or Shopify. You are getting an empty array in response because you didn't create one. Reports are scoped to the app that created them.

Sergiu Svinarciuc | CTO @ visely.io
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
- To learn more about the awesome stuff we do head over to visely.io or our blog
0 Likes
New Member
5 0 0

Oh, I see.. 
So just one more question: 

 

I have changed my code to: 

 

import requests

APIkey = "myAPYkey"
APIversion = "2019-04"
Pass = "myPass"
hostname = "myHost"

#Creating a new report
report_data = { "report": { "name": "A new app report made with the API", "shopify_ql": "SHOW total_sales BY country FROM order SINCE -1m UNTIL today ORDER BY total_sales" } } new_report = requests.post("https://{}:{}{}/admin/api/{}/reports.json".format(APIkey,Pass,hostname,APIversion), data=report_data)

#Get the reports
response = requests.get("https://{}:{}{}/admin/api/{}/reports.json".format(APIkey,Pass,hostname,APIversion))

print(response.text)

 

And I am still getting:

 

{"reports":[]}

Why is that?

Can I access to the report data or just to the report properties like the name of the report?

 

0 Likes

Success.

Shopify Partner
798 75 111

You cannot access report data, only report definitions. What do you get in response for the POST request?

Sergiu Svinarciuc | CTO @ visely.io
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
- To learn more about the awesome stuff we do head over to visely.io or our blog
0 Likes
New Member
5 0 0

Thanks, 
I get: 

 

{"errors":{"report":"expected String to be a Hash"}}
0 Likes

Success.

Shopify Partner
798 75 111

Yup, the report is not created because of this error, this is why you are getting an empty array back. You'll have to fix it first, and then you'll be able to get it back in the GET request.

Sergiu Svinarciuc | CTO @ visely.io
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
- To learn more about the awesome stuff we do head over to visely.io or our blog
0 Likes