Sunday, November 22, 2015

Generating Access Token for Connected App using CURL

When you have designed a REST API using apex, to provide the authentication to the requester we will be creating a Connected App in salesforce .In this post we will being learning how to create a Connected App and how to get the AcccessToken using the CURL.

Creating the Connected App 

1.Goto Setup--> Create --> App--> click on Connected Apps (as shown as below)

2. Fill all the manadtory fields(Connected App Name,Contact Email) as heigligted as below image

3. For authentication purpose we are using here OAuth .So,click on Enable OAuth Settings checkbox 

    i) Fill the CallBack URL with below values based on instance
         Prod or Developer Edition =
         For Sandboxes                   =

  ii)In Selected OAuth Scopes section move Full access(full) value from Available OAuth Scopes to Selected OAuth Scopes (Plz refer the below image for more info)

4.Click on Save and your connected app would populate with Consumer Key and Consumer Secret as heightened in the below image

Getting the Access Token using the CURL

Testing RESTful webservices on Windows can be done outside of the browser using an open source command tool called cURL. can download the CURL from the below link based on your operating systems.
     a)  CURL download link
     b)  For Windows 32 bit (safer choice)
     c)  For Window 64 bit

2. For windows download Zip file from the above mention links (b and c).

3. Extract the zip file copy the curl.exe file and paste in the c:\windows\system32

4. Installation of CURL is finished.

5. To test the installation execute the command as given in image

Syntax to get the Access Token 

1.Open command promt and execute the below command

 curl --form client_id=<Your client id/Consumer Key>  --form client_secret=<Your Secret ID/Consumer Secret> --form grant_type=password --form username=<Your User Name>  --form password=<Your Password+SecurityToken> -k https://<Your Domain/Instance Name>


curl --form client_id=3MVG9Y6d_Btp4xp7.7cBQRNzmybjPJDdJ8B1jneA51uSo_o_5Vwkz --form client_secret=596012939950 --form grant_type=password --form --form password=ilovecodeYlM4IQZjX1TiDAW -k

If command is successfully executed you will receive below response with Access Token


Thanks for visiting...Enjoy........