Demand Key-Value Targeting API

Once keys have been created, you can apply key-value targeting to demand tags. Targeting on Key-Value pairs can be done on an AND and OR basis. Any combination of Key-Value pairs with the same group ID will follow AND logic. OR logic will be applied for targeting of different groups.

Visit the Demand page for more information on Key-Value Targeting on a Demand Tag.

Add Key-Value Targeting

SDK 

In [1]: tag = springserve.demand.get(30424)

In [2]: tag.key_value_targeting = True
In [3]: tag.targeting_keys = [{'key_id': 90, 'list_type': 'white_list', 'group': 1, 'value_ids': [60]}]

In [4]: tag.ok
Out [4]: True

API

POST /api/v0/demand_tags/<demand_tag_id>/demand_tag_keys/<id>

Headers

Content-Type application/json
Authorization "yourAuthToken"

Body (example)

{
   "group": "1",
   "key_id": "27",
   "list_type": "white_list",
   "value_ids": [53]

}


Required parameters: group, key_id, list_type, value_ids

Response

Status code 200

[
  'targeting_keys': [{'id': 247,
   'key_id': 27,
   'list_type': 'white_list',
   'group': '1',
   'targeting_key_type': 'values',
   'key_required': True,
   'free_values': [],
   'value_ids': [53],
   'value_list_ids': []}]
]

Get Key-Value Targeting

SDK

In [1]: tag = springserve.demand_tags.get(30424)

In [2]: demand_keys = tag.get_key_value_targeting_keys()

In [3]: demand_keys.ok
Out [3]: True

In [4]: for k in demand_keys:
   ...:     print k.key_id
Out [4]: 27

API

GET /api/v0/demand_tags/<demand_tag_id>/demand_tag_keys

Headers

Content-Type application/json
Authorization "yourAuthToken"

Response

Status code 200

[
  {
    'demand_tag_id': 122870,
    'free_values': [],
    'group': u'1',
    'id': 157,
    'key_id': 25,
    'list_type': u'white_list',
    'value_ids': [53]
  }
]

Edit Key-Value Targeting

SDK

In [1]: tag = springserve.demand_tags.get(30424)

In [2]: demand_keys = tag.get_key_value_targeting_keys()

In [3]: key = demand_keys[0]

In [4]: key.value_ids
Out [4]: [53]


In [5]: key.value_ids = [53, 54]


In [6]: saved = key.save()


In [7]: saved.ok
Out [7]: True

API

PUT /api/v0/demand_tags/<demand_tag_id>/demand_tag_keys/<id>

Headers

Content-Type application/json
Authorization "yourAuthToken"

Body (example)

{
   "group": "1",
   "key_id": "27",
   "list_type": "white_list",
   "value_ids": [53, 54]

}


Response

Status code 200

[
  {
    'demand_tag_id': 122870,
    'free_values': [],
    'group': u'1',
    'id': 157,
    'key_id': 25,
    'list_type': u'white_list',
    'value_ids': [53, 54]
  }
]