How to trigger an Azure Data Factory pipeline through API using parameters

Andolina1
New Contributor III

Hello All,

I have a use case where I want to trigger an Azure Data Factory pipeline through API. Right now I am calling the API in Databricks and using Service Principal(token based) to connect to ADF from Databricks.The ADF pipeline has some parameters which I want to pass via the API.

The issue is when I run the notebook, the ADF pipeline gets triggered, but the parameters get passed as empty values or ''. Below is the code for POST method to trigger the pipeline (some details have been masked for security reasons):

tenant_id = dbutils.secrets.get(scope="adb-dev-secret-scope",key="spn-databricks-dev-eastus2-001-tenantid")

client_id = dbutils.secrets.get(scope="adb-dev-secret-scope",key="spn-databricks-dev-eastus2-001-clientid")

client_secret = dbutils.secrets.get(scope="adb-dev-secret-scope",key="spn-databricks-dev-eastus2-001-secret")

subscription_id = "****"

resource_group = "****"

factory_name = "****"

pipeline_name = "Test Adf from databricks"

api_version = "2018-06-01"

# Optional: parameters to pass to pipeline

parameters = {

'curr_working_user': 'xyz'

}

# === Get token using client secret auth ===

credential = ClientSecretCredential(tenant_id, client_id, client_secret)

token = credential.get_token("https://management.azure.com/.default").token

url = f"https://management.azure.com/subscriptions/{subscription_id}/resourceGroups/{resource_group}/provide...}"

headers = {

"Authorization": f"Bearer {token}",

"Content-Type": "application/json"

}

body = {

'parameters': f'{parameters}'

}

print(json.dumps(body, indent=1))

response = requests.post(url, headers=headers, json=body)

print(response.status_code)

print(response.json())

I want the parameter "curr_working_user" to be passed as 'xyz' in ADF pipeline. The parameter in ADF is same: curr_working_user.

You help is greatly appreciated!!

Thanks,

Andolina

#azuredatafactory #API #parameters