Let's see how you can get an access token from Salesforce to access the Salesforce API's.
- Create a developer account for Salesforce in https://developer.salesforce.com/signup
- Navigate to Setup ➤ Create ➤ Apps, and in the Connected Apps section, click New to create a new connected app.
- To create a new app, you have fill the basic information as follow and then click Enable OAuth Settings to open the API section. In Enable OAuth Settings, you have to add the scope and need to put the callback as follow and save the configurations.
- Once you save the configurations, you can see your Consumer Key and under API (Enable OAuth Settings).
- Then copy the following URL and paste it into a web browser URL bar and you have to replace the <your_client_id> and <your_redirect_uri> with the created app values.
- Then you need to approve the application to access your salesforce account. On successful authorization, the user's browser will redirect back to the redirect URI (Call back URL) at the client application, with a URL of the form:
From the above redirect URL, extract the authorization code and send a direct POST request to the authorization server with the following request with the relevant values of your created app.
In above you can set format as urlencoded, json or xml to get the response with the specified format.
- From the above response, you can get the accessToken to access the salesforce organization via the created app and refreshToken to refresh the accessToken when it will be expired.