Executable Code Samples

Run a quick spike of our API with our pre-created ads. Just copy our examples below - no API key needed!

Post here: https://e-23.adzerk.net/api/v2

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>Adzerk Decision API - JavaScript Request</title>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script type="text/javascript">
      nativeAdRequest = function() {
        var data = JSON.stringify({
          "placements": [{
            "divName": "div1",
            "networkId": 23,
            "siteId": 667480,
            "adTypes": [5],
            "properties": {"foo": "bar"}
          }],
          "keywords": ["adzerk", "demo"]
        });
        $.ajax({
          url: "https://e-23.adzerk.net/api/v2",
          method: "POST",    
          dataType: 'json',
          data: data,
          success: function(data, status, xhr) {
            console.log("SUCCESS!!!", data);
            
            // record the impression; REQUIRED
            console.log("Impression URL: ", data.decisions.div1.impressionUrl, "\n");
            $.ajax({url: data.decisions.div1.impressionUrl, method: "GET"});

            // log & display the response
            console.log("Adzerk response:", data.decisions.div1);
            console.log("Click URL: ", data.decisions.div1.clickUrl);         
            $("#response").text(JSON.stringify(data.decisions.div1));
            $("#div1").replaceWith(data.decisions.div1.contents[0].body)
          },
          error: function(data, status, xhr) {
            console.log("ERROR!!!", data, status)
          }
        });
      };
    </script>
  </head>
  <body>
    <h1>Adzerk Decision API - JavaScript Request</h1>
    <p>Press the button to make a Decision ad request, record the impression, and display both the internal JSON and HTML payload of the response.  Also, check the console for logs!</p>

    <button type="button" onclick="nativeAdRequest()">Request an Ad</button>
    <br/>
    <hr/>

    <h5>Response:</h5>
    <code id="response">(Nothing yet; please click the button!)</code>

    <h5>HTML:</h5>
    <div id="div1"><code>(Nothing yet; please click the button!)</code></div>

  </body>
</html>
Copy
curl -H 'Content-Type:application/json' \
  -X POST \
  -d '{"placements":[{
  "divName":"div1",
  "networkId":23,
  "siteId":667480,
  "adTypes":[5]}],
  "user":{"key":"abc"}}' \
  \
  https://e-23.adzerk.net/api/v2
Copy
require 'net/http'
require 'uri'
require 'json'

uri = URI.parse("https://e-23.adzerk.net/api/v2")
header = {'Content-Type': 'application/json'}

data = {
  placements: [
    {
      divName:   'div1',
      networkId: 23,
      siteId:    667480,
      adTypes:   [5]
    }
  ],
  user: {"key":"abc"}
}

# Create the HTTP objects
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.request_uri, header)
request.body = data.to_json

# Send the request
response = http.request(request)
puts response.body
Copy
package com.adzerk.examples;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import javax.net.ssl.HttpsURLConnection;

class AdzerkNativeAdExample {

  public static void main(String[] args) throws Exception {
    System.out.println("\nTesting - Sending HTTP POST request...");

    URL url = new URL("https://e-23.adzerk.net/api/v2");
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();

    // Add request headers
    conn.setRequestMethod("POST");
    conn.setRequestProperty("Content-Type", "application/json");
    
    // Normally you'd use JSON here, but we've compressed it into a String for ease of instruction
    String params = "{\"placements\":[{\"divName\":\"div1\",\"networkId\":23,\"siteId\":667480,\"adTypes\":[5]}],\"user\":{\"key\":\"abc\"}}";

    // Send post request
    conn.setDoOutput(true);
    DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
    wr.writeBytes(params);
    wr.flush();
    wr.close();

    int responseCode = conn.getResponseCode();
    System.out.println("\nSending 'POST' request to URL : " + url);
    System.out.println("Post parameters : " + params);
    System.out.println("Response Code : " + responseCode);

    BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    String inputLine;
    StringBuffer response = new StringBuffer();

    while ((inputLine = in.readLine()) != null) {
     response.append(inputLine);
    }
    
    in.close();

    System.out.println(response.toString());
    System.out.println("\nDone!");
 }
}
Copy
Or, Test With JSFiddle

Click on 'Request Ad' in the Result tab to see the Response data.


Building with APIs comes with many innovative benefits

Quick MVP

Launch something in a couple weeks. If it fails, iterate. You'll build exactly what you want in no time.

100% Server-Side

JSON responses let you white-label Adzerk, serve native ads, and have super fast response times (as low as 35ms).

Avoid Ad Blocking

Since these are bespoke, custom ad units displayed server-side, you can avoid ad blocking tech.

Privacy Compliance

Our tools are 100% GDPR/CCPA compliant by default - no need to worry about non-compliance.

Features Galore

Easily give advertisers the targeting features they've come to expect thanks to Google, Amazon, & Facebook.



Adzerk is a great partner, and we recommend them to anyone building a custom ad server.
-Daniel Murray, Bed Bath & Beyond, Chief Digital Officer

Learn how Adzerk can help you build your own ad server in weeks, not years

Start now