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. 

0
👍 Spot On 💡 Innovative Approach 💪 Stellar Advice ✅ Solved 🪄 Remove Kudos
6 comments

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 'https://www.wrike.com/api/v4/tasks/{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 Wrike Product Manager Become a Wrike expert with Wrike Discover

Lisa K. Wrike Team member Become a Wrike expert with Wrike Discover

0
👍 Spot On 💡 Innovative Approach 💪 Stellar Advice ✅ Solved 🪄 Remove Kudos

Hi Lisa K,

I try to following your step on Postman, but the file appears to be invalid or broken on wrike ticket. Please see image bellow :

What should I do ?

 

0
👍 Spot On 💡 Innovative Approach 💪 Stellar Advice ✅ Solved 🪄 Remove Kudos

Hi Brad Powers and Agus Mahendra, let me elaborate a little bit more on the API request.
@Augus, I'm sorry to hear about the issue with opening the attachment. Have you included the file in the request Body? Please choose the binary format and select the file from the local storage, otherwise, an empty attachment is added to Wrike:

Also, please note that apart from the 'X-File-Name' Header the example Request on Wrike Developers portal has two other additional Headers: 'content-type: application/octet-stream' and 'X-Requested-With: XMLHttpRequest'. The request works without them in my Postman environment, but please add those to make sure all is set according to the recommendations.
If needed, please check this cURL example below:

Hope it helps!😉

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

Lisa K. Wrike Team member Become a Wrike expert with Wrike Discover

1
👍 Spot On 💡 Innovative Approach 💪 Stellar Advice ✅ Solved 🪄 Remove Kudos

Thank you Lisa K, is working properly now.

1
👍 Spot On 💡 Innovative Approach 💪 Stellar Advice ✅ Solved 🪄 Remove Kudos

I'm looking to do something similar, but would like to attach files from a download link from a cloud service.  I've tried creating an attachment, and then updating the attachment with a POST url that is a download link, but this just creates a new version of the attachment, and I get the "invalid/broken" error above.  Any further elaboration on how to post an attachment from a download link would be greatly appreciated.  I'm a bit of a newcomer to Wrike, and integration development in general, so your patients is appreciated.  Lisa-K

0
👍 Spot On 💡 Innovative Approach 💪 Stellar Advice ✅ Solved 🪄 Remove Kudos

Hey Matt Keyes, I've asked our API experts from the Support team to reach out to you about your question 👍 

Please let me know if there's anything else we can help you with 🙂

Lisa Community Team at Wrike Wrike Product Manager Become a Wrike expert with Wrike Discover

Lisa Wrike Team member Become a Wrike expert with Wrike Discover

0
👍 Spot On 💡 Innovative Approach 💪 Stellar Advice ✅ Solved 🪄 Remove Kudos

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

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