Discussing APIs and development related to customers, discounts, and order management.
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.
Solved! Go to the solution
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.
This is an accepted solution.
You cannot access report data, only report definitions. What do you get in response for the POST request?
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.
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.
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?
This is an accepted solution.
You cannot access report data, only report definitions. What do you get in response for the POST request?
Thanks,
I get:
{"errors":{"report":"expected String to be a Hash"}}
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.
Is it possible to provide a example code to "POST"? I still get a empty array back without errors.
Are we able to do this without having a Shopify Advanced/Plus subscription?
@Anonymous nope. The api is available only for merchants running on Shopify Advanced or Plus.
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
@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.
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?
@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).
So How to get the data via API ?
I dont need report definition I need the Data
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
So the merchant can query their own reports available in their dashboard?