The same code without the tags (in the payload) succeeds with default template values, when adding the tags the message is getting 200-ok but on the onesignal dashboard - messages -delivery page i see NO RECIPIENTS status. what am i doing wrong ?
import json
import requests
headers = {'Authorization': 'Basic mykey',
'Content-Type': 'application/json'}
payload = {'app_id': 'myapp_id',
'include_player_ids': ['my_player_id'],
'tags': [{'key': 'full_name', 'relation': '=', 'value': 'MOSHOE'}],
'template_id': 'my_template id'}
req = requests.post('ONESIGNAL_URL',headers=headers,data=json.dumps(payload))
You cannot add custom variables to notifications sent from OneSignal. You need to tag user devices first, then use the tag key within the template directly or API call and the OneSignal servers will substitute that tag key with the value you set on each device.
For example, I tagged a user's device with the sendTag
method with key:value pair "full_name": "Bob Odenkirk"
Within my API call, I want the message to say "Hey Bob Odenkirk, you are awesome!"
Then my contents property within the API call will look like:
"contents": {"en": "Hey {{ full_name }}, you are awesome!"}
OneSignal Tagging Guide:https://documentation.onesignal.com/docs/add-user-data-tags
OneSignal Tag Substitution Guide: https://documentation.onesignal.com/docs/personalization