I am trying to build an utility to bulk publish documents through apex HTTPCallout. I dont want to read individual files from some visualforce page as this not feasible for bulk publishes. Rather want to be able to just provide URL and the files get sent through HTTPCallout. I tried this with Postman for one single document and it did work. Just trying to put the same but for mulitple documents in an apex code. Kindly suggest.
public void publish(){
if(UserInfo.getSessionId() != null) {
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('https://ignore.domainname.com/api/v17.2/objects/documents');
req.setMethod('POST');
req.setHeader('Content-Type', 'multipart/form-data');
req.setTimeout((Integer) settings.My_Timeout_MVN__c);
req.setHeader('Authorization', '5F055E6F00EA0JHKH98Y8989');
String body = 'file= C:\\ignore\\ignore\\Downloads\\my sample document.docx'
+'& type__v = type1'
+'& subtype__v = Subtype1'
+'& classification__v = classification1'
+'& name__v = Document from Utility'
+'& summary__c = Summary of Doc'
+'& country__v = belgium'
+'& for_verbal_use_only__c = true'
+'& document_category__c = Doc cat 2';Doc';
req.setBody(body);
req.setHeader('Accept', 'application/json');
try {
HttpResponse res = h.send(req);
System.debug(res.getBody());
}catch(Exception e) {
System.debug(e);
ApexPages.addMessages(e);
}
}
}