Azure Functions REST API

Overview

The Azure Functions REST API allows you to programmatically manage and interact with your Azure Functions resources. You can use this API to deploy code, manage function keys, monitor executions, and much more.

This API is built around standard REST principles, using HTTP methods (GET, POST, PUT, DELETE) and JSON for request and response bodies.

Key Concepts

Tip: For most operations, you will need to authenticate using Azure Active Directory (now Microsoft Entra ID) or a Function Key.

Authentication

Accessing the Azure Functions REST API requires proper authentication. The primary methods are:

1. Azure Active Directory (Microsoft Entra ID) Authentication

This is the recommended method for programmatic access, especially for management operations. You'll need to register an application in Azure AD and obtain credentials (client ID, client secret, tenant ID). Use these to acquire an OAuth 2.0 access token.

The access token should be included in the Authorization header of your requests:

Authorization: Bearer <your_access_token>

2. Function Keys

For invoking specific functions, you can use function keys. These are obtained through the Azure portal or programmatically via the Management API. Keys can be associated with a specific function or the entire Function App.

When using a function key, include it in the x-functions-key header:

x-functions-key: <your_function_key>
Note: Function keys are generally less secure than Azure AD authentication for management tasks and should be treated with care.

API Endpoints

The following are some of the common API endpoints available. For a comprehensive list, refer to the official Azure Functions REST API documentation.

Function App Management

GET /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{functionAppName}

Get details of a specific Function App.

POST /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{functionAppName}/start

Start a Function App.

POST /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{functionAppName}/stop

Stop a Function App.

Function Key Management

GET /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{functionAppName}/functions/{functionName}/listkeys

List all keys for a specific function.

POST /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{functionAppName}/functions/{functionName}/regeneratekeys?keyName=default

Regenerate a specific key for a function.

Function Invocation

To invoke a function directly, you typically send a POST request to the function's URL, including any required authorization (e.g., function key) and the request payload.

POST /api/{functionName}

Invoke a specific HTTP-triggered function. (Note: The base URL will depend on your Function App's deployment).

Request Body Example:

{
    "name": "World"
}

The exact URL for function invocation depends on your Function App's host and any custom domain configurations.

Monitoring and Logs

The API provides access to diagnostic logs and execution details.

GET /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{functionAppName}/hostruntime/runtime/web/logs/applications/{applicationName}/logStream

Stream live application logs.

Error Handling

The Azure Functions REST API uses standard HTTP status codes to indicate the success or failure of a request. Error details are typically provided in a JSON response body.

Status Code Meaning
200 OK Request successful.
201 Created Resource created successfully.
400 Bad Request The request was malformed or invalid.
401 Unauthorized Authentication failed or credentials are missing.
403 Forbidden The authenticated user does not have permission to perform the action.
404 Not Found The requested resource could not be found.
500 Internal Server Error An unexpected error occurred on the server.

An error response typically includes a JSON object with fields like code and message:

{
    "code": "BadRequest",
    "message": "The request body is missing or invalid."
}

Rate Limiting

To ensure service stability and prevent abuse, Azure Functions REST API employs rate limiting. You may encounter 429 Too Many Requests errors if you exceed the allowed request limits within a specific time frame.

The specific limits can vary based on the Azure service tier and the type of operation. It's good practice to implement retry mechanisms with exponential backoff in your client applications.