Experience Salesforce
REST API Part 3
What You’ll Learn
- Authorizing Salesforce From Postman
- Generating Access Token
- Calling Salesforce API Using Access Token
Topics
- APIs in Salesforce
- Need of API in Salesforce
- Languages Used in creating APIs
- How Communication Happens in APIs
- Types of APIs in Salesforce
- REST API Part 1
- REST API Part 2
- REST API Part 3
- REST API Part 4
- REST API Part 5
- REST API Part 6
- REST API Part 7
- REST API Part 8
- REST API Part 9
- SOAP API Part 1
- SOAP API Part 2
- SOAP API Part 3
- SOAP API Part 4
- SOAP API Part 5
- Metadata API in Salesforce
Authorizing Salesforce From Postman
Set up OAuth 2.0:
In Salesforce, from Setup, enter Apps in the Quick Find box, then select Apps, and under Connected Apps click New to create a new connected app.Â
We have to use this connected app because Apex REST Service inside salesforce cannot be accessed directly so it needs a link to be connected we have to use the connected appÂ
- Give the connected app any name.
- Check on the Enable OAuth Settings.
- The Callback URL you supply here is the same as your Web application’s callback URL. In this case, as we are sending a request through Postman the callback URL must be of Postman. Give this URL, https://www.getpostman.com/oauth2/callback, as a callback URL.
- In the OAuth scope give it full access and click on save.
As you click on save you will get two more parameters that are used in this process of authentication that is Consumer Key and Consumer Secret.Â
Generating Access Token
Now In Postman, we have to generate an access token that can be used for calling out the service. Access token defines that we have used proper credentials to login into the account and we can proceed further.
So to generate an access token follow these steps:
- Open Postman
- Set Method to PostÂ
- Set the method URL to https://login.salesforce.com/services/oauth2/token
- In Body define these parameters
- grant_type = passwordÂ
- client_id = Consumer KeyÂ
- client_secret = Consumer SecretÂ
- username = your Salesforce Account usernameÂ
- password = password+security_tokenÂ
After applying these steps click on Send button and as a result, an Access token and your instance URL is generated so save it for future reference.Â
Calling Salesforce API Using Access Token
The access token that is generated is used in REST Request to call the web service so to call the service the URL is the same as the URL mapping of Apex-Service for example: “https://instance_name.salesforce.com/services/apexrest/URLMapping”
Provide your instance name and use this URL to reach out to your APEX REST Service.
Now in the header part provide the access token and content type.Â
Authorization: Bearer “your access token” Content-type: application/json |
{“First Name”: “testing”, “Last Name”: “Leads”, “Company”: “XYZ Company”} |
Need Extra Support? Our FREE study materials have got you covered.
Our expert-prepared study materials provide the answers you need. Clear your doubts and improve your skills with detailed notes from industry professionals.