Documentation
Code Examples
PHP

PHP example for Meta, DNS and Screenshot API

Here's an example using PHP's curl:

<?php
$authKey = "YOUR_AUTH_KEY"; // your API key
$curl = curl_init();
 
curl_setopt_array($curl, array(
  // to get the DNS records, change the URL to https://api.urlmeta.org/dns?domain=backupdiary.com
  // for screenshot, change the URL to https://api.urlmeta.org/screenshot?url=https://backupdiary.com
 
  CURLOPT_URL => "https://api.urlmeta.org/meta?url=https://backupdiary.com",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "accept: application/json",
    "content-type: application/json",
    "Authorization: Basic " . $authKey
  ),
));
 
$response = curl_exec($curl);
$err = curl_error($curl);
 
curl_close($curl);
 
if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

To render HTML or SVG as an image

<?php
$authKey = "YOUR_AUTH_KEY"; // your API key
$curl = curl_init();
 
curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.urlmeta.org/render",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_HTTPHEADER => array(
    "accept: application/json",
    "content-type: application/xml",
    "Authorization: Basic " . $authKey
  ),
  CURLOPT_POSTFIELDS => "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"100\" height=\"100\"><rect width=\"300\" height=\"100\" style=\"fill:rgb(0,0,255);stroke-width:1;stroke:rgb(0,0,0)\" /></svg>",
));
 
$response = curl_exec($curl);
$err = curl_error($curl);
 
curl_close($curl);
 
if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}