Forum Discussion

Suchith's avatar
6 years ago

Endpoint Access error in Production.

Hi,

I have created an endpoint in staging to Access Salesforce Access token. Endpoint works fine when I make a request through community staging, but its throwing an error when I tried to access from community production.

End point Code:

 

 

<#assign response = http.client.request("https", "login.salesforce.com", "/services/oauth2/token").body("grant_type=password&client_id=<clientid>&client_secret=<ClientSecret>&username=<username>&password=<password>", "application/x-www-form-urlencoded").post()/>
<#if response.hasError>
ERROR
<#else>
${response.content}
</#if>

 

 

 

Staging Output:

 

 

{"access_token":"<AccessToken>","instance_url":"<Instance_url>","id":"<ID>","token_type":"Bearer","issued_at":"<Issued_at>","signature":"<Signature>"}

 

 

 

Production Output:
1) Firefox:

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

2)Advanced Rest Client

There was an error parsing JSON data

Unexpected token E in JSON at position 0

I have checked the Login History on salesforce and couln't able to find one for community production.

Thanks

 

  • Hi Suchith ,

    it could be that you have not whitelisted the HTTP client domain.

    You have to whitelist the caller domain for the http client here:
    ADMIN DASHBOARD > SYSTEM > HTTP Client

    Here you will find an input field called "Allowed domain names", where you can enter the http client domain.

    Hope this helps.

3 Replies

  • AdamN's avatar
    AdamN
    Khoros Oracle
    6 years ago

    Hi Suchith ,

    The error you're seeing seems to be from the fact that the error message your endpoint is returning is not formatted for JSON. You might try replacing "ERROR" with something like the following in order to at least alleviate that issue:

    {"status":"error"}

    The real issue though is to figure out why it's getting to that error condition in the first place. One thing that could help you determine this is to take advantage of response.error.message context object to give you more details as to why the call is failing. You could even include this as part of your error response from your endpoint, for example:

    {"status":"error","message":"${response.error.message?json_string}"}

    See here for more details on this context object:

    https://community.khoros.com/t5/Developer-Documentation/bd-p/dev-doc-portal?section=freemarker#l::%7B%22p%22:%22%2Frefer%2FcontextObjects%22,%22h%22:%22%23httpClientResponse%22%7D 

    I hope this helps!

  • Suchith's avatar
    Suchith
    Ace
    6 years ago

    Hi AdamN,

    I have updated the return type of webservice from plain text to JSON and I got the below error message.

    http request not allowed: http client not allowed: hostname-allowed-domains-list-empty

    I am not sure why I am receiving this error message only on production when its works fine on staging.

    Thanks,

  • STARFLEET's avatar
    STARFLEET
    Expert
    6 years ago

    Hi Suchith ,

    it could be that you have not whitelisted the HTTP client domain.

    You have to whitelist the caller domain for the http client here:
    ADMIN DASHBOARD > SYSTEM > HTTP Client

    Here you will find an input field called "Allowed domain names", where you can enter the http client domain.

    Hope this helps.