Skip to main content
added 319 characters in body
Source Link

I am trying to launch a callout call to an OCR from an Apex method using a secured named credential with an external credential.

The HTTP request is a POST request with multipart body containing a file. I am using this response to compose the multipart body.

Here a code sample I am using

    ContentDocument document = [SELECT LatestPublishedVersion.VersionData FROM ContentDocument WHERE Id = 'XXXXX'];
    Blob fileContent = document.LatestPublishedVersion.VersionData;
    String contentType = vNHttpFormBuilder.GetContentType();
    String form64 = '';
    form64 += vNHttpFormBuilder.WriteBoundary();
    vNHttpFormBuilder.WriteFileResult result = vNHttpFormBuilder.WriteFile('file', 'test File Name.pdf', 'pdf', fileContent);
    form64 += result.Content;
    form64 += vNHttpFormBuilder.WriteBoundary(result.EndingType);
    Blob formBlob = EncodingUtil.base64Decode(form64);
    String contentLength = String.valueOf(formBlob.size());
    HttpRequest req = new HttpRequest();
    req.setEndpoint('callout:TestCredential/api/publicapi/v1/transactions/launch?skillId=123');
    req.setMethod('POST');
    req.setHeader('Content-Type', contentType);
    req.setHeader('Connection', 'keep-alive');
    req.setHeader('Content-Length', contentLength);
    req.setTimeout(20000);

    req.setBodyAsBlob(formBlob);
    Http http = new Http();
    HttpResponse response = http.send(req);

But I keep getting this error when making the call. Origin of the error is the http.send method. enter image description here

Even though the call seems to work just fine when replacing the endpoint with. req.setEndpoint('https://vantage-eu.abbyy.com/api/publicapi/v1/transactions/launch?skillId=123');

PS: I have tried the named credential (the http call with 'callout:TestCredential') with a GET endpoint and it works fine.

I am suspecting that the script executed by Salesforce to inject the authentication token is failing due to some error with the blob body.

I am trying to launch a callout call to an OCR from an Apex method using a secured named credential with an external credential.

The HTTP request is a POST request with multipart body containing a file. I am using this response to compose the multipart body.

Here a code sample I am using

    ContentDocument document = [SELECT LatestPublishedVersion.VersionData FROM ContentDocument WHERE Id = 'XXXXX'];
    Blob fileContent = document.LatestPublishedVersion.VersionData;
    String contentType = vNHttpFormBuilder.GetContentType();
    String form64 = '';
    form64 += vNHttpFormBuilder.WriteBoundary();
    vNHttpFormBuilder.WriteFileResult result = vNHttpFormBuilder.WriteFile('file', 'test File Name.pdf', 'pdf', fileContent);
    form64 += result.Content;
    form64 += vNHttpFormBuilder.WriteBoundary(result.EndingType);
    Blob formBlob = EncodingUtil.base64Decode(form64);
    String contentLength = String.valueOf(formBlob.size());
    HttpRequest req = new HttpRequest();
    req.setEndpoint('callout:TestCredential/api/publicapi/v1/transactions/launch?skillId=123');
    req.setMethod('POST');
    req.setHeader('Content-Type', contentType);
    req.setHeader('Connection', 'keep-alive');
    req.setHeader('Content-Length', contentLength);
    req.setTimeout(20000);

    req.setBodyAsBlob(formBlob);
    Http http = new Http();
    HttpResponse response = http.send(req);

But I keep getting this error when making the call enter image description here

Even though the call seems to work just fine when replacing the endpoint with req.setEndpoint('https://vantage-eu.abbyy.com/api/publicapi/v1/transactions/launch?skillId=123');

I am trying to launch a callout call to an OCR from an Apex method using a secured named credential with an external credential.

The HTTP request is a POST request with multipart body containing a file. I am using this response to compose the multipart body.

Here a code sample I am using

    ContentDocument document = [SELECT LatestPublishedVersion.VersionData FROM ContentDocument WHERE Id = 'XXXXX'];
    Blob fileContent = document.LatestPublishedVersion.VersionData;
    String contentType = vNHttpFormBuilder.GetContentType();
    String form64 = '';
    form64 += vNHttpFormBuilder.WriteBoundary();
    vNHttpFormBuilder.WriteFileResult result = vNHttpFormBuilder.WriteFile('file', 'test File Name.pdf', 'pdf', fileContent);
    form64 += result.Content;
    form64 += vNHttpFormBuilder.WriteBoundary(result.EndingType);
    Blob formBlob = EncodingUtil.base64Decode(form64);
    String contentLength = String.valueOf(formBlob.size());
    HttpRequest req = new HttpRequest();
    req.setEndpoint('callout:TestCredential/api/publicapi/v1/transactions/launch?skillId=123');
    req.setMethod('POST');
    req.setHeader('Content-Type', contentType);
    req.setHeader('Connection', 'keep-alive');
    req.setHeader('Content-Length', contentLength);
    req.setTimeout(20000);

    req.setBodyAsBlob(formBlob);
    Http http = new Http();
    HttpResponse response = http.send(req);

But I keep getting this error when making the call. Origin of the error is the http.send method. enter image description here

Even though the call seems to work just fine when replacing the endpoint with. req.setEndpoint('https://vantage-eu.abbyy.com/api/publicapi/v1/transactions/launch?skillId=123');

PS: I have tried the named credential (the http call with 'callout:TestCredential') with a GET endpoint and it works fine.

I am suspecting that the script executed by Salesforce to inject the authentication token is failing due to some error with the blob body.

added 12 characters in body
Source Link

I am trying to launch a callout call to an OCR from an Apex method using a secured named credential with an external credential.

