I’m currently working with the Asana API and need to fetch all stories (comments, updates, etc.) for a project. So far, I have only found methods to fetch stories by individual tasks. Is there a more efficient way to retrieve all stories for an entire project directly?
Any guidance or recommendations on how to achieve this would be greatly appreciated!
Now goal is to retrieve stories for multiple tasks using the Batch API endpoint. However, I am receiving a 400 Bad Request error when making the request.
Here is the code I am using,
import asana
import requests
import json
# Your Asana personal access token
personal_access_token = 'personal_access_token'
# Function to perform a batch request to retrieve stories for multiple tasks
def batch_request(task_ids):
# Construct the batch request
batch_request = {
"actions": [
{
"method": "get",
"relative_path": f"/tasks/{task_id}/stories"
} for task_id in task_ids
]
}
# API endpoint for batch requests
batch_url = 'https://app.asana.com/api/1.0/batch'
# Send the batch request
headers = {
'Authorization': f'Bearer {personal_access_token}',
'Content-Type': 'application/json'
}
try:
response = requests.post(batch_url, json=batch_request, headers=headers)
# Check if the request was successful
if response.status_code == 200:
batch_response = response.json()
for result in batch_response['data']:
if 'errors' in result:
print("Batch request error:", result['errors'])
else:
print("Batch request success:", result)
else:
print(f"Batch request failed with status code {response.status_code}")
print(response.text)
except requests.RequestException as e:
print(f"Batch request exception: {e}")
# Test the batch request (replace with actual task IDs)
batch_request(['1207872325643479', '1207872327937129'])
Problem:
Despite following the documentation, I am receiving a 400 Bad Request error. I have verified the format of the request and the API endpoint. The error message from the response body indicates that the request may be malformed or that there is an issue with the provided parameters.
Questions:
Is there a specific format or additional parameters required for the batch request that I might be missing?
Could there be an issue with the way the batch_request payload is constructed?
Are there any common pitfalls or troubleshooting steps that I should consider when working with the Asana Batch API?
Any assistance or guidance on resolving this issue would be greatly appreciated.