So ive been working away on this and think im nearly there with subscriptions in my smart app but no matter what I try im getting a 403 error when trying to create the “All Contact Sensor” subscription.
See my code below…
elif (content['lifecycle'] == 'UPDATE'):
print(content['lifecycle'])
print('The auth token is:' + str(content['updateData']['authToken']))
print('The app id is:' + str(content['updateData']['installedApp']['installedAppId']))
#Build Post URL
BaseURL = 'https://api.smartthings.com/v1/installedapps/'
AppID = content['updateData']['installedApp']['installedAppId']
EndURL = '/subscriptions'
#Assign Token to variable
authtoken = content['updateData']['authToken']
#Subscribe to all contact sensor events
headers = {'Authorization': 'Bearer '+authtoken}
datasub = {
"sourceType": "CAPABILITY",
"capability": {
"locationId": LocationID,
"capability": "contactSensor",
"attribute": "contact",
"value": "*",
"stateChangeOnly": "true",
"subscriptionName": "all_contacts_sub"
}
}
r = requests.post(BaseURL+str(AppID)+EndURL,headers=headers,json=datasub)
#error checking for creation of subscription
print(r.status_code)
print('The below is the content for the fault code')
print(r.content)
if r.status_code == 200:
print('Subscription successfully created')
else:
print('Error Creating subscription because you prob dont have the token')
I can confirm that the location ID is correct. The auth token is correctly retrieved during the update lifecycle along with the application iD.
Ive also looked and I need to have r:devices set during the Initialization lifecycle. I have this done as per the code below…
When I do this the app gives me an error when authorizing.
Maybe I need to chase this ticket before troubleshooting more?. Banging my head at this stage!
If anyone can see something wrong in this code id appreciate the feedback.
Thanks.