Skip to main content
I am trying to call rest API using Httprequest (from salesforce using Apex code), but not able to figure how I can pass the body.  I would appreciate if anyone share the way to pass the below mentioned body in the HttpRequest.

 

 

 

here are the details:

 

End-point URL : https://api.boomi.com/api/rest/v1/AccountID/EnvironmentExtensions/XXXXXXXXXX

 

 

 

Body:

 

 

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

 

<bns:EnvironmentExtensions xmlns:bns="http://api.platform.boomi.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="XXXXXXXXXXXXXXXX" extensionGroupId="" environmentId="XXXXXXXXXXXXXXX">

 

    <bns:connections>

 

        <bns:connection name="SFDC connection" id="XXXX">

 

            <bns:field componentOverride="false" usesEncryption="false" encryptedValueSet="false" value="email@gmail.com" id="user"/>

 

            <bns:field componentOverride="false" usesEncryption="true" encryptedValueSet="true" id="password" value="password"/>

 

        </bns:connection>

 

    </bns:connections>

 

</bns:EnvironmentExtensions>

 

 

 

 

 

Apex code to call Rest API:

 

 

 

 

 

      String endPointURL = 'https://api.boomi.com/api/rest/v1/AccountID/EnvironmentExtensions/XXXXXXXXXX';

 

     

 

      String userName = 'XXXXXX';

 

      String password = 'XXXXXXX';

 

 

 

      String body= '';

 

      String query;

 

      query = '';

 

      Blob headerValue = Blob.valueOf(userName + ':' + password);

 

      String authorizationHeader = 'BASIC ' +

 

      EncodingUtil.base64Encode(headerValue);

 

      accs1 = new List<cAccount>();

 

      Httprequest request = new HttpRequest();

 

      Http http = new Http();

 

      request.setMethod('POST');

 

      request.setEndpoint(endPointURL);

 

      request.setHeader('Content-Type', 'application/json');

 

      // Header info with remote server user name and password

 

      request.setHeader('Authorization', authorizationHeader);

 

      request.setBody(query);

 

           

 

      request.setTimeout(120000);

 

      request.setBody(query);         

 

      //Making call to external REST API

 

      HttpResponse response = http.send(request); 

 

      System.debug('responseBody: '+response.getBody());
5 respostas
  1. 20 de mai. de 2016, 08:54
    This Answers Community is focused on configuration and design questions. 

     

     

     

    Any questions related to REST, API's  are best submitted at the developer forums

     

    You ETA will be Quick in those Forums

     

     

     

    Please use below links 

     

    https://developer.salesforce.com/forums/#!/feedtype=RECENT&criteria=ALLQUESTIONS

     

    http://salesforce.stackexchange.com/

     

    Hope this helps,

     

     If it does, please mark as best answer.

     

    Kind Regards,

     

    Jaya

     

     
0/9000