function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Abilash Kosigi 8Abilash Kosigi 8 

Requesting OAuth Token from Curl (Rest API)

Hi,

I am new to REST API. I would like to send Http Requests from Curl software that I installed on my desktop.
How to request OAuth token from command prompt using Curl.(I have done extensive search on google - could not find any reliable answer). 

What is the callback URL that I should give in Salesforce dev edition.

Please help
logontokartiklogontokartik
Since you cannot really do three legged oauth with CURL, you need to use Username-password flow to get access token,   please see below

For the callback URL you can use something like http://test or http://localhost.

https://developer.salesforce.com/page/Digging_Deeper_into_OAuth_2.0_on_Force.com#Obtaining_a_Token_in_an_Autonomous_Client_.28Username_and_Password_Flow.29




Grazitti TeamGrazitti Team
Hi Abhilash,

Try using the below cURL command :

curl -k https://login.salesforce.com/services/oauth2/token -d "grant_type=password" -d "client_id=[clientid]" -d "client_secret=[clientsecret]" -d "username=[myusername]" -d "password=[mypassword][mysecuritytoken]"

It will return you the access token.

Mark it as Best Answer, if it helps you

Regards,
Grazitti Team
www.grazitti.com
Abilash Kosigi 8Abilash Kosigi 8
Hi Grazitti,

I am getting the following error when I am trying cURL Command that you mentioned.

{"error":"invalid_grant","error_description":"authentication failure"}

Please help.
Grazitti TeamGrazitti Team
Just make sure you are using correct clientId, client_secret, username and password. Also, if you are doing it on sandbox your url should be https://test.salesforce.com/services/oauth2/token
Abilash Kosigi 8Abilash Kosigi 8
Unfortunately I am still facing the same issue :(

Grazitti TeamGrazitti Team
Its working fine on our end.

Also, Just make sure that you are entering proper combination of Password and Security Token.

If you still face the same issue send us the cUrl command you are hitting as well as the error genarated.
Sanjay SubramanianSanjay Subramanian
I am facing the same issue as Abilash.
See my post here (scroll to the bottom)
https://developer.salesforce.com/forums/ForumsMain?id=906F00000009CYaIAM
 
Sanjay SubramanianSanjay Subramanian
Anyone with ant thoughts or ideas that could help ?