Hi Anvil Support Team,
I’m encountering an issue with making a POST request to the Darwin V7 API using Anvil. The request consistently returns an HTTP 422 error indicating that fields workflow_id
and filters
are missing. However, the same request works perfectly when executed in Google Colab and via Curl. I suspect there might be an issue with the payload structure when using Anvil, but I can’t pinpoint the exact problem.
Here’s the context:
- API Endpoint:
https://darwin.v7labs.com/api/v2/teams/{team_slug}/items/assign
- Payload Structure:
{
“filters”: {
“dataset_ids”: [67890],
“select_all”: true,
“item_paths”: [“/folder_1”]
},
“assignee_id”: 45689,
“workflow_id”: “bt56678-reed-5678-5f6c-6f7f9f0f0d5ds”
}
Headers:
Authorization: ApiKey my_actual_api_key
Content-Type: application/json
Accept: application/json
Google Colab and Curl:
- Google Colab: The request works without any issues.
- Curl: The request works and returns a successful response.
Here is my Anvil server function:
import anvil.http
import anvil.server
@anvil.server.callable
def assign_items_to_user(user_id, dataset_id, folder_path, workflow_id):
API_KEY = 'my_actual_api_key'
url = "https://darwin.v7labs.com/api/v2/teams/{team_slug}/items/assign"
payload = {
"filters": {
"dataset_ids": [dataset_id],
"select_all": True,
"item_paths": [folder_path]
},
"assignee_id": user_id,
"workflow_id": workflow_id
}
headers = {
"Authorization": f"ApiKey {API_KEY}",
"Content-Type": "application/json",
"Accept": "application/json"
}
print("Sending payload:", payload)
print("Using headers:", headers)
try:
response = anvil.http.request(url, method="POST", json=payload, headers=headers)
print(f"API Response: {response}")
return response
except anvil.http.HttpError as e:
error_details = e.content if hasattr(e, 'content') else str(e)
print(f"HTTP error details: {error_details}")
return {"error": f"HTTP error 422: {error_details}"}
except Exception as e:
error_message = str(e)
print(f"An error occurred: {error_message}")
return {"error": error_message}
Error Details:
HTTP error 422: {'errors': {'code': 'INVALID_REQUEST', 'message': "Invalid request. Refer to 'detail' for specific errors.", 'status': 422, 'detail': {'missing_field': ['/workflow_id', '/filters']}}}
Steps I’ve Taken:
- Verified the payload structure and headers.
- Successfully ran the request in Google Colab and Curl.
- Ensured that the API key and all parameters are correctly set.
Is there something specific to how Anvil handles JSON payloads or headers that might be causing this issue? Any insights or suggestions to resolve this would be greatly appreciated.
Thank you!
Reference: