Real-Time Product Catalog via Salesforce REST API
Real-Time Product Catalog via Salesforce REST API
Salesforce, known for its comprehensive Customer Relationship Management (CRM) solution, offers capabilities for developers to expose logic as RESTful services. In our example, a Bank called wanted to expose its POS product catalog for Merchants to external client applications in real-time using Salesforce’s platform. Let’s see how we achieved this using Salesforce’s REST API.
Problem Statement:
The Bank provides POS offerings to Merchants with current account. The company’s product catalog, including details like product name, price, description, and availability, is maintained in Salesforce. The Bank aims to:
- Provide real-time access to its product catalog to external client applications.
- Trigger additional logic (like inventory checks) before sending out the product details.
Solution:
Flow Creation:
A flow was created in Salesforce which contains the logic for:
- Querying the product catalog.
- Running inventory checks.
- Preparing the response containing product details.
REST API Endpoint Creation:
- Using Salesforce’s developer capabilities, a custom Apex class was developed to expose an inbound REST API.
- This Apex class was defined with a URL mapping (like /getProductCatalog) to handle HTTP GET requests.
- Within this class, the previously created flow was invoked to fetch and process the product details.
API Security:
- To ensure secure access, Salesforce’s in-built OAuth2 capabilities were leveraged.
- Client applications were required to authenticate using OAuth2 before accessing the API.
Client Application Integration:
- External client applications were provided with appropriate API documentation.
Client apps were required to:
- Obtain an access token using OAuth2.
- Make an HTTP GET request to the Salesforce endpoint (e.g., https://bank.my.salesforce.com/services/apexrest/getProductCatalog).
- Parse the JSON response to access the product catalog in real-time.
Results:
- Real-time Access: External applications could now access Banks POS product catalog in real-time.
- Scalability: By utilizing Salesforce’s robust platform, the Bank ensured the system could handle a large number of concurrent API requests.
- Flexibility: Changes to the product catalog logic could be easily handled within Salesforce flows, ensuring minimum changes to the API or the client applications.
Conclusion:
Salesforce’s capabilities, including flows and Apex classes, offer a powerful way to expose business logic as REST APIs. The Bank successfully leveraged these features to provide a seamless experience for its external client applications, ensuring they always had access to the most up-to-date product information.