How to pass parameter from webhook to a python runbook.

Arun M K 0 Reputation points
2024-10-16T22:58:19.99+00:00

Hi I have a python script which i want to run using Azure automation. I have added a webhook for this runbook and i am able to run the scipt using webhook url from ADF. The problem is I want to pass a parameter to the script.

Could someone help on this?

Thanks,
Arun

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,272 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Vinodh247 25,201 Reputation points MVP
    2024-10-19T13:26:32.2966667+00:00

    Hi Arun M K,

    Thanks for reaching out to Microsoft Q&A.

    To pass parameters from a webhook to an azure automation python runbook, you can include the parameter in the webhook payload and modify your runbook to accept it.

    Here’s how can set it up:

    1. Modify the Webhook Request:
      • When calling the webhook, pass the parameter in the request body. For example, if you are triggering the webhook from ADF, you can include the parameter in the body like this:

        { "myParameter": "parameterValue" }

    2. Modify the Python Runbook:
      • In your Python runbook, use the sys module to capture the webhook data. The webhookData is passed as a JSON object when the webhook is triggered.
      Here’s an example of how to retrieve and use the parameter:

      import sys import json

      Get the webhook data

      webhook_data = json.loads(sys.argv[1])

      Extract the parameter

      my_parameter = webhook_data.get('myParameter', 'default_value') print(f"Received parameter: {my_parameter}")

    3. Test the Integration:
      • Make sure you are passing the correct JSON format when triggering the webhook. If testing from adf ensure that the parameter is included properly in the body of the HTTP request activity.

    This way your python runbook can handle dynamic parameters passed from the webhook.

    Please feel free to click the 'Upvote' (Thumbs-up) button and 'Accept as Answer'. This helps the community by allowing others with similar queries to easily find the solution.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.