Create Wrike Attachment using API

We are trying to create an attachment under the project using the Wrike API, attachment is getting created inside the Wrike system but not able to see the content of the doc. We are sending an API request from salesforce to Wrike. We have different content-type of files inside the salesforce system.
Please help me with how we can store the correct file with the correct content type.
Sample code:-
String token='*****************************************************************************';
String endpointFolder='https://www.wrike.com/api/v4/folders/******************/attachments';
String fileName='https://test--wrike.my.salesforce.com/sfc/servlet.shepherd/document/download/06917000001BabcAAC?operationContext=S1';
HttpRequest req = new HttpRequest();
req.setEndpoint(endpointFolder);
req.setHeader('Authorization', 'bearer '+token);
req.setHeader('X-File-Name', fileName);
req.setHeader('Content-Type', 'application/octet-stream');
req.setHeader('X-Requested-With', 'XMLHttpRequest');
req.setHeader('data-binary', 'XMLHttpRequest');
req.setMethod('POST');
Http http = new Http();
HTTPResponse res = http.send(req);
System.debug('res-->'+res.getBody());

0
2 comments
Spot On Innovative Approach Stellar Advice
Avatar

I am able to fix the issues.
we need to specify the name and type extension in "X-File-Name"
Example:- X-File-Name: your file name+'.'+ file extension. 
Along with this, we need to send the blob in the body.
Sample code:-
String endpointFolder=TASK_ATTACHMENTS_ENDPOINT+taskID+'/attachments';
HttpRequest req = new HttpRequest();
req.setEndpoint(endpointFolder);
req.setHeader('Authorization', 'bearer '+TOKEN);
req.setHeader('X-File-Name', conVerData.Title+'.'+conVerData.FileExtension);
req.setHeader('Content-Type', 'application/octet-stream');
req.setHeader('X-Requested-With', 'XMLHttpRequest');
req.setBodyAsBlob(conVerData.VersionData);
req.setMethod('POST');
Http http = new Http();
HTTPResponse res = http.send(req);

1
Comment actions Permalink
Spot On Innovative Approach Stellar Advice
Avatar

Hello Gaurav Kumar, welcome to the Community 👋🏻

I see that you're in touch with our Support team regarding this question. Please let me know if I can help with anything else 🙋🏻‍♀️

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

Cansu Wrike Team member Become a Wrike expert with Wrike Discover

0
Comment actions Permalink

Folllowing List for Post: Create Wrike Attachment using API
[this list is visible for admins and agents only]

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