Querying Customer Saved Searches in Shopify Python API - python

I'm trying to get all customers who abandoned their order last week.
I was able to achieved it through the REST API, however, I wonder how to achieve the same thing via Shopify Python API.
Here's the code I tried in Postman:
https://{shop}.myshopify.com/admin/api/2019-07/customer_saved_searches/{customer_saved_search_id}/customers.json?limit=250
Also, it seems like there's a 250 results limit in the REST API, is there a way to exceed it?

The Python SDK is a bit of afterthought of Shopify. Sadly.
Regarding the paging on th REST request. Just add the query parameter ...?page=2 at the end of your URL.
Regarding the Python SDK, following will do the trick:
id = 23423423423
css = shopify.CustomerSavedSearch.find(id)

Related

HTML Request from Denticon

I am attempting to query a cloud database using the requests package. This is from Denticon, a dentistry software that my office uses to schedule patients and store information on the cloud about them and their dental history. Eventually, I would like to process and analyze the results of the query in pandas but I am having issues getting query to work at all. I admit I am a novice at using this sort of API and querying in general, so show some grace if I am doing this absolutely wrong.
By their own documentation, the makers of Denticon say you must query using a html request. When attempting to use 'request.get()' I get an error message that this method in not supported for the request when using it on a url for a specific query.
Here is some short documentation from their own website that could help fill some gaps:
Denticon API
Denticon API Getting Started
Denticon Patient APIs
In my case I am trying to query a list of patients at a specific office/location. This is what I would think to try:
import requests
apiKey = {"API-AUTH-KEY":"AAC6DB7A-5A66-4EBC-B694-D6BCD99881CB",
"API-VENDOR-KEY":"BCF756D4-DCE6-4F2B-BAAE-7679D87037A7",
"PGID":"1"}
requests.get('https://dev-api.denticon.com/v2/api/Patient/AllPatients/', headers=apiKey)
(As a short disclaimer: these are practice api keys that Denticon provides. They do not allow you query any actual patient data, just to practice using the API)
At this point is where I get the "method not supported" response for request.get
The error means that you cannot call the API using requests.get. Try to do it using requests.post.
import requests
apiKey = {"API-AUTH-KEY":"AAC6DB7A-5A66-4EBC-B694-D6BCD99881CB",
"API-VENDOR-KEY":"BCF756D4-DCE6-4F2B-BAAE-7679D87037A7",
"PGID":"1"}
json = {"OID":"","PAGEINDEX":"1"}
requests.post('https://dev-api.denticon.com/v2/api/Patient/AllPatients/', headers=apiKey, json=json)

Python code to connect to twitter search API

I'm new to Python and am very confused on how to begin this assignment:
Write Python code to connect to Twitter search API at:
https://api.twitter.com/1.1/search/tweets.json
with at least the following parameters:
q for a search topic of your interest;
count to 100 for 100 records
to retrieve twitter data and assign the data to a variable.
I already created the app to access Twitter's API. Thanks.
I had this same issue. According to Twitter, you must register an account to even use basic search features of public tweets and there is no way around it. I followed the guide for the complete setup here and can confirm it works
Edit: the article is for php, but changing it to python shouldn’t be very difficult. It has all the methods outlined in the article
Just as a hint, you might want to use tweepy for this. They have very good documentation and its much easier than trying to reinvent the wheel.

Unable to get campaigns data to push to database in google adwords api

I am facing a couple of issues in figuring out what-is-what, in spite of the humungous documentation I am unable to figure out these issues
1.Which report type should be used to get the campaign level totals. I am trying to get the data in the format of headers
-campaign_id|campaign_name|CLicks|Impressions|Cost|Conversions.
2.I have tried to use "CAMPAIGN_PERFORMANCE_REPORT" but I get broken up information at a keyword level, but I am trying to pull the data at a campaign level.
3.I also need to push the data to a database. In the API documentation, i get samples which will either print the results on my screen or it will create a file on my machine. is there a way where I can get the data in JSON to push it to the database.
4.I have 7 accounts on my MCC account as of now, the number will increase in the coming days. I don't want to manually hard code the client customer ids into my code as there will be new accounts which will be created. is there a way where I can get the list of client customer ids which are on my MCC ac
I am trying to get this data using python as my code base and adwords api V201710.
To retrieve campaign performance data you need to run a campaign_performance_report. Follow this link to view all available columns for Campaign performance report.
The campaign performance report does not include stats aggregated at a keyword level. Are you using AWQL to pull your report?
Can you paste your code here, I find it odd you are getting keyword level data.
Run this python example code to get campaign data (you should definitely not be getting keyword level data with this example code).
Firstly Google AdWords API only returns report data in the following file formats CSVFOREXCEL, CSV, TSV, XML, GZIPPED_CSV, GZIPPED_XML. Unfortunately JSON is not supported for your use case. I would recommend GZIPPED_CSV and set the following properties to false:
skipReportHeader
skipColumnHeader
skipReportSummary
This will simply skip all headers, report titles & totals from the report making is very simple to upsert data into a table.
It is not possible to enter a MCC ID and expect the API to fetch a report for all client accounts. Each API report request contains the client ID, so therefore you are required to create an array of all client IDs and then iterate through each id. If you are using the client library (recommended) then you can simply set the clientID within the session i.e. session.setClientCustomerId("xxx");
To automate this use the ManagedCustomerService to automatically retrieve all clientIDs then iterate through this therefore you would not need to hard code each ClientID. Google have created a handy python file which returns the account hierarchy including child account ID (click here).
Lastly I based on your question I assume you attempting to run an ETL process. Google have an opensource AdWords extractor which I highly recommend.

