PHP
<?php
// Initialize cURL and make the request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.adgem.com/v1/all/campaigns?&appid=ADGEM_APP_ID&token=ADGEM_API_TOKEN');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
// Decode the response into a PHP associative array
$response = json_decode($response, true);
// Make sure that there wasn't a problem decoding the repsonse
if(json_last_error()!==JSON_ERROR_NONE){
throw new RuntimeException(
'API response not well-formed (json error code: '.json_last_error().')'
);
}
// Print out the response details or, any error messages
if(isset($response['status']) && $response['status']==="success"){
echo 'API call successful';
echo PHP_EOL;
echo 'Response Data: <pre>'.print_r($response['data'], true).'';
echo PHP_EOL;
}else if(isset($response['status']) && $response['status']==="error"){
echo 'API call error';
echo PHP_EOL;
echo 'Errors: <pre>'.print_r($response['data'], true).'';
echo PHP_EOL;
}else{
echo 'API call failed';
echo PHP_EOL;
echo 'Errors: <pre>'.print_r($response['data'], true).'';
echo PHP_EOL;
}
?>
Python
# importing the requests library
import requests
# defining the api-endpoint
API_ENDPOINT = "https://api.adgem.com/v1/all/campaigns?&appid=ADGEM_APP_ID&token=ADGEM_API_TOKEN"
# your Adgem App ID and API Token
ADGEM_APP_ID = "xxxxx"
ADGEM_API_TOKEN = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
# data to be sent to api
data = {'appid': ADGEM_APP_ID,
'token': ADGEM_API_TOKEN}
# sending post request and saving response as response object
r = requests.post(url = API_ENDPOINT, data = data)
# extracting response data
response_data = r.data
print(response_data)
Ruby
require 'net/http'
require 'json'
url = 'https://api.adgem.com/v1/all/campaigns?&appid=ADGEM_APP_ID&token=ADGEM_API_TOKEN'
uri = URI(url)
response = Net::HTTP.get(uri)
JSON.parse(response)
Tags api, call examples, php, python, ruby
Was this article helpful to you?
Yes
2
No