How to get a month of data out of Mediahawk
In this guide we will show you how to get call and Call-to-Action (CTA) data for a date period. There are other ways you can get this data out, to see the entire list of options please check the calls or CTAs sections under reference.
Before you begin this guide, please ensure you have followed the Authenticate guide and have a valid token.
You can download a full working code example for this guide here:
CURL, PHP, Node.js, Python, C#
How to get a month's worth of calls
In a scenario where you would need last month's call data, you can achieve this by using the API.
This is an example of getting call records for a month, including a demonstration of how to paginate the response for smaller data sets as per your system's needs.
limit and offset parameters are available to control the amount of call data returned. The limit parameter has a maximum of 3000 records.
- CURL
- PHP
- Python
- Node.js
- C#
- Try it out
apiKey="<YOUR_API_KEY>"
limit="100"
offset="0"
fromDate="2022-10-01"
toDate="2022-10-31"
calls="$(curl -L -X GET "https://www.reports.mediahawk.co.uk/rest/v2_0/calls?api_key=${apiKey}&from_date=${fromDate}&to_date=${toDate}&limit=${limit}&offset=${offset}" \
--header "Content-Type: application/json" \
--header "Accept: application/json" \
)"
echo $calls
$apiKey = "<YOUR_API_KEY>";
$limit = 100;
$offset = 0;
$fromDate = "2022-10-01";
$toDate = "2022-10-31";
$client = new Client();
$headers = [
"Accept" => "application/json",
"Content-type" => "application/json",
];
$request = new Request("GET", "https://www.reports.mediahawk.co.uk/rest/v2_0/calls?api_key={$apiKey}&from_date={$fromDate}&to_date={$toDate}&limit={$limit}&offset={$offset}", $headers);
$res = $client->sendAsync($request)->wait();
$responseBody = $res->getBody();
echo json_encode(json_decode($responseBody), JSON_PRETTY_PRINT) . PHP_EOL;
apiKey = "<YOUR_API_KEY>"
limit = 100
offset = 0
fromDate = "2022-10-01"
toDate = "2022-10-31"
url = "https://www.reports.mediahawk.co.uk/rest/v2_0/calls?api_key=" + apiKey + "&from_date=" + fromDate + "&to_date=" + toDate + "&limit=" + str(limit) + "&offset=" + str(offset)
headers = {
"Content-Type": "application/json"
}
httpRequest = requests.Session();
response = httpRequest.request("GET", url, headers=headers)
calls = json.loads(response.text)
print(json.dumps(calls, indent=2))
const apiKey = "<YOUR_API_KEY>";
let limit = 100;
let offset = 0;
const fromDate = "2022-10-01";
const toDate = "2022-10-31";
let config = {
method: "get",
url: "https://www.reports.mediahawk.co.uk/rest/v2_0/calls?api_key=" + apiKey + "&from_date=" + fromDate + "&to_date=" + toDate + "&limit=" + limit + "&offset=" + offset,
headers: {
"Accept": "application/json",
"Content-type": "application/json",
}
};
axios(config)
.then((response) => {
let calls = response.data;
console.log(JSON.stringify(calls, null, 2));
});
string apiKey = "<YOUR_API_KEY>";
int limit = 100;
int offset = 0;
string fromDate = "2022-10-01";
string toDate = "2022-10-31";
var restClient = new RestClient("https://www.reports.mediahawk.co.uk/rest/v2_0");
restClient.Timeout = -1;
var request = new RestRequest("/calls?api_key=" + apiKey + "&from_date=" + fromDate + "&to_date=" + toDate + "&limit=" + limit + "&offset=" + offset, Method.GET);
request.AddHeader("Content-Type", "application/json");
IRestResponse calls = restClient.Execute(request);
var callsResponseObject = JsonConvert.DeserializeObject<dynamic>(calls.Content);
Console.WriteLine(callsResponseObject);
The response will appear here
How to get a month's worth of CTAs
In the same fashion as getting a month of call data, you can also do the same for CTAs.
limit and offset parameters are available to control the amount of CTA data returned. The limit parameter has a maximum of 3000 records.
- CURL
- PHP
- Python
- Node.js
- C#
- Try it out
apiKey="<YOUR_API_KEY>"
limit="100"
offset="0"
fromDate="2022-10-01"
toDate="2022-10-31"
ctas="$(curl -L -X GET "https://www.reports.mediahawk.co.uk/rest/v2_0/ctas?api_key=${apiKey}&from_date=${fromDate}&to_date=${toDate}&limit=${limit}&offset=${offset}" \
--header "Content-Type: application/json" \
--header "Accept: application/json" \
)"
echo $ctas
$apiKey = "<YOUR_API_KEY>";
$limit = 100;
$offset = 0;
$fromDate = "2022-10-01";
$toDate = "2022-10-31";
$client = new Client();
$headers = [
"Accept" => "application/json",
"Content-type" => "application/json",
];
$request = new Request("GET", "https://www.reports.mediahawk.co.uk/rest/v2_0/ctas?api_key={$apiKey}&from_date={$fromDate}&to_date={$tpDate}&limit={$limit}&offset={$offset}", $headers);
$res = $client->sendAsync($request)->wait();
$responseBody = $res->getBody();
echo json_encode(json_decode($responseBody), JSON_PRETTY_PRINT) . PHP_EOL;
apiKey = "<YOUR_API_KEY>"
limit = 100
offset = 0
fromDate = "2022-10-01"
toDate = "2022-10-31"
url = "https://www.reports.mediahawk.co.uk/rest/v2_0/ctas?api_key=" + apiKey + "&from_date=" + fromDate + "&to_date=" + toDate + "&limit=" + str(limit) + "&offset=" + str(offset)
headers = {
"Content-Type": "application/json"
}
httpRequest = requests.Session();
response = httpRequest.request("GET", url, headers=headers)
ctas = json.loads(response.text)
print(json.dumps(ctas, indent=2))
const apiKey = "<YOUR_API_KEY>";
let limit = 100;
let offset = 0;
const fromDate = "2022-10-01";
const toDate = "2022-10-31";
let config = {
method: "get",
url: "https://www.reports.mediahawk.co.uk/rest/v2_0/ctas?api_key=" + apiKey + "&from_date=" + fromDate + "&to_date=" + toDate + "&limit=" + limit + "&offset=" + offset,
headers: {
"Accept": "application/json",
"Content-type": "application/json",
}
};
axios(config)
.then((response) => {
let ctas = response.data;
console.log(JSON.stringify(ctas, null, 2));
});
string apiKey = "<YOUR_API_KEY>";
int limit = 100;
int offset = 0;
string fromDate = "2022-10-01";
string toDate = "2022-10-31";
var restClient = new RestClient("https://www.reports.mediahawk.co.uk/rest/v2_0");
restClient.Timeout = -1;
var request = new RestRequest("/ctas?api_key=" + apiKey + "&from_date=" + fromDate + "&to_date=" + toDate + "&limit=" + limit + "&offset=" + offset, Method.GET);
request.AddHeader("Content-Type", "application/json");
IRestResponse ctas = restClient.Execute(request);
var ctasResponseObject = JsonConvert.DeserializeObject<dynamic>(ctas.Content);
Console.WriteLine(ctasResponseObject);
The response will appear here