3

I am trying to consume sales force rest api service in my application.At that time,i am getting this exception "exception": "instance.salesforce.com".

Please observe my source code

String orgLimitUrl           = "https://instance.salesforce.com/services/data/v29.0/limits/"

DefaultHttpClient httpClient = new DefaultHttpClient()
HttpGet getRequest           = new HttpGet(orgLimitUrl)

getRequest.addHeader("Authorization", "Bearer " + accessToken )
getRequest.addHeader("X-PrettyPrint", "1" )

HttpResponse response = httpClient.execute(getRequest)

if (response.getStatusLine().getStatusCode() != 200) {
    throw new RuntimeException("Failed : HTTP error code : "+ response.getStatusLine().getStatusCode());
}

BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())))

while ((orgLimitLine = br.readLine()) != null) {
    orgLimisList.append(orgLimitLine)
}

httpClient.getConnectionManager().shutdown()

Please help me.

Thanks Anuradha

3

DO NOT hard code the Salesforce instance.

Salesforce Instance is retrieved when we get access token. In response to login.salesforce.com it provides a json containing accesstoken, instance_url etc. which looks like:

{
"id":"https://login.salesforce.com/id/00D90000000jXtlEAE/00590000001LjyRAAS",
"issued_at":"1392529622903",
"token_type":"Bearer",
"instance_url":"https://eu2.salesforce.com",
"signature":"acwHCJ9BeQczNFFBIk3dV2O8O2fGzkgWq4H8z4zzuZI=",
"access_token":"00D90000000jXtl!AQYAQGaorn7i0658sX6p8v.02OiuSJTcl6GXoi3Y92V1to2DVySlLl0XljgeEgF7aIgazQ.40TeMdoh3gMYFdH4Wl5JUhOBE"
}

Use that instance_url + /services/data/v29.0/limits/ or any other query path

| improve this answer | |
  • Hi regal,I did according to you told.Its working fine.Thank you so much for helping – Anuradha Feb 17 '14 at 13:43
2

You have "https://instance.salesforce.com/services/data/v29.0/limits/" as your URL, but there is no such host as instance.salesforce.com, you need to substitute in your real instance name e.g. "https://na13.salesforce.com/services/data/v29.0/limits/" for your API request. If you login via the UI you can see what your instance is there, or if you got your access token via OAuth, the OAuth result also includes it.

| improve this answer | |
0

Check your endpoint URL. If there is authentication problem, you'll get login exception. See if other integrations in your org are working or if the same exception is thrown. You can contact salesforce support if you can't debug the problem.

| improve this answer | |
  • yes this is only whole error message. – Anuradha Feb 15 '14 at 9:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.