Manually run a non HTTP-triggered function

This article demonstrates how to manually run a non HTTP-triggered function via specially formatted HTTP request.

In some contexts, you may need to run "on-demand" an Azure Function that is indirectly triggered. Examples of indirect triggers include functions on a schedule or functions that run as the result of another resource's action.

Postman is used in the following example, but you may use cURL, Fiddler or any other like tool to send HTTP requests.

Define the request location

To run a non HTTP-triggered function, you need a way to send a request to Azure to run the function. The URL used to make this request takes a specific form.

Define the request location: host name + folder path + function name

  • Host name: The function app's public location that is made up from the function app's name plus azurewebsites.net or your custom domain.
  • Folder path: To access non HTTP-triggered functions via an HTTP request, you have to send the request through the folders admin/functions.
  • Function name: The name of the function you want to run.

You use this request location in Postman along with the function's master key in the request to Azure to run the function.

Note

When running locally, the function's master key is not required. You can directly call the function omitting the x-functions-key header.

Get the function's master key

  1. Navigate to your function app in the Azure portal, select App Keys, and then the _master key.

    Locate the master key to copy.

  2. In the Edit key section, copy the key value to your clipboard, and then select OK.

    Copy the master key to the clipboard.

  3. After copying the _master key, select Code + Test, and then select Logs. You'll see messages from the function logged here when you manually run the function from Postman.

    Screenshot that shows the 'Code + Test' page with a message from the logs displayed.

Caution

Due to the elevated permissions in your function app granted by the master key, you should not share this key with third parties or distribute it in an application. The key should only be sent to an HTTPS endpoint.

Call the function

Open Postman and follow these steps:

  1. Enter the request location in the URL text box.

  2. Ensure the HTTP method is set to POST.

  3. Select the Headers tab.

  4. Type x-functions-key as the first key and paste the master key (from the clipboard) as the value.

  5. Type Content-Type as the second key and type application/json as the value.

    Postman headers settings.

  6. Select the Body tab.

  7. Type { "input": "test" } as the body for the request.

    Postman body settings.

  8. Select Send.

    Send a request with Postman.

    Postman then reports a status of 202 Accepted.

  9. Next, return to your function in the Azure portal. Review the logs and you'll see messages coming from the manual call to the function.

    View the logs to see the master key test results.

Next steps