1

I have issue with posting an API header to Bright Pattern out of Developer Console using a workspace. below is the Code and when I send it I get an error:

Execute Anonymous Error on line 6 column:19 Unexpected token '('

It looks like there is an Problem with the opening bracket after the request.setHeader. However, it looks okay to me.

Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://sprout.brightpattern.com/clientweb/api/v1/chats?tenantUrl=sprout.brightpattern.com&timestamp=1538601898');
request.setMethod('POST');
// Set Header for the Authorization 
request.setHeader('Content-Type', 'application/json;charset=UTF-8';
  'Authorization: MOBILE-API-140-327-PLAIN'+ appId=9aeb0234a + clientId=WebChat);
// Set the body as a JSON object
request.setBody('{"LeadId":"00QM000000FL93tMAD"}');
// Parse the JSON response
HttpResponse response = http.send(request);
if (response.getStatusCode() != 201) {
    System.debug('The status code returned was not expected: ' +
        response.getStatusCode() + ' ' + response.getStatus());
} else {
    System.debug(response.getBody());
}
2
  • You're missing the closing parentheses at the end of that line before the semi-colon: request.setHeader('Content-Type', 'application/json;charset=UTF-8');
    – sfdcfox
    Commented Oct 4, 2018 at 2:06
  • Note that I have removed the portion in appId=... which seemed to be some sort of token. It's recommended not to post any credentials on public forum.
    – Jayant Das
    Commented Oct 4, 2018 at 3:23

1 Answer 1

1

You seem to have couple of issues here those need to be corrected:

  1. Starting with this:

    request.setHeader('Content-Type', 'application/json;charset=UTF-8';
    

    Needs to be

    request.setHeader('Content-Type', 'application/json;charset=UTF-8');
    
  2. Then, not sure what is the appId=<> portion, but there seems to be something missing here too. I would imagine everything here should be part of the string itself and should be set in the header separately.

    'Authorization: MOBILE-API-140-327-PLAIN'+ appId=<>+ clientId=WebChat);
    

    Should be something as below:

    request.setHeader('Authorization: MOBILE-API-140-327-PLAIN everything else goes here');
    
  3. Then further below,

    request.setBody('{"LeadId":"00QM000000FL93tMAD"}');
    

    Should be as:

    request.setBody('{\"LeadId\":\"00QM000000FL93tMAD\"}');
    
7
  • thanks issue 1 is working with your changes when I do a Highlighted Execute from Developer Console. Commented Oct 4, 2018 at 17:27
  • You will need to verify what's the authorization expected and how should you pass it. It's usually provided by the service provider as what they expect.
    – Jayant Das
    Commented Oct 4, 2018 at 18:05
  • the problem is if I add the Authorization to the request.setHeader When I add Authorization I get Line: 6, Column: 9 Method does not exist or incorrect signature: void setHeader(String, String, String) from the type System.HttpRequest Commented Oct 4, 2018 at 21:29
  • here is how it looks Commented Oct 4, 2018 at 21:30
  • request.setHeader('Content-Type', 'application/json;charset=UTF-8', 'Authorization: MOBILE-API-140-327-PLAIN appId="########" clientId="#######"'); Commented Oct 4, 2018 at 21:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .