function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Andre Baxter 7Andre Baxter 7 

Error received: {“document”:[“The submitted data was not a file. Check the encoding type on the form.”],“status_code”:400}



I'm trying to do a POST call to SBA from Salesforce that involves uploading a file. The call asks for 4 parameters in the form of JSON. As I have tested, 3 of the 4 JSON fields are passing validation on the other end. However, when I use the VersionData(Blob) field on the ContentVersion, the error in the title is returned. I have also tried using PathOnClient(String) as the value, but receive the same error.

Perhaps there is another field on the ContentVersion object that I should be passing in to represent the file? Or maybe there is another object I should be using to retrieve the file and utilize it in Apex? My sandbox is fairly new so the Attachment object unfortunately doesn't retrieve any files via SOQL. My code is below:

public static void makeCallOutForUpload(){
    
    //query for File
ContentVersion file = [SELECT Title, PathOnClient, VersionData FROM ContentVersion WHERE ContentDocumentId = '0693J0000007rltQAA' AND IsLatest = true];
    
    
    //sample request for upload doc callout
    String jsonstring = '{'
                       +'"name": "delete these todos.csv",'
                       +'"document": "'+file.VersionData+'",'
                       +'"document_type": "1",'
                       +'"etran_loan": "7ab138f3-7507-47f9-a330-1a2c0b4e4f73"'
                       + '}';
  
    HttpResponse response;
    ETranDetails__c etranDetails = ETranDetails__c.getOrgDefaults();
    
    //call out logic here
    Http http = new Http();
    HttpRequest request = new HttpRequest();
    request.setHeader('Authorization', etranDetails.API_Key__c);
    request.setHeader('Vendor-Key', etranDetails.Vendor_Key__c);
    request.setHeader('Content-Type', 'application/json');
    request.setEndpoint(etranDetails.Forgiveness_Endpoint_For_Upload_Docs__c);
    request.setMethod('POST');
    request.setTimeout(120000);
    request.setBody(jsonstring);
    response = http.send(request);
    
    system.debug('what came back?'+response.getStatusCode()+' '+response.getBody());
    
}