Summary

Requirements:

  • python 3

This notebook show how to make call to the AppNexus API.
Implemented functions:

def get_campaign(self, ids=None, one_id=None, advertiser_id=None, only_names=True):
        """ cf https://wiki.appnexus.com/display/api/Campaign+Service"""

    def get_pixel(self, ids=None, one_id=None, advertiser_id=None,
                   advertiser_code=None, pixel_code=None, only_names=True):
        """ cf https://wiki.appnexus.com/display/api/Conversion+Pixel+Service """

    def get_device(self, one_id=None, device_type=None, only_names=True):
        """ cf https://wiki.appnexus.com/display/api/Device+Model+Service """

    def get_advertiser(self, ids=None, one_id=None, search_term=None, only_names=True):
        """ cf https://wiki.appnexus.com/display/api/Advertiser+Service"""

    def get_line_item(self, ids=None, one_id=None, advertiser_id=None, only_names=True):
        """ cf https://wiki.appnexus.com/display/api/Line+Item+Service"""

    def get_insertion_order(self, ids=None, one_id=None, advertiser_id=None, search_term=None, only_names=True):
        """ cf https://wiki.appnexus.com/display/api/Insertion+Order+Service"""

    def get_segment(self, ids=None, one_id=None, search_term=None, only_names=True):
        """ cf https://wiki.appnexus.com/display/api/Segment+Service"""

In [1]:
from pynexus import AppNexusAPI

APPNEXUS_ACCOUNT = {
    "username": "",
    "password": ""
}
api = AppNexusAPI(**APPNEXUS_ACCOUNT)

1. Make a request

Only the mapping id -> name


In [2]:
api.get_device(one_id=80)


Out[2]:
{80: 'One Touch 156'}

Full response


In [3]:
api.get_device(one_id=80, only_names=False)


Out[3]:
{'count': 1,
 'dbg_info': {'awesomesauce_cache_used': False,
  'count_cache_used': True,
  'db': '10.3.78.21',
  'instance': '62.bm-hbapi.prod.nym2',
  'member_last_modified_age': 1476455595,
  'output_term': 'device-model',
  'read_limit': 100,
  'read_limit_seconds': 60,
  'reads': 2,
  'slave_hit': True,
  'slave_lag': 0,
  'start_microtime': 1476455595.7868,
  'time': 101.31597518921,
  'user::read_limit': 100,
  'user::read_limit_seconds': 60,
  'user::reads': 3,
  'user::write_limit': 60,
  'user::write_limit_seconds': 60,
  'user::writes': 0,
  'uuid': 'c845c11348223b07',
  'version': '1.16.791',
  'warnings': [],
  'write_limit': 60,
  'write_limit_seconds': 60,
  'writes': 0},
 'device-model': {'codes': [{'code': 'da-205064',
    'device_model_id': 80,
    'id': 80,
    'notes': 'Alcatel:One Touch 156'}],
  'device_make_id': 12,
  'device_make_name': 'Alcatel',
  'device_type': 'Phone',
  'device_type_id': 2,
  'id': 80,
  'last_modified': '2016-08-09 14:54:06',
  'name': 'One Touch 156',
  'screen_height': 80,
  'screen_width': 101,
  'supports_cookies': None,
  'supports_flash': None,
  'supports_geo': None,
  'supports_html_audio': None,
  'supports_html_video': None,
  'supports_js': None},
 'num_elements': 100,
 'start_element': 0,
 'status': 'OK'}

2. Bulk request

If you need to retrieve more than 100 mappings, you will need to make several call.
The bulk_requests function can to that for you


In [5]:
pixels = AppNexusAPI.bulk_requests(api.get_pixel, range(0, 300))


The installed widget Javascript is the wrong version.

You may also want to retrieve all the elements, without specifying an id.
base the default get function will only return up to 100 elements, you can use the bulk_request_get_all to avoid hitting the limit.


In [6]:
# We limit here the number of calls to 10
names = AppNexusAPI.bulk_request_get_all(api.get_pixel, limit=10, only_names=True)


2016-10-14 16:33:33 INFO 9134 elements found
The installed widget Javascript is the wrong version.
2016-10-14 16:33:42 INFO 	10/10, breaking loop


In [7]:
print('%d elements downloaded' % len(names))


1000 elements downloaded

In [ ]: