lingareddy_Alva
Esteemed Contributor

@Andolina1 

I see the issue in your code. The problem is with how you're constructing the body parameter object.
The Problem
You're formatting the parameters dictionary into a string when creating the body,
which is causing the parameters to be sent incorrectly:

body = {
'parameters': f'{parameters}' # This converts parameters to a string representation
}

When you use f'{parameters}', it converts your dictionary to a string like "{'curr_working_user': 'xyz'}",
which ADF can't parse correctly as a JSON object.

Solution:
Simply pass the parameters dictionary directly without string conversion:

body = {
'parameters': parameters # Pass the dictionary directly
}

Here's the corrected code:

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"

# 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"
}

# Corrected body construction - pass the dictionary directly
body = {
'parameters': parameters
}

print(json.dumps(body, indent=1))
response = requests.post(url, headers=headers, json=body)
print(response.status_code)
print(response.json())


This will ensure that the parameters are properly serialized as a JSON object within the request body,
and ADF will receive them in the correct format.
If you want to verify the request is formatted correctly, you can add these debug lines:
import json
print("Request URL:", url)
print("Request body:", json.dumps(body, indent=2))

The properly formatted JSON should look like:
{
"parameters": {
"curr_working_user": "xyz"
}
}

 

LR