Use time range in Ad Insights of Facebook Marketing API - facebook

I'm trying to obtain impressions of my ads between two dates
I'm using Graph API Explorer with this path:
act_0123456789/ads?fields=insights{ad_id,ad_name,impressions}
I want to use 'time_range' attribute that we can find it in Marketing API reference but I don't know the syntax. Anyone can help me?

I can't comment on the approach you're using as I have not used it myself. However, here is an alternative approach which I have used with success:
https://graph.facebook.com/v2.5/act_xyz/insights?level=<yourLevel>&fields=ad_id,ad_name,impressions&time_range[since]=2016-02-15&time_range[until]=2016-02-16&limit=25
where <yourLevel> can be one of: ad, adset, campaign
Also note that I am using straight up http requests in java which is why I show you the request itself. Hopefully you can extrapolate to your own solution.

Using the same endpoint you've shown in your question
act_0123456789/ads?fields=insights{ad_id,ad_name,impressions}
The way to specify a time range would be
act_0123456789/ads?fields=insights.time_range({"since":"2017-08-07","until":"2017-08-14"}){ad_id,ad_name,impressions}
(of course, those two dates are provided just as an example)

Easiest way of doing this is
act_0123456789?fields=ads{insights.time_range({"since":"2019-03-03","until":"2019-03-03"}).time_increment(1){impressions}}
Remove .time_increment(1) if you don't want day by day data
you can use {} for subfields like
act_0123456789?fields=campaigns{ads{name,insights,adcreatives{image_url}}}
you can use . and () for parameters like; always make sure you use you use fields only after parameters like this order .(){}
act_0123456789?fields=campaigns.limit(1).time_range({"since":"2019-03-03","until":"2019-03-03"}).time_increment(1).breakdowns(country){ads{name,insights.time_range({"since":"2019-03-03","until":"2019-03-03"}).time_increment(1).breakdowns(country),adcreatives{image_url}}}

Related

Filtering certain coins based upon name with CoinMarketCap

I'm currently attempting to use the CoinMarketCap API but finding it frustrating.
I'm wanting to use this URL to query their API:
https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest
However, rather than finding all, or just simply filtering based upon the number, I want to find a certain few coins.
So for example, I want to only find Bitcoin, Ethereum and Cardano.
Looking at their docs, it suggests you can sort by name, but it appears this is only listing them alphabetically, which I don't want to do.
So can anyone suggest how to query their API successfully and find just Bitcoin, Ethereum and Cardano using that GET URL above?
Here's the URL to the specific URL for the API request: https://coinmarketcap.com/api/documentation/v1/#operation/getV1CryptocurrencyListingsLatest
For this purpose, you can use the endpoint Quotes Latest:
https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest
It allows you to pass a list of identifiers in a string as a parameter, like this:
1,1027,328
or a list of slugs:
bitcoin,ethereum,monero
or a list of symbols
BTC,ETH,XMR
If you trying to scrape information about new listings at crypto exchanges, you can be interested in this API:
https://rapidapi.com/Diver44/api/new-cryptocurrencies-listings/
It includes an endpoint with New Listings, New Pairs from the biggest exchanges and a very useful endpoint with information about exchanges where you can buy specific coins and prices for this coin at that exchange. It's a bit paid, but it's worth it!

How to filter REST API JSON result by passing params

I'm trying to consume JIRA 2 API and trying to get custom fields. I want to further filter by passing appropriate criteria in URI itself. Current query I'm using is something similar to this:
http://localhost:8522/jira522/rest/api/2/issue/createmeta?expand=projects.issuetypes.fields
The result I'm getting from above request is about 2000 lines.. How can I further filter to get only Custom_fields and also under custom fields I need to only the ones which are required?
I'm pretty new to REST API. Please guide me If anything is wrong... TIA. I spent a lot of time browsing but don't know what exactly I need to search for or where exactly I need to get started.
You can use another queryParam just like expand and add further filtering or pagination.
http://localhost:8522/jira522/rest/api/2/issue/createmeta?expand=projects.issuetypes.fields&limit=1000

Possible to specify date_preset with insights edge in Facebook Ads API?

