Adzerk API Quickstart and Tutorial
Executable Code Samples

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

import { Client } from "@adzerk/decision-sdk";

// Demo network, site, and ad type IDs; find your own via the Adzerk UI!
let client = new Client({ networkId: 23, siteId: 667480 });

let request = {
  placements: [{ adTypes: [5] }],
  user: { key: "abc" },
  keywords: ["keyword1", "keyword2"]
};

client.decisions.get(request).then(response => {
  console.dir(response, { depth: null });
});
Copy
<!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://unpkg.com/@adzerk/decision-sdk/dist/adzerk-decision-sdk.js"></script>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script type="text/javascript">
      requestNativeAd = function() {
        // Demo network, site, and ad type IDs; find your own via the Adzerk UI!
        let client = new AdzerkDecisionSdk.Client({
          networkId: 23,
          siteId: 667480
        });

        let request = {
          placements: [{
            adTypes: [5]
          }]
        };

        client.decisions.get(request).then(response => {
          let decision = response.decisions.div0[0];

          // Inject ad contents into page
          $("#div0").replaceWith(decision.contents[0].body);
          $("#response").text(JSON.stringify(response));
          $("#clickUrl").text(decision.clickUrl);

          // Record the impression
          client.pixels.fire({
            url: decision.impressionUrl
          });

        }).catch(error => {
          console.log("ERROR!", error.toString());
        });
      };
    </script>
  </head>

  <body>
    <h1>Adzerk Native Ad Request</h1>

    <p>Press the button to make an ad request, record the impression, and display both the internal JSON and HTML payload of the response. The response includes data like Impression URL, Click URL, Campaign ID, Metadata, and more. (Note: May not work if you're using an ad blocker).</p>

    <button type="button" onclick="requestNativeAd()">Request Ad</button>

    <hr />

    <h4>Image:</h4>
    <div id="div0">
      <code>(Nothing yet; please click the button!)</code>
    </div>

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

    <h4>Click URL:</h4>
    <code id="clickUrl">(Nothing yet; please click the button!)</code>
  </body>
</html>
Copy
package com.adzerk.examples;

import java.util.*;
import com.adzerk.sdk.*;
import com.adzerk.sdk.generated.ApiException;
import com.adzerk.sdk.generated.model.*;
import com.adzerk.sdk.model.DecisionResponse;

public class FetchAds {
  public static void main(String[] args) throws ApiException {
    // Demo network, site, and ad type IDs; find your own via the Adzerk UI!
    Client client = new Client(new ClientOptions(23).siteId(667480));
    Placement placement = new Placement().adTypes(Arrays.asList(5));
    User user = new User().key("abc");

    DecisionRequest request = new DecisionRequest()
      .placements(Arrays.asList(placement))
      .keywords(Arrays.asList("keyword1", "keyword2"))
      .user(user);

    DecisionResponse response = client.decisions().get(request);
    System.out.println(response.toString());
  }
}
Copy
import adzerk_decision_sdk

# Demo network, site, and ad type IDs; find your own via the Adzerk UI!
client = adzerk_decision_sdk.Client(23, site_id=667480)

request = {
  "placements": [{"adTypes": [5]}],
  "user": {"key": "abc"},
  "keywords": ["keyword1", "keyword2"],
}

response = client.decisions.get(request)
print(response)
Copy
require "adzerk_decision_sdk"

# Demo network, site, and ad type IDs; find your own via the Adzerk UI!
client = AdzerkDecisionSdk::Client.new(network_id: 23, site_id: 667480)

request = {
  placements: [{ adTypes: [5] }],
  user: { key: "abc" },
  keywords: ["keyword1", "keyword2"],
}

pp client.decisions.get(request)
Copy
(ns example-ad-request
  (:import (com.adzerk.sdk Client ClientOptions)
           (com.adzerk.sdk.generated.model DecisionRequest Placement User)))

(defn -main []
  ; Demo network, site, and ad type IDs; find your own via the Adzerk UI!
  (let [client (Client. (doto (ClientOptions. (int 23)) (.siteId (int 667480))))
        request (doto (DecisionRequest.)
                      (.placements [(doto (Placement.) (.adTypes [5]))])
                      (.keywords ["keyword1" "keyword2"])
                      (.user (doto (User.) (.key "abc"))))
        response (-> client (.decisions) (.get request))]

    (println response)))
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
Or, Test With JSFiddle

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




Developer Updates

Subscribe for updates and announcements of Adzerk developer tools, SDKs, updates, and events

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

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

Start now