Add attachments to tasks with API

We have 24 brick and mortar locations that all need the same Wrike task assigned to them. The copy, duplicate, blueprint, and import options in the UI don't work for this as those would push the same task to the 24 stores instead of an individual task to each store. We need each store to complete the task on their own for tracking when we push it out. This is a very manual and time consuming process to build in 24 tasks today.

To solve for this I'm using the API with Postman. I'm able to make a POST that reads off of a CSV file to import 24 individual tasks to solve for the issue above. I now need to go a step further and use the API to attach a file (i.e. xls, .csv, .txt, etc.) from my PC to those 24 tasks I've created. 

Where I'm getting hung up on this is that from what I can tell, I first need to POST in my 24 tasks so that Wrike can create unique task ID's for each of them. After that completes, I need to fetch those ID's so that I can do another POST to upload my attachment to those newly created tasks. 

I'm almost certain this can be achieved by using a Pre-request Script, or by chaining my calls together with variables, but I can't seem to figure out how that's done. I've watched tutorials on this but can never seem to get those to work for my situation in Wrike/Postman. Keep in mind I'm a complete novice in the API space and learning as I go so I'd need you to step me through this in very simplistic procedural steps. 

Thank you in advance for any assistance you can provide! I'm very close to getting this but just need a little assistance to bring it across the finish line. 

1 comment
Spot On Innovative Approach Stellar Advice

Hi Brad Powers

You can fetch the task ID from the response of the POST request when you create those 24 tasks:

Next, to attach files from the local stage to the tasks, please try this cURL request:

curl --location --request POST '{taskID}/attachments' \
--header 'X-File-Name: Link to you attachment' \
--header 'Authorization: Bearer your_token'

The attachment will be added as a comment to the task.
Please make sure the 'X-File-Name' header is added and contains the link to the file on your computer. Here is an example of my request:

If the file you are looking to add is located in cloud storage, then you can add a link to that file by updating the task description.

Let me know if you have any additional questions!🙌

Lisa K. Community Team at Wrike Become a Wrike expert with Wrike Discover

Comment actions Permalink

Folllowing List for Post: Add attachments to tasks with API
[this list is visible for admins and agents only]

Didn’t find what you were looking for? Write new post