MediaMath / t1-python

Python SDK for MediaMath Platform APIs
https://developer.mediamath.com/
Apache License 2.0
18 stars 30 forks source link

How to include audience segments for a strategy? #118

Closed robrechtdr closed 7 years ago

robrechtdr commented 7 years ago

What do I want to achieve?

For (e.g.) Strategy 1707441 I’d like to include the audience segment 14_Female_25-54_MaxComp through the API.

The id for that segment is 1645683btw , found that through non-SDK API call.

What have I tried?

strategy_targeting = t1.get(“strategies”, 1707441, child=”audience_segments”)
>>> strategy_targeting
<generator object _gen_classes at 0x10a8335a0>  
# It’s an empty generator btw

Why I expected a non-empty object is because when I do

strategy_targeting = t1.get(“strategies”, 1707441, child=”dma”)
>>> TargetDimension(_type='target_dimension', parent='strategies', parent_id=1707442, exclude=[], include=[TargetValue(_type=u'target_value',code=u'613', name=u'United States / Minnesota / Minneapolis-St. Paul', entity_type=u'target_value', id=362, …]
strategy_targeting[“include”] = [374, 455, 301]
strategy_targeting.save()

This properly includes those 3 dma location targets on t1.

Also, the child name audience segments should be correct because

aud = t1.get("audience_segments",1645683,full=True)
>>> aud
AudienceSegment(_type=u'audience_segment', code=u'911000086', retail_cpm=0.0, created_on=datetime.datetime(2016, 9, 28, 10, 39, 43, tzinfo=FixedOffset(0)), taxonomy_id=229, parent_audience_segment_id=1645480, id=1645683, wholesale_cpm=0.0, name=u'14_Female_25-54_MaxComp', entity_type=u'audience_segment', audience_vendor_id=313, version=0, child_count=0, updated_on=datetime.datetime(2016, 9, 28, 10, 39, 43, tzinfo=FixedOffset(0)), type=u'custom', full_path=u'Quantcast Private - Reckitt Benckiser US - 14_Female_25-54_MaxComp', buyable=True)

I'm using the t1 sdk with commit state of https://github.com/MediaMath/t1-python/commit/f98f2a5048756b22d58abd32c3425cf58ce2af5f.

FodT commented 7 years ago

There are no audience segments attached to that strategy. Are you looking to set up targeting through the SDK?


select count(*) from strategy_audience_segments where strategy_id = 1707441
count
0
robrechtdr commented 7 years ago

screen shot 2017-01-03 at 14 02 43

Yes, I'm looking to put 14_Female_25-54_MaxComp in "included audience" on t1.

robrechtdr commented 7 years ago

Fod: "afaik right now we dont actually support this at all".

For whoever runs into this problem again; the api call to do te desired is under Change the Audience Targeting of a Strategyon https://developer.mediamath.com/docs/read/execution_and_management_api/targeting/Audience_Segments .

With payload e.g.:

{ "segments.1.id":1645683, "segments.1.restriction": "INCLUDE", "include_op":"OR", "exclude_op":"OR" }

Bit confusing imo to have to pass on segments.1.restriction as a string as dots are usually used for attributes of objects so expected the following was needed initially:

{ "segments": { 1: {"id": 1645683, "restriction": "INCLUDE"}}, "include_op":"OR", "exclude_op":"OR"}