Salesforce rest api INVALID_SESSION_ID error

I am using the salesforce rest api to access the salesforce account from my rails application. I created a remote access application and got the key N id. I was able to authenticate the user and get auth_token, instance url and all that. But when I send a request to "instance_url / services / data / v20.0" along with the access token, I get this error:

[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]

I have a Salesforce account for developers and the API is enabled for all profiles except the Authenticated Site profile (which is not available).

Please help me with this?

I check the user with the following query

HTTParty.post "login.salesforce.com/services/oauth2/token";, :body=>{"grant_type"=>"authorization_code","code"=>"abc}","client_secret"=>"abc"‌​, "client_id"=>"abc","format"=>"json","redirect_uri"=>"localhost:3000/salesforce/callback";}

which returns the signature, id, instance_url, issu_at, access_token and refresh_token

HTTParty.get "ap1.salesforce.com/services/data/v20.0";, :headers=>{"Authentication"=>"OAuth access_token", "Content-Type"=>"application/json"}

which answers

[{"errorCode"=>"INVALID_SESSION_ID", "message"=>"Session expired or invalid"}]
+5
7

sessionId /services/data/v 20.0?, access_token abc123, http Authorization: OAuth abc123 .

+9

API Salesforce , - . a > > > a >

- 8 .

!

+2

, < > .

0

, . , access_token, JSON login.salesforce.com/services/oauth2/token.

ID access_token, SalesForce: " "

0

, , Lock sessions to the IP address from which they originated Salesforce, , . Salesforce KB:


" IP-, ", API Salesforce REST OAuth2, INVALID_SESSION_ID, Apex.


" IP-, " , IP- . API REST IP-, INVALID_SESSION_ID , .

, IP ( Summer '15):

  1. " IP-, ",
  2. " IP- ",
  3. IP " IP"
  4. Add the Salesforce internal IP range from 10.0.0.0 to 10.255.255.255 to the list of profiles for which you must use the Salesforce REST API.

or just loosen the IP restrictions:

  1. Turn off the "Block sessions to the IP address from which they came" option, and
  2. Select the IP Relaxation Policy of the connected IP Address Restrictions application
0
source

All Articles