0% found this document useful (0 votes)
15 views7 pages

Overview of REST API

The Salesforce REST API enables external applications to interact with Salesforce data using standard HTTP methods, making it ideal for mobile and web applications, as well as third-party integrations. It primarily uses JSON for data exchange and supports various operations like retrieving, creating, and updating records, while also enforcing authentication via OAuth 2.0. Key features include lightweight design, statelessness, and the ability to handle custom objects, with limitations on daily request counts and support for error handling and CORS configurations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views7 pages

Overview of REST API

The Salesforce REST API enables external applications to interact with Salesforce data using standard HTTP methods, making it ideal for mobile and web applications, as well as third-party integrations. It primarily uses JSON for data exchange and supports various operations like retrieving, creating, and updating records, while also enforcing authentication via OAuth 2.0. Key features include lightweight design, statelessness, and the ability to handle custom objects, with limitations on daily request counts and support for error handling and CORS configurations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

REST API.

1. Overview of REST API


• What It Is: The Salesforce REST API allows external applications to
interact with Salesforce data using standard HTTP methods like
GET, POST, PUT, PATCH, and DELETE.
• Key Feature: It's lightweight, simple, and uses HTTP for
communication. This makes it a preferred choice for mobile apps,
web apps, or any external system that needs to interact with
Salesforce.
• Data Format: JSON (JavaScript Object Notation) is the most
commonly used format for sending and receiving data.

2. When to Use REST API in Salesforce


• Mobile Apps: When building mobile applications that need to
retrieve or update Salesforce data.
• Web Applications: For web applications to integrate Salesforce
functionalities.
• Third-Party Integrations: To connect external systems (e.g., ERP
systems, marketing tools) with Salesforce.
• Simple Use Cases: When dealing with simple queries or actions that
don't require bulk data operations (you can use Bulk API for large
datasets).

3. Common HTTP Methods Used


• GET: Retrieve records (e.g., fetching a contact or an account).
• POST: Create new records in Salesforce (e.g., adding a new lead).
• PUT: Update existing records.
• PATCH: Update a record but with a smaller payload (only modified
fields).
• DELETE: Remove records from Salesforce.

4. Authentication
• OAuth 2.0: Common authentication method. You need to obtain an
access token to make API calls.
• Session ID: Alternatively, you can use the Salesforce session ID for
authentication when making API calls.
5. Usage Example in Salesforce REST API
Suppose you want to retrieve all the Accounts in your Salesforce instance:

• Endpoint:
https://yourInstance.salesforce.com/services/data/vXX.X/sobjects/Ac
count/
• HTTP Method: GET
• Authorization: Bearer Token (OAuth 2.0)
• Response: A list of accounts in JSON format.

Example Request:

curl -H "Authorization: Bearer <Access-Token>" \


-H "Content-Type: application/json" \

https://yourInstance.salesforce.com/services/data/vXX.X/sobjects/Account/

Example Response (JSON):

{
"totalSize": 2,
"done": true,
"records": [
{
"attributes": {
"type": "Account",
"url": "/services/data/vXX.X/sobjects/Account/0015g00000Xzzy2AAB"
},
"Id": "0015g00000Xzzy2AAB",
"Name": "Acme Corporation",
"Industry": "Technology"
},
{
"attributes": {
"type": "Account",
"url": "/services/data/vXX.X/sobjects/Account/0015g00000XzzzzZZZ"
},
"Id": "0015g00000XzzzzZZZ",
"Name": "Beta Solutions",
"Industry": "Consulting"
}
]
}

6. Key Points to Remember


• Security: Always authenticate using OAuth 2.0 for secure access.
Using session IDs or hardcoded tokens in the client is not
recommended.
• Limitations: REST API has a daily request limit, which can vary
depending on your Salesforce edition and license.
• Ease of Use: REST API is great for simple, lightweight integrations
where you don’t need complex data processing or batch processing.
• Bulk API: If you need to handle large amounts of data, consider
using Salesforce's Bulk API instead of REST API.

7. Where It's Used in Salesforce


• Mobile SDKs: Salesforce provides mobile SDKs that use REST API
to fetch data from Salesforce to mobile apps.
• External Integrations: Connect tools like marketing automation
platforms, ERP systems, or custom web services with Salesforce.
• Third-Party Apps: If you are building apps on Salesforce
AppExchange, REST API is commonly used to fetch or send data
from Salesforce.
• Custom UI Components: If you're building a custom UI using
technologies like React or Angular, you can use REST API to fetch
Salesforce data and integrate it into your UI.

8. Advantages
• Lightweight: REST API is less complex and doesn’t require a lot of
resources to implement.
• Stateless: Each request is independent and does not depend on
previous requests. This makes it scalable and efficient for external
integrations.
• JSON Format: JSON is easy to parse and use in modern web and
mobile apps.

9. Bulk API vs REST API


