I am preparing Azure automation, I am using Python SDK Automation runbook, runbook will be triggered by a webhook. I tested webhook, and I am able to run Python runbook using webhook. Automation Runbook Job status is Completed
, I can see output data.
input data
"WebhookName":"webhookname","RequestBody":"{\"name\": \"Mike\", \"Nazwisko\": \"Tyson\"}","RequestHeader":{"Connection":"keep-alive","Accept":"*/*","Accept-Encoding":"gzip","Host":"XXXzzzWWW.webhook.wus2.azure-automation.net","User-Agent":"python-requests/2.27.1","x-ms-request-id":"AAAbbbCCC"}}
output data
['C:\\Temp\\ce51on0d.0c4\\XXvvBB', '{WebhookName:webhookname,RequestBody:{"name":', '"Mike",', '"Nazwisko":', '"Tyson"},RequestHeader:{Connection:keep-alive,Accept:*/*,Accept-Encoding:gzip,Host:AAAbbbCCC.webhook.wus2.azure-automation.net,User-Agent:python-requests/2.27.1,x-ms-request-id:AAbbCC}}']
Python script for sending webhook
import requests
import json
url = 'webhookURL'
payload = {'name': 'Mike','Nazwisko': 'Tyson'}
requests.post(url, data=json.dumps(payload), headers={'Content-Type': 'application/json'})
My question is how can I get, in my Automation Python runbook, specific values from Webhook data. like:
var1 = payload.name
var2 = payload.nazwisko
I was trying with sys
module, but it does not work as expected.
import sys
test = str(sys.argv)
print(test)
Finally I prepared my Azure Automation runbook, and works as expected, below, Python runbook code.