Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: Unable to get reports with API

Solved

Unable to get reports with API

lcalcagni
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.

 

Accepted Solutions (3)

Visely-Team
Shopify Partner
1843 210 488

This is an accepted solution.

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

View solution in original post

Visely-Team
Shopify Partner
1843 210 488

This is an accepted solution.

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

View solution in original post

Visely-Team
Shopify Partner
1843 210 488

This is an accepted solution.

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

View solution in original post

Replies 15 (15)

Visely-Team
Shopify Partner
1843 210 488

This is an accepted solution.

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
lcalcagni
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?

 

Visely-Team
Shopify Partner
1843 210 488

This is an accepted solution.

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
lcalcagni
New Member
5 0 0

Thanks, 
I get: 

 

{"errors":{"report":"expected String to be a Hash"}}
Visely-Team
Shopify Partner
1843 210 488

This is an accepted solution.

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
Bryan43
Visitor
1 0 0

Is it possible to provide a example code to "POST"? I still get a empty array back without errors.

Not applicable

Are we able to do this without having a Shopify Advanced/Plus subscription?

Visely-Team
Shopify Partner
1843 210 488

@Anonymous nope. The api is available only for merchants running on Shopify Advanced or Plus.

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
Francis21
Visitor
2 0 0

Hello, in the API documentation Analytics / Report section: https://shopify.dev/docs/admin-api/rest/reference/analytics/report#index-2020-10 it says that it is possible to retrieve a list of reports. But my tech team can't get any data and as a result we obtain the following info:

"reports": [ ]

What can be the case?

Thank you

 

  

Visely-Team
Shopify Partner
1843 210 488

@Francis21 as mentioned above, this endpoint will ONLY return the reports (not the data, but the report definition) created using the same API access token. You are getting [] because you didn't create any reports through the API.

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
Francis21
Visitor
2 0 0

Thank you for the reply. As we are creating a internal database for our email campaigns, is it possible to retrieve the total orders and total gross sales metrics for each utm_campaign_name?

 

 

Visely-Team
Shopify Partner
1843 210 488

@Francis21 only by leveraging Shopify Order API (REST or GraphQL) to go through the orders and pick the ones that have the extra information you are matching on (say UTM campaign) in the customAttributes. But this is all assuming the customAttributes are populated when the order is created on the store front (through a third-party integration or an app).

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
huta
Visitor
1 0 0

So How to get the data via API ?

I dont need report definition I need the  Data

zhangqingxiu
New Member
7 0 0

Hello I have encountered the same problem now, but I always fail to call the creation interface. I am using C# and the interface always returns: “The request could not be understood by the server due to malformed syntax”. I use the post method, The text passed is

{
  "report": {
    "name""A new app report",
    "shopify_ql""SHOW total_sales BY order_id FROM sales SINCE -1m UNTIL today ORDER BY total_sales"
  }
}
Can you tell me what went wrong?
 
frog-dev
Shopify Partner
9 0 1

So the merchant can query their own reports available in their dashboard?