0 votes
1 view
in Salesforce by (11.9k points)

I am using salesforce rest API to access the salesforce account from my rails app.I created a remote access app and got the key N the id. I was able to authenticate the user and get the auth_token, instance URL and all that. But, when I send a request at "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 developer salesforce account and have API enabled true for every profile, except for the "Authenticated website" profile(which is not accessible).

Please, can anybody help me with this?

I'm authenticating the user with the following request

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 is returning signature, id, instance_url, issued_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 responds with
[{"errorCode"=>"INVALID_SESSION_ID", "message"=>"Session expired or invalid"}]

1 Answer

0 votes
by (31.8k points)

You can't pass the sessionId to the /services/data/v20.0 request. 

If your access_token is abc123 then you need an HTTP header of Authorization: OAuth abc123 in your request.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...