Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
4,997 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi, How to query in synapse pipeline activity runs using api, i want to know inside pipeline how many activities we are running per day any option is there to find out this in synapse
Here’s how you can query activity runs in Synapse using the API:
POST https://login.microsoftonline.com/{tenantId}/oauth2/token
Replace {tenantId}
with your Azure AD tenant ID. The request body should contain the following parameters:
grant_type
: client_credentialsclient_id
: (your application client ID)client_secret
: (your application secret)resource
: https://management.azure.com/Pipeline Runs - Query By Factory
API. The API allows you to filter pipeline runs by a specific time range, such as daily.
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Synapse/workspaces/{workspaceName}/pipelines/{pipelineName}/queryActivityRuns?api-version=2020-12-01
Replace:
{subscriptionId}
: Your Azure subscription ID{resourceGroupName}
: The resource group containing your Synapse workspace{workspaceName}
: The name of your Synapse workspace{pipelineName}
: The name of the pipeline you want to query
{
"startTime": "YYYY-MM-DDTHH:MM:SS",
"endTime": "YYYY-MM-DDTHH:MM:SS",
"filters": []
}
Set the startTime
and endTime
for your desired date range.
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Synapse/workspaces/{workspaceName}/pipelines/{pipelineName}/runs/{runId}/activityruns?api-version=2020-12-01
Replace {runId}
with the ID of the pipeline run obtained in step 2.Here’s an example of querying activity runs within a Synapse pipeline for the last day:
import requests
# Set your credentials
tenant_id = "your-tenant-id"
client_id = "your-client-id"
client_secret = "your-client-secret"
subscription_id = "your-subscription-id"
resource_group = "your-resource-group"
workspace_name = "your-workspace-name"
pipeline_name = "your-pipeline-name"
# Get the OAuth2 token
auth_url = f"https://login.microsoftonline.com/{tenant_id}/oauth2/token"
auth_payload = {
"grant_type": "client_credentials",
"client_id": client_id,
"client_secret": client_secret,
"resource": "https://management.azure.com/"
}
auth_response = requests.post(auth_url, data=auth_payload)
access_token = auth_response.json()["access_token"]
# Set headers for the request
headers = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json"
}
# Query pipeline runs
pipeline_runs_url = f"https://management.azure.com/subscriptions/{subscription_id}/resourceGroups/{resource_group}/providers/Microsoft.Synapse/workspaces/{workspace_name}/pipelines/{pipeline_name}/queryActivityRuns?api-version=2020-12-01"
pipeline_runs_payload = {
"startTime": "2024-09-11T00:00:00",
"endTime": "2024-09-12T00:00:00",
"filters": []
}
pipeline_runs_response = requests.post(pipeline_runs_url, headers=headers, json=pipeline_runs_payload)
# Parse the response
print(pipeline_runs_response.json())