Show azure cost analysis data using Azure billing API/SDK

In Azure portal ,if one subscription is selected ,the cost analysis can be viewed like the following screenshot
I want to programmatically fetch the information the like the one displayed above may be using using some python SDK API/REST API.
If anybody has any experience/idea on this ,please help.
After going through replies ,I have gone through the Azure Billing Rest API and I am now able to call the Usage Aggrgate and RateCard related Rest APIs.
Following are the results of those REST Calls. .Azure Billing Usage Aggregate Response
Azure Billing Ratecard Response
But honestly speaking ,I still have not figured out how these to would give me detailed view like the cost analysis does where for each resource how much cost associated can be displayed.Actually I am very new to Azure probably that is why I am missing the link some where .
Can somebody give some hint here ?
If you already have the usage and the ratecard data, then you must combine them. Take the meterId of the usage data and get the related ratecard data. The ratecard data contains the MeterRates and the IncludedQuantity which you must take. There are probably multiple meter rates and the included quantity because there are probably different costs per usage (e.g. first 10 calls for free, 3 GB for free, ...). The consumption starts/is reseted at the 14th of the month. That's the reason why you have to read the data from the whole billing period (begins with 14th of each month), because that's the only way how you get the correct consumption.
So, if you are using e.g. Azure Functions and you have a usage of 100.000 units per day and you want the costs from 20th - 30th, then the calculation works as follows:
read data from 14th - 30th. These are 17 days and therefore it used 1.700.000 units.
The first 400.000 are for free = IncludedQuantity (so in this sample the first 4 days). From the 400.001 unit on, you have to take the meter rate (0,0000134928 €) and calculate the costs. 1.300.000 * 0,0000134928 = ~17,54€. Fortunately, the azure functions have only one rate. If the rate changes e.g. after 5.000.000 units, then you also have to take this into account.
If you have the whole costs, then you can filter on your date which is 20.-30. and you will get the result.
That's the short explanation of the calculation. I implemented this calculation in C# and published it as a NuGet package. The source code is on github - probably it helps. It also contains a sample console which you could use to export the data.
Source: https://github.com/codehollow/AzureBillingApi
Blog post: https://codehollow.com/2017/02/using-the-azure-billing-api-to-calculate-the-costs/
I have the same issue. But unluckily, python SDK is too hard to use.
Moreover, you cannot find an availabale sample or example on Google.
So, I choose using restapi rather than python SDK.
With python code, you can do this firstly,
import requests
from azure.common.credentials import ServicePrincipalCredentials
and set headers pyload and url.
headers = {
"Content-Type": "application/json",
"Authorization": <token> }
you can get token through credentials, which generated by client_id,secret,tenant.
credentials.token() will return the token you can use in headers.
you can find restapi in https://learn.microsoft.com/en-us/rest/api/ or use F12 in Chrome when you access the Azure dashboard.
There are the offical documents below for retrieving the billing data using Python SDK or REST API in Python.
For using Python SDK, please see http://azure-sdk-for-python.readthedocs.io/en/latest/resourcemanagementcommerce.html.
For using Billing REST API, please see https://learn.microsoft.com/en-us/rest/api/billing/, and you can try to use Python package requests to get these data.
However, I think you may have know these above, the key is that you need to follow the tutorial Manage access to billing information for Azure using role-based access control to get the role permission via your account admin.
And then you may also need to register a client app to get the client id for Resource Management Authentication if you want to use Service Principal/ADAL (not AD User/Password) in Python SDK or use REST API to do the same authentication as Azure REST API Reference page said. For the authentication topic, you can refer to the content map of Manage Apps to know more if you have been getting some trouble.
Hope it helps. Any concern, please feel free to let me know.

Get multiple connections at once with Python facebook package

To get connections using the Python facebook package I know to use:
g.get_connections("me", "friends")
But is there a way to get "friends" and "books" in one call?
Didn't see anything in the docs...
Based on the Graph API documentation, you can do a request in the form
GET graph.facebook.com
/{node-id}?
fields={first-level}
Thus, you'd want to execute a GET for /me?fields=friends,books, looking at the facebook-sdk code, the g.get_object seems to be the closest one, thus:
g.get_object('/me', fields='friends,books')
Of course chances are that not all are returned, and you need to page through the results anyway...

Categories