Skip to main content
Question

Custom Integration with Salesforce

  • May 22, 2025
  • 2 replies
  • 25 views

Forum|alt.badge.img

I am trying to upload a file to Box using following apex method.

public static String uploadBoxSample(){

/* endpoint by named credential */
HttpRequest request = new HttpRequest();
request.setHeader('Content-Type','multipart/form-data');
request.setMethod('POST');
String endpoint = 'callout:uploadBox/api/2.0/files/content';
request.setEndpoint(endpoint);

BodyJson body = new BodyJson ();
body.attributes.content_created_at ='';
body.attributes.content_modified_at ='';
body.attributes.name = 'testTextFile.txt';
body.attributes.parent.id = '0'; // parent should be object
body.file = 'test file content';

String strBody = System.JSON.serialize(body);
request.setBody(strBody);
Http http = new Http();
HttpResponse response = http.send(request);
System.debug('response body ' + response.getBody());

return null;
}
public class BodyJson {
Attributes attributes;
String file;
public BodyJson(){
attributes = new Attributes();
}
}
public class Attributes {
public String content_created_at;
public String content_modified_at;
public String name;
public parent parent;
public Attributes(){
parent = new parent();
}
}
public class parent {
public String id;
}

I got following error.

code : bad_request, status : 400, message : the request was rejected because no multipart boundary was found

Thanks for any solution.

2 replies

Forum|alt.badge.img

after adding boundary to header, this error is clear.

String boundary = '--------------------------test 388d840fef1';
request.setHeader('Content-Type','multipart/form-data; boundary=' + boundary);

 


Forum|alt.badge.img

Hey Lin, 

Yes you have to add a boundary to the call. Did you get around the size limitations? 

Thanks, 

Alex, Box Developer Advocate