I want to upload files from Salesforce to Box
How do I upload a file from Salesforce (Lightning Experience) to Box?
I get the error.
" FATAL_ERROR box.Toolkit.BoxApiException: box.Toolkit.sendRequest() - HttpRequest endpoint must start with: https://api.box.com/2.0 "
Can't I upload using BoxToolkit?
Here is the code snippet which is doing this.
---
@future (callout=true)
public static void uploadFile(String fileName, String recordId, Blob file) {
box.Toolkit boxToolkit = new box.Toolkit();
//getFolderId
String folderId = boxToolkit.getFolderIdByRecordId(recordId);
// setEndpoint
String endpoint = 'https://upload.box.com/api/2.0/files/content';
//setParameters
Map<String, String> parent = new Map<String, String>{
'id' => folderId
};
Map<String, Object> attributes = new Map<String, Object>{
'content_created_at' => null,
'content_modified_at' => null,
'name' => fileName,
'parent' => parent
};
Map<String, Object> body = new Map<String, Object>{
'attributes' => attributes,
'file' => file
};
HttpRequest request = new HttpRequest();
request.setMethod('POST');
request.setEndpoint(endpoint);
request.setBody(JSON.serialize(body));
request.setHeader('content-type', 'multipart/form-data');
// sendRequest
HttpResponse response = boxToolkit.sendRequest(request);
boxToolkit.commitChanges();
}
投稿コメントは受け付けていません。
コメント
0件のコメント