Native Ads API Quickstart

Post

to the Native Ads API.

Parse

the JSON response.

Place

on your site or app!

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: http://engine.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 Native Ads - 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://engine.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 Native Ads - JavaScript Request</h1>
    <p>Press the button to make a native 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 a Native 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
// php simple stuff here...
Copy
require 'net/http'
require 'uri'
require 'json'

uri = URI.parse("http://engine.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
curl -H 'Content-Type:application/json' \
     -X POST \
     -d '{"placements":[{"divName":"div1","networkId":23,"siteId":667480,"adTypes":[5]}],"user":{"key":"abc"}}' \
     http://engine.adzerk.net/api/v2
Copy
// c# simple stuff here...
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("http://engine.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
// clojure simple stuff here...
Copy



Interactive JavaScript Sample


JSFiddle