Global API
Requests
Upload File
2min
when using the upload file request, use requestjson to pass the required file details the response will have responsejson, which stores the file response returned by netsuite this action will upload the file into the given file cabinet's folder note netsuite has a 500k limitation for uploaded files however, this can be overcome by using contenturl this passes a url link to the file, rather than the file itself the file object has the following parameters field name data type description caption string pass the file name content blob pass the blob content in the base64encode format contenturl string public url of the content folder lookuprecord internal id of the folder name string provide the file name with the extension like test pdf the following is an example of uploading the opportunity's attachment as a file to netsuite request blob contentdata; id currentoppid = \[select id, name from opportunity where id='\[your opportunity id]' limit 1] id; for (contentdocumentlink doclinks \[select id, contentdocumentid from contentdocumentlink where linkedentityid = \ currentoppid limit 1]) { for (contentdocument docs \[select id, filetype, title, fileextension from contentdocument where id= \ doclinks contentdocumentid]) { for (contentversion docversion \[select id, versiondata from contentversion where contentdocumentid =\ doclinks contentdocumentid ]) { contentdata = docversion versiondata; } } } map\<string, object> nsfile = new map\<string, object>(); nsfile put('caption', 'test'); nsfile put('content', encodingutil base64encode(contentdata)); nsfile put('folder', new map\<string, object>{'internalid'=>'800'}); nsfile put('name', 'test pdf'); // initialize the requestjson data to be passed map\<string, object> requestjsonmap = new map\<string, object>(); requestjsonmap put('files', new list\<object>{nsfile}); string reqjson = json serialize(requestjsonmap); map\<string, object> reqobj = new map\<string, object>(); reqobj put('version', '1 0'); reqobj put('action', 'uploadfile'); reqobj put('requestjson', reqjson); // place a request to breadwinner global api map\<string, object> resp = breadwinner ns breadwinnernetsuiteapi call(reqobj); system debug(resp); response { action=uploadfile, responsejson={ "fileinternalid" "1776", "errors" \[], "status" "200" }, timestamp=1682316853154, validrequest=true, version=1 0 } the following is an example of uploading a url as a file to netsuite request map\<string, object> nsfile = new map\<string, object>(); nsfile put('caption', 'test'); nsfile put('contenturl', 'https //resources docs salesforce com/latest/latest/en us/sfdc/pdf/basics pdf'); nsfile put('folder', new map\<string, object>{'internalid'=>'800'}); nsfile put('name', 'test pdf'); // initialize the requestjson data to be passed map\<string, object> requestjsonmap = new map\<string, object>(); requestjsonmap put('files', new list\<object>{nsfile}); string reqjson = json serialize(requestjsonmap); map\<string, object> reqobj = new map\<string, object>(); reqobj put('version', '1 0'); reqobj put('action', 'uploadfile'); reqobj put('requestjson', reqjson); // place a request to breadwinner global api map\<string, object> resp = breadwinner ns breadwinnernetsuiteapi call(reqobj); system debug(resp); response { action=uploadfile, responsejson={ "fileinternalid" "1876", "errors" \[], "status" "200" }, timestamp=1682327380844, validrequest=true, version=1 0 }