• Bulk API is specifically designed for handling large data sets, such as
inserting, updating, or deleting large volumes of records at once. While
REST API is great for smaller, more frequent requests (like individual
records), Bulk API is used when you need to process large batches of
records (e.g., thousands or millions).
• REST API is best suited for real-time or transactional integrations, while
Bulk API is suited for batch processing scenarios.

10. Querying Data


• The /query endpoint in REST API allows you to use SOQL (Salesforce
Object Query Language) to query Salesforce data. This is similar to SQL
but is specific to Salesforce.
• Example query:
GET
/services/data/vXX.X/query/?q=SELECT+Name+FROM+Acco
unt

• You can use LIMIT, WHERE, and ORDER BY clauses in your SOQL
queries for filtering and sorting records.

11. Handling Large Responses


• Salesforce limits the number of records returned in a single REST API call.
If you query more records than the limit (usually 2,000), Salesforce will
provide a nextRecordsUrl that you can use to retrieve the next set of
records.
• Example of pagination:
{
"done": false,
"nextRecordsUrl":
"/services/data/vXX.X/query/01g0Y000001XbLhUAZ-
2000"
}

• This helps in retrieving large datasets by making multiple calls to the API.

12. Custom Object Support


• REST API also supports custom objects (those with a __c suffix). You can
interact with custom Salesforce objects just like standard objects (e.g.,
Account, Contact).
• Example: If you have a custom object called Customer__c, you can
create, update, or query it using the same endpoints.
• Example of accessing a custom object via REST API:

GET /services/data/vXX.X/sobjects/Customer__c/

13. Rate Limits


• Salesforce imposes API rate limits on the number of requests you can make
to the REST API within a 24-hour period. This is to prevent abuse and
ensure fair use of resources.
• Example: In a typical Salesforce org, you might have a limit of 15,000
API calls per 24 hours (this depends on your Salesforce edition and license
type).
• You can check your remaining API requests using the following:

GET /services/data/vXX.X/sobjects/limits/

14. Error Handling


• The Salesforce REST API provides standard HTTP status codes to indicate
whether a request was successful or if an error occurred. Some common
status codes include:
o 200 OK: The request was successful.
o 201 Created: A new record was created.
o 400 Bad Request: The request is malformed or contains invalid
parameters.
o 401 Unauthorized: Authentication failed (invalid OAuth token).
o 404 Not Found: The requested resource doesn't exist.
o 500 Internal Server Error: Something went wrong on the server
side.
• The response body often includes more detailed error messages in JSON
format.

15. Chatter Integration


• Salesforce REST API can also interact with Chatter, Salesforce's
collaboration platform. You can post to Chatter feeds, comment on posts,
and retrieve Chatter feeds using REST API.
• Example of posting to Chatter:
POST /services/data/vXX.X/chatter/feed-elements
16. Metadata API
• While REST API is typically used for data operations, the Metadata API is
used to retrieve, deploy, and manage Salesforce metadata (e.g., Apex
classes, triggers, page layouts, etc.).
• If you need to manage your Salesforce org’s setup or schema, you'd use the
Metadata API.

17. Cross-Origin Resource Sharing (CORS)


• When integrating with external web applications, you might encounter
issues with CORS. Salesforce allows you to configure CORS settings to
permit or restrict access to your org’s REST API from specific domains.
This is important for securing your API from unauthorized cross-origin
requests.

18. Timeouts and Retries


• Salesforce imposes a maximum execution time for each API request. If a
request takes too long, it will time out, and you’ll need to retry the request.
• Implementing retry logic in your integration is essential to handle timeouts
gracefully and ensure that data is eventually processed.

19. Field-Level Security


• When querying data via REST API, it’s important to remember that field-
level security settings apply. If a user doesn’t have permission to view a
certain field, that field will not be returned in the API response, even if it
exists in the record.

20. Support for JSON and XML


• While JSON is the most commonly used format for requests and
responses in REST API, Salesforce REST API also supports XML for
those who prefer it or need it for integration with systems that rely on
XML.
• When making requests, you can specify the format by including the
Accept header:

Accept: application/xml
21. Versioning of API
• Salesforce REST API is versioned, which means that you can
specify which version of the API you want to use. This ensures
compatibility as Salesforce makes updates or changes to the API.
• You can find the version of the API you're working with by
referencing /services/data/vXX.X/, where XX.X is the version number
(e.g., v54.0).
• It's important to stay updated on which API versions are deprecated
or no longer supported to ensure your integrations continue to work
smoothly.

My Points
• REST API is highly useful when you need real-time, small amounts of
data fetched or updated from Salesforce.
• Because it uses JSON and works over HTTP, it's simple to integrate
into almost any modern programming language or framework (like
Python, JavaScript, or Java).
• I suggest using REST API when you want to keep things simple and
efficient for client-side integrations.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy