[SalesForce] Get the session id and Access token using curl php

I want to get my current session id and Access token in salesforce , Im using curl with php how to I get,

i Dont know how to get it ,,,

if anyone Knows tell me

Thanks ,
Ganesh

Best Answer

The easiest way to accomplish that would be with the REST API using SessionID Authorization (as opposed to Oauth).

To do this, first you need to create a "Connected App" in your salesforce instance. You can do that here: https://login.salesforce.com/app/mgmt/forceconnectedapps/forceAppEdit.apexp.

Then once you've got your connected app setup, you'll want to copy the consumer_key and consumer_secret that Salesforce generates for you and use it in the following curl command:

curl https://login.salesforce.com/services/oauth2/token -d "grant_type=password" -d "client_id=your_consumer_key" -d "client_secret=your_consumer_secret" -d "username=your_username" -d "password=your_password_plus_security_token"

If all goes well, you'll get back a response that looks something like this:

{"id":"https://login.salesforce.com/id/00D000000000abCDEF/00500000000gHIJQK2","issued_at":"1375515717557","instance_url":"https://na1.salesforce.com","signature":"X26l4MggO2go16d6bXo+YHhWUN+LWLSnwzc/0ap0x3A=","access_token":"00D000000000abCDEF!AQEAGJwlyvPbNQtRkLv1vDUIwkGaaG4l9oiQMeVNnopHcuDOrGkAT59s1c_zdlLNd_itHXZZai_Bq4L.uVqIjpJMHeiBzQF2"}

where "access_token" is your sessionId

You can find more information here under the heading "Session ID Authorization": http://www.salesforce.com/us/developer/docs/api_rest/Content/quickstart_oauth.htm