
Getting Started
Authentication
Error Handling
Endpoints
Scan HTML5 Ads
Scan Ad Tags
Scan VAST Tags
Scan Videos
Scan Images
Scan Audio
Tools
Backup Ad Generator
|
arrow_drop_down
API v3 (beta)
search
API v2 (stable) API v3 (beta)
Nothing found...
SDK & ExamplesFind AdValify's SDKs in 5 common programming languages here below. Build a proof of concept in less than an hour. Show your custom-built ad validation module to your colleagues, saving huge amounts of time. PHP
JavaScript
Ruby
Node.js
Python
class AdValifySDK{
private $apiKey;
private $baseUrl;
public function __construct($apiKey, $baseUrl) {
$this->apiKey = $apiKey;
$this->baseUrl = $baseUrl;
}
public function sendRequest($endpoint, $data = []) {
// Set up cURL options
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->baseUrl . $endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_ENCODING , "");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'X-ApiKey: ' . $this->apiKey,
]);
// Execute the request
$response = curl_exec($ch);
// Check for cURL errors
if (curl_errno($ch)) {
throw new Exception('cURL Error: ' . curl_error($ch));
}
// Close cURL session
curl_close($ch);
// Return the API response (you may want to add error handling here)
return $response;
}
}
// Example usage:
$apiKey = 'YOUR_API_KEY';
$baseUrl = 'https://{your_name}.api.advaify.io';
$api = new AdValifySDK($apiKey, $baseUrl);
$endpoint = '/v3/someEndpoint';
$data = ['data' => base64_encode('BINARY_DATA_OR_AD_TAG_HERE')];
try {
$response = $api->sendRequest($endpoint, $data);
echo "API Response: " . $response;
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
class AdValifySDK{
constructor(apiKey, baseUrl) {
this.apiKey = apiKey;
this.baseUrl = baseUrl;
}
async sendRequest(endpoint, data = {}) {
const url = `${this.baseUrl}${endpoint}`;
const headers = {
'Content-Type': 'application/json',
'X-ApiKey': `${this.apiKey}`
};
try {
const response = await fetch(url, {
method: 'POST',
headers: headers,
body: JSON.stringify(data)
});
if (!response.ok) {
throw new Error(`HTTP Error: ${response.status} ${response.statusText}`);
}
return response.json();
} catch (error) {
throw new Error(`Request Error: ${error.message}`);
}
}
}
// Example usage:
const apiKey = 'YOUR_API_KEY';
const baseUrl = 'https://{your_name}.api.advaify.io';
const api = new AdValifySDK(apiKey, baseUrl);
const endpoint = '/v3/someEndpoint';
const data = { data: btoa('BINARY_DATA_OR_AD_TAG_HERE') };
api.sendRequest(endpoint, data)
.then(response => {
console.log('API Response:', response);
})
.catch(error => {
console.error('Error:', error.message);
});
require 'net/http'
require 'json'
require 'base64'
class AdValifySDK
def initialize(api_key, base_url)
@api_key = api_key
@base_url = base_url
end
def send_request(endpoint, data = {})
url = URI("#{@base_url}#{endpoint}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true if url.scheme == 'https'
request = Net::HTTP::Post.new(url)
request['Content-Type'] = 'application/json'
request['X-ApiKey'] = "#{@api_key}"
request.body = data.to_json
begin
response = http.request(request)
if response.is_a?(Net::HTTPSuccess)
return JSON.parse(response.body)
else
raise StandardError, "HTTP Error: #{response.code} #{response.message}"
end
rescue StandardError => e
raise "Request Error: #{e.message}"
end
end
end
# Example usage:
api_key = 'YOUR_API_KEY'
base_url = 'https://{your_name}.api.advaify.io'
api = AdValifySDK.new(api_key, base_url)
endpoint = '/v3/someEndpoint'
data = { 'data' => Base64.encode64('BINARY_DATA_OR_AD_TAG_HERE') }
begin
response = api.send_request(endpoint, data)
puts "API Response: #{response}"
rescue StandardError => e
puts "Error: #{e.message}"
end
const axios = require('axios');
class AdValifySDK{
constructor(apiKey, baseUrl) {
this.apiKey = apiKey;
this.baseUrl = baseUrl;
}
async sendRequest(endpoint, data = {}) {
const url = `${this.baseUrl}${endpoint}`;
const headers = {
'Content-Type': 'application/json',
'X-ApiKey': `${this.apiKey}`
};
try {
const response = await axios.post(url, data, { headers });
return response.data;
} catch (error) {
throw new Error(`Request Error: ${error.message}`);
}
}
}
// Example usage:
const apiKey = 'YOUR_API_KEY';
const baseUrl = 'https://{your_name}.api.advaify.io';
const api = new AdValifySDK(apiKey, baseUrl);
const endpoint = '/v3/someEndpoint';
const data = { data: Buffer.from('BINARY_DATA_OR_AD_TAG_HERE').toString('base64') };
api.sendRequest(endpoint, data)
.then(response => {
console.log('API Response:', response);
})
.catch(error => {
console.error('Error:', error.message);
});
import json
import requests
import base64
class AdValifySDK:
def __init__(self, api_key, base_url):
self.api_key = api_key
self.base_url = base_url
def send_request(self, endpoint, data=None):
headers = {
'Content-Type': 'application/json',
'X-ApiKey': '' + self.api_key
}
url = self.base_url + endpoint
payload = json.dumps(data) if data is not None else None
try:
response = requests.post(url, headers=headers, data=payload)
response.raise_for_status() # Raise an exception for HTTP errors
return response.text
except requests.exceptions.RequestException as e:
raise Exception('Request Error: ' + str(e))
# Example usage:
api_key = 'YOUR_API_KEY'
base_url = 'https://{your_name}.api.advaify.io'
api = AdValifySDK(api_key, base_url)
endpoint = '/v3/someEndpoint'
data = {'data': base64.b64encode('BINARY_DATA_OR_AD_TAG_HERE')}
try:
response = api.send_request(endpoint, data)
print("API Response:", response)
except Exception as e:
print("Error:", str(e))
|