The HTTP request is a POST request with multipart body containing a file. I am using this response to (compose the multipart body)[https://salesforce.stackexchange.com/questions/132135/how-can-i-compose-a-multipart-form-data-request]compose the multipart body.

Here a code sample I am using

    ContentDocument document = [SELECT LatestPublishedVersion.VersionData FROM ContentDocument WHERE Id = 'XXXXX'];
    Blob fileContent = document.LatestPublishedVersion.VersionData;
    String contentType = vNHttpFormBuilder.GetContentType();
    String form64 = '';
    form64 += vNHttpFormBuilder.WriteBoundary();
    vNHttpFormBuilder.WriteFileResult result = vNHttpFormBuilder.WriteFile('file', 'test File Name.pdf', 'pdf', fileContent);
    form64 += result.Content;
    form64 += vNHttpFormBuilder.WriteBoundary(result.EndingType);
    Blob formBlob = EncodingUtil.base64Decode(form64);
    String contentLength = String.valueOf(formBlob.size());
    HttpRequest req = new HttpRequest();
    req.setEndpoint('callout:TestCredential/api/publicapi/v1/transactions/launch?skillId=123');
    req.setMethod('POST');
    req.setHeader('Content-Type', contentType);
    req.setHeader('Connection', 'keep-alive');
    req.setHeader('Content-Length', contentLength);
    req.setTimeout(20000);

    req.setBodyAsBlob(formBlob);
    Http http = new Http();
    HttpResponse response = http.send(req);

But I keep getting this error when making the call enter image description here

Even though the call seems to work just fine when replacing the endpoint with req.setEndpoint('https://vantage-eu.abbyy.com/api/publicapi/v1/transactions/launch?skillId=123');

I am trying to launch a callout call to an OCR from an Apex method using a secured named credential with an external credential.

The HTTP request is a POST request with multipart body containing a file. I am using this response to (compose the multipart body)[https://salesforce.stackexchange.com/questions/132135/how-can-i-compose-a-multipart-form-data-request].

Here a code sample I am using

    ContentDocument document = [SELECT LatestPublishedVersion.VersionData FROM ContentDocument WHERE Id = 'XXXXX'];
    Blob fileContent = document.LatestPublishedVersion.VersionData;
    String contentType = vNHttpFormBuilder.GetContentType();
    String form64 = '';
    form64 += vNHttpFormBuilder.WriteBoundary();
    vNHttpFormBuilder.WriteFileResult result = vNHttpFormBuilder.WriteFile('file', 'test File Name.pdf', 'pdf', fileContent);
    form64 += result.Content;
    form64 += vNHttpFormBuilder.WriteBoundary(result.EndingType);
    Blob formBlob = EncodingUtil.base64Decode(form64);
    String contentLength = String.valueOf(formBlob.size());
    HttpRequest req = new HttpRequest();
    req.setEndpoint('callout:TestCredential/api/publicapi/v1/transactions/launch?skillId=123');
    req.setMethod('POST');
    req.setHeader('Content-Type', contentType);
    req.setHeader('Connection', 'keep-alive');
    req.setHeader('Content-Length', contentLength);
    req.setTimeout(20000);

    req.setBodyAsBlob(formBlob);
    Http http = new Http();
    HttpResponse response = http.send(req);

But I keep getting this error when making the call enter image description here

Even though the call seems to work just fine when replacing the endpoint with req.setEndpoint('https://vantage-eu.abbyy.com/api/publicapi/v1/transactions/launch?skillId=123');

I am trying to launch a callout call to an OCR from an Apex method using a secured named credential with an external credential.

The HTTP request is a POST request with multipart body containing a file. I am using this response to compose the multipart body.

Here a code sample I am using

    ContentDocument document = [SELECT LatestPublishedVersion.VersionData FROM ContentDocument WHERE Id = 'XXXXX'];
    Blob fileContent = document.LatestPublishedVersion.VersionData;
    String contentType = vNHttpFormBuilder.GetContentType();
    String form64 = '';
    form64 += vNHttpFormBuilder.WriteBoundary();
    vNHttpFormBuilder.WriteFileResult result = vNHttpFormBuilder.WriteFile('file', 'test File Name.pdf', 'pdf', fileContent);
    form64 += result.Content;
    form64 += vNHttpFormBuilder.WriteBoundary(result.EndingType);
    Blob formBlob = EncodingUtil.base64Decode(form64);
    String contentLength = String.valueOf(formBlob.size());
    HttpRequest req = new HttpRequest();
    req.setEndpoint('callout:TestCredential/api/publicapi/v1/transactions/launch?skillId=123');
    req.setMethod('POST');
    req.setHeader('Content-Type', contentType);
    req.setHeader('Connection', 'keep-alive');
    req.setHeader('Content-Length', contentLength);
    req.setTimeout(20000);

    req.setBodyAsBlob(formBlob);
    Http http = new Http();
    HttpResponse response = http.send(req);

But I keep getting this error when making the call enter image description here

Even though the call seems to work just fine when replacing the endpoint with req.setEndpoint('https://vantage-eu.abbyy.com/api/publicapi/v1/transactions/launch?skillId=123');

Source Link

Callout named credential calls with a blob body

I am trying to launch a callout call to an OCR from an Apex method using a secured named credential with an external credential.

The HTTP request is a POST request with multipart body containing a file. I am using this response to (compose the multipart body)[https://salesforce.stackexchange.com/questions/132135/how-can-i-compose-a-multipart-form-data-request].

Here a code sample I am using

    ContentDocument document = [SELECT LatestPublishedVersion.VersionData FROM ContentDocument WHERE Id = 'XXXXX'];
    Blob fileContent = document.LatestPublishedVersion.VersionData;
    String contentType = vNHttpFormBuilder.GetContentType();
    String form64 = '';
    form64 += vNHttpFormBuilder.WriteBoundary();
    vNHttpFormBuilder.WriteFileResult result = vNHttpFormBuilder.WriteFile('file', 'test File Name.pdf', 'pdf', fileContent);
    form64 += result.Content;
    form64 += vNHttpFormBuilder.WriteBoundary(result.EndingType);
    Blob formBlob = EncodingUtil.base64Decode(form64);
    String contentLength = String.valueOf(formBlob.size());
    HttpRequest req = new HttpRequest();
    req.setEndpoint('callout:TestCredential/api/publicapi/v1/transactions/launch?skillId=123');
    req.setMethod('POST');
    req.setHeader('Content-Type', contentType);
    req.setHeader('Connection', 'keep-alive');
    req.setHeader('Content-Length', contentLength);
    req.setTimeout(20000);

    req.setBodyAsBlob(formBlob);
    Http http = new Http();
    HttpResponse response = http.send(req);

But I keep getting this error when making the call enter image description here

Even though the call seems to work just fine when replacing the endpoint with req.setEndpoint('https://vantage-eu.abbyy.com/api/publicapi/v1/transactions/launch?skillId=123');