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
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
Действия с комментариями Постоянная ссылка
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 Узнайте о самых популярных функциях Wrike и советах по его использованию

Cansu Wrike Team member Узнайте о самых популярных функциях Wrike и советах по его использованию

0
Действия с комментариями Постоянная ссылка

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

Вверх
Didn’t find what you were looking for? Write new post