REST API provide a powerful and simple Web Services API for interacting with Force.com. Its advantages is easy to integrate and development. However, REST API is the best option, if you have many records to process. REST API uses the same underlying data model and standard objects as like in SOAP API.
REST API is the best example of abstraction, such as single record, collection of records or even dynamic real-time data. REST API is identified by named URL and is accessed by using standard HTTP methods like (HEAD, GET, POST, PATCH, DELETE). REST API can be use to interact with Force.com object. For example:
- Obtain detailed information about the Standard/Custom object.
- Perform Query/Search options.
- Add/Update or Delete records.
Force.com API supports OAuth an open source protocol to allow secure API authentication. It also supports for JSON and XML format. JSON is the default format for REST API, you can change this to XML. You can use many tools like PostMan or CURL to send HTTP request to access REST API.
- SalesForce.com supports OAuth protocol to allow users of application to securly access the data without having real username and password. Before making any API request, you must authenticate the application using OAuth.
- Set up your application as a connected app in the Salesforce organization.
- Determine the correct Salesforce OAuth endpoint for your connected app to use. Supported OAuth flows include:
- Web server flow, where the server can securely protect the consumer secret.
- User-agent flow, used by applications that cannot securely store the consumer secret.
- Username-password flow, where the application has direct access to user credentials.
- After successfully authenticating the connected app user with Salesforce, you’ll receive an access token which can be used to make authenticated REST API calls.
Creating Connected APP:
- From Setup, enter Apps in the Quick Find box, then select Apps and click New to start defining a connected app.
- Enter the name of your application.
- Enter the contact email information, as well as any other information appropriate for your application.
- Select Enable OAuth Settings.
- Enter a Callback URL. Depending on which OAuth flow you use, this is typically the URL that a user’s browser is redirected to after successful authentication. As this URL is used for some OAuth flows to pass an access token, the URL must use secure HTTP (HTTPS) or a custom URI scheme.
- Add all supported OAuth scopes to Selected OAuth Scopes. These scopes refer to permissions given by the user running the connected app.
- Enter a URL for Info URL. This is where the user can go for more information about your application.
- Click Save. The Consumer Key is created and displayed, and the Consumer Secret is created (click the link to reveal it).
curl -X POST -H “Content-Type: application/x-www-form-urlencoded” -H “Cache-Control: no-cache” -H “Postman-Token: 26a0df06-9cc6-d1a5-2945-bce6a12a40b4” -d ‘client_id=3MVG9ZL0ppGP5UrBctV8ANK6.aSwde.V2awsdMdFLRjJwx_vAoetz0GFD2iM2zoLqwefGtgFy.1b1Sx23d44fpemail@example.com&password=test@123AsqswDeXGRWCR4zMGU6xnFMz’ “https://login.salesforce.com/services/oauth2/token”