For the Marketing API, I know that I'm able to make one call to retrieve all of the adsets from a certain account along with their insights, but am I able to specify the date_preset for the insights edge in that same call?
For example, the following gives me lifetime insights stats:
/v2.4/{accountID}/adcampaigns?fields=insights
To be clear - I know this is possible to retrieve by making separate calls for each adset id (where I know I can specify the date_preset); instead, I'd like to do this via the call where I get a long list of the ad sets plus their insights details in one go.
Yes this is possible using query expansion, however you probably should not do it in this anyway.
Using query expansion results in multiple requests being executed in one HTTP call, in this case one to get all the adcampaigns, and then N requests where N is the number of adcampaigns returned. This will in turn affect your rate limiting.
The most efficient way to request all insights for all adcampaigns (ad sets) is instead to request them at the account level, specifying aggregation level:
/v2.4/act_{ADACCOUNT_ID}/insights?date_preset=last_7_days&level=campaign
This requires just 1 request, or the number of requests to retrieve the total number of pages.
If you really want to achieve this with query expansion, you can do the following for example:
/v2.4/act_{ADACCOUNT_ID}/adcampaigns?fields=insights.date_preset(last_30_days).time_increment(all_days)
You can see the parameters to insights that would normally be query parameters of the form param_name=param_value are now in the form of param_name(param_value).
To specify the date_preset , here is the correct format . Its important to use insights as edge to get the date_preset filtering .
/v2.10/act_{ADACCOUNT_ID}/insights?fields=impressions,clicks,ctr,unique_clicks,unique_ctr,spend,cpc&date_preset=last_3d
The above one is tested with latest Graph Api version(2.10) as of now . FOr more info related to the date_preset values refer to there api docs .
https://developers.facebook.com/docs/marketing-api/insights/parameters

Search API Facebook Graph by date range

is there any way to explore the Facebook Graph API by date range? Ex. to find all events on February?
I use following code, but I’m not sure, that’s correct request:
since=2015-01-28T00:00:00%2B0000&until=2015-01-30T00:00:00%2B00000
In this way, I get records for defined date range - ok, but there is missing events – a set is incomplete (despite it doesn’t exceed a limit of API). Why I can’t get all of results for given query?
Maybe do you know another method of filtering results by date?
thanks
There's no way to restrict the search results by since and until as far as I know.
For searching events, you can use the /search endpoint as described at
https://developers.facebook.com/docs/graph-api/using-graph-api/v2.2#search
but I guess there's no further way to filter the results other than specifying the q parameter.

Posting IDs to REST API

I am designing a REST API for inserting a record to the "solutions" table. A "solution" has a solverID, problemID. I have two different designs in mind:
POST /solutions
and passing the solverID and problemID in JSON with the content of the solution. Or putting the solverID and problemID in the URI:
POST /users/:solver_id/problems/:problem_id/solutions
Which design is better?
It's a good practice to define your resources in a consistent hierarchy, so that they are easily understandable and predictable.
Let's say this is the URL to retrieve a question -
GET /users/{solverId}/problems/{problemId}
It clearly conveys that the problem belongs to the {solverId}.
The following URL would clearly show that the we are retrieving all solutions for problems solved by {solverId}
GET /users/{solverId}/problems/{problemId}/solutions
To create a new solution for the {problemId}, you would do a post on
POST /users/{solverId}/problems/{problemId}/solutions
To retrieve a particular solution you would do a get on
GET /users/{solverId}/problems/{problemId}/solutions/{solutionId}
When to use Ids in path vs query ?
If an ID is definitely required to identify a resource, use it in the path. In the above scenario, since all three Ids are required to uniquely identify a solution, all of them should be in the path.
Let's say you want to retrieve a solution that was given in a particular date range, you would use the following
GET /users/{solverId}/problems/{problemId}/solutions?startDate={}&endDate={}
Here startDate and endDate cannot uniquely identify a resource, they are just parameters that are being used to filter the results.
Go with the first one. I would keep your urls as clean and simple as you can. Here are some other examples off the top my head. Not sure on your entire structure.
POST /solutions
GET /solutions?solverid=123 //query solutions by user
GET /users/555/problems // problems for a given user
GET /users/555/solutions // solutions for a given user
GET /problems/987/solutions // solutions for a given problem
I came up with a scheme: including user ID in the route only when authentication is not needed for the route, otherwise, the user ID can be figured out from the authentication information, and the above route becomes:
POST /problems/:problem_id/solutions