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 can 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.
- 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
Navigate to your function app in the Azure portal, select App Keys, and then the
_master
key.In the Edit key section, copy the key value to your clipboard, and then select OK.
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.
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:
Enter the request location in the URL text box.
Ensure the HTTP method is set to POST.
Select the Headers tab.
Type x-functions-key as the first key and paste the master key (from the clipboard) as the value.
Type Content-Type as the second key and type application/json as the value.
Select the Body tab.
Type { "input": "test" } as the body for the request.
Note
If you don't want to pass data into the function, you must still pass an empty dictionary
{}
as the body of the POST request.Select Send.
Postman then reports a status of 202 Accepted.
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.
Next steps
Feedback
Submit and view feedback for