You need to sign in to do that
Don't have an account?
Exposing Data through REST API
Hi,
I need to expose certain Salesforce Data to a third party app that doesn't have a ready-made Salesforce integration. I'm going to use REST API to expose the data and this action will be triggered when a status changes.
Here is the general process of what should happen
1. User changes status which triggers the API
2. API call made to an external app and Salesforce Data is exposed, ready to be consumed
3. External App consumes data
I'm struggling to understand what would I need to ask from the third part? and is there anything else I would need to do?
Any help is much appreciated :)
Many Thanks,
Natasha
In this case you want to expose a REST API and then you have to code a class with @RestResource annotation.
Check this example:
So, your third party API will call Salesforce service using https://<your_instance_url>/services/apexrest/myserviceendpoint/<account_id>.
Also, it is necessary to send the Bearer (Salesforce auth) inside the request headers using this format:
'Authorization','Bearer <access_token>
The session ID may be requested using the endpoint https://login.salesforce.com/services/oauth2/token. There are some OAuth2 flows like web flow and password flow. You'll find some guidance here (https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_understanding_web_server_oauth_flow.htm).
Regards.
All Answers
First of all, you need to get the integration contract. This means you need to understand the data exchange format.
REST API usually user JSON format. Suppose you have an API to change an account status on your legacy system. One integration contract may be:
That said, we can move to next step. "User changes status which triggers the API". You'll need to have inside your object trigger (Account in this example) a future method witch callout=true annotation. For example:
Your third-party API should be able (since you got integration contract from them) to process your request.
Let me know if you have any doubts.
Hope you find this solution useful. If it does please mark as Best Answer to help others too.
Regards.
Thank you for your prompt response :)
I'm quite new to dev and the only instructions we got from the third party is that we need to expose data for them to consume it. The user would trigger the callout when the status changes, then the information on that record would be exposed ready to be used.
Just to clarify, I'd need to write a trigger which invokes a REST web service method? Would it be how you've written it above?
Many Thanks!!
Natasha
In this case you want to expose a REST API and then you have to code a class with @RestResource annotation.
Check this example:
So, your third party API will call Salesforce service using https://<your_instance_url>/services/apexrest/myserviceendpoint/<account_id>.
Also, it is necessary to send the Bearer (Salesforce auth) inside the request headers using this format:
'Authorization','Bearer <access_token>
The session ID may be requested using the endpoint https://login.salesforce.com/services/oauth2/token. There are some OAuth2 flows like web flow and password flow. You'll find some guidance here (https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_understanding_web_server_oauth_flow.htm).
Regards.