It is required to create an API method which will be used by Aitarget for requesting statistics on-the-go.
The most preferrable is a POST-method which returns JSON.
Method MUST receive:
- ids - Facebook entities ids array which is used to request data.
- fields - the requested fields data array.
- Either a pair date_start date_stop in format 2017-03-27, or one field date_preset which receives values: last_hour - for the last hour, prev_hour - for the previous hour.
- time_increment - period of statistics aggregation (only used with the pair date_start date_stop): 'monthly', 'all_days' or an integer amount of days from 1 to 90.
Optionally access_token can be added in order to increase security Server2Server.
Examples:
Let's assert you have released API (via POST request) with address https://example.com/aitarget/api/stats and you have chosen access_token=top_secret as a security parameter (it might be changed later).
Case №1
Let's assert we need to retrieve summary data (time_increment='all_days') for the metrics (these metrics are set on example.com side) field1 and field2 during time period from 2017-08-01 to 2017-08-10 for the Facebook objects with ids 123456 and 654321. In this case Aitarget will run CURL:
curl 'https://example.com/aitarget/api/stats' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: application/json' --data 'ids[0]=123456&ids[1]=654321&fields[0]=field1&fields[1]=field2&date_start=201 7-08-01&date_stop=2017-08-10&time_increment=all_days&access_token=top_secret' --compressed
Expecting to receive JSON as response:
{ "123456": { "data": [ { "date_start": "2017-08-01", "date_stop": "2017-08-10", "field1": 35, "field2": 1.5 } ] }, "654321": { "data": [ { "date_start": "2017-08-01", "date_stop": "2017-08-10", "field1": 8, "field2": 10.5 } ] } }
Case №2
Let's assert we require to receive the field1 and field2 metrics data during time period from 2017-08-01 to 2017-08-03 for the Facebook objects with ids 123456 и 654321 with a breakdown by days. In this case Aitarget will run CURL:
curl 'https://example.com/aitarget/api/stats' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: application/json' --data 'ids[0]=123456&ids[1]=654321&fields[0]=field1&fields[1]=field2&date_start=201 7-08-01&date_stop=2017-08-03&time_increment=1&access_token=top_secret' --compressed
Expecting to receive JSON as response:
{ "123456": { "data": [ { "date_start": "2017-08-01", "date_stop": "2015-08-01", "field1": 35, "field2": 1.5 }, { "date_start": "2017-08-02", "date_stop": "2017-08-02", "field1": 5, "field2": 0.5 }, { "date_start": "2017-08-01", "date_stop": "2017-08-01", "field1": 500, "field2": 110.5 } ] }, "654321": { "data": [ { "date_start": "2017-08-01", "date_stop": "2017-08-01", "field1": 350, "field2": 221.5 }, { "date_start": "2017-08-02", "date_stop": "2017-08-02", "field1": 53, "field2": 330.5 }, { "date_start": "2017-08-03", "date_stop": "2017-08-03", "field1": 50, "field2": 60.5 } ] } }
Case №3
Let's assert we need to receive the field1 and field2 metrics data (these metrics are set on example.com side) for the Facebook objects with ids 123456 и 654321 for the last hour (date_preset=last_hour), i.e. if current time is 2017-09-01 14:40 then we need data from 14:00 to the current moment. In this case Aitarget will run CURL:
curl 'https://example.com/aitarget/api/stats' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: application/json' --data 'ids[0]=123456&ids[1]=654321&fields[0]=field1&fields[1]=field2&date_preset=la st_hour&access_token=top_secret' --compressed
Expecting to receive JSON as response:
{ "123456": { "data": [ { "date_start": "2017-09-01", "date_stop": "2017-09-01", "field1": 35, "field2": 1.5 } ] }, "654321": { "data": [ { "date_start": "2017-09-01", "date_stop": "2017-09-01", "field1": 8, "field2": 10.5 } ] } }
Comments
0 comments
Please sign in to leave a comment.