You need to sign in to do that
Don't have an account?
James Jones 1
Server to Server REST API Access
I have a server that needs to push changes up to a Salesforce DB several times per day. There is only one Salesforce 'user' involved with this task.
How do I implement OAuth, or use an alternative scheme, to handle this scenario, and allow me to use the REST API to complete this task? I suppose if the access token could be made to be non-expiring that could work but I am hoping for a cleaner solution.
Thanks,
James
How do I implement OAuth, or use an alternative scheme, to handle this scenario, and allow me to use the REST API to complete this task? I suppose if the access token could be made to be non-expiring that could work but I am hoping for a cleaner solution.
Thanks,
James
As I understand you have two salesforce instances and wish to integrate them using OAuth. If this is correct, then follow the below steps -
Destination Instance Configuration -
Create a new Connected App record in this instance that will generate a set of Consumer Key and Consumer Secret. These will be required by the Source Instance for retrieving the access token.
Source Instance Configurations -
1. Create a Remote Site Setting record in this instance mentioning the Destination instance URL.
2. Create a Trigger in the Source instance that makes a call to a class which has a method with annotation @future(callout=true)
3. Within the Trigger, check for any pre-conditions that you wish to check before triggering the interface and then call the class method.
4. Within the Class method do the following -
- Using the 'Salesforce User' credentials get the access token
- Use the access token and then call the REST API resource that you wish to access like Account, Opportunity etc with the relevant input as JSON/XML.
And you are done. I am sharing a sample piece of code of the Class that should help you configure all this -
Thanks
AR
If you find the reply useful that solves your problem then please mark it as best answer.
All Answers
As I understand you have two salesforce instances and wish to integrate them using OAuth. If this is correct, then follow the below steps -
Destination Instance Configuration -
Create a new Connected App record in this instance that will generate a set of Consumer Key and Consumer Secret. These will be required by the Source Instance for retrieving the access token.
Source Instance Configurations -
1. Create a Remote Site Setting record in this instance mentioning the Destination instance URL.
2. Create a Trigger in the Source instance that makes a call to a class which has a method with annotation @future(callout=true)
3. Within the Trigger, check for any pre-conditions that you wish to check before triggering the interface and then call the class method.
4. Within the Class method do the following -
- Using the 'Salesforce User' credentials get the access token
- Use the access token and then call the REST API resource that you wish to access like Account, Opportunity etc with the relevant input as JSON/XML.
And you are done. I am sharing a sample piece of code of the Class that should help you configure all this -
Thanks
AR
If you find the reply useful that solves your problem then please mark it as best answer.
One change in the above reply. Use the following URL instead of the one given for sending the data.
Replace https://na23.salesforce.com/services/data/v32.0/sobjects/Account/01QU0000000DF
With https://na23.salesforce.com/services/data/v32.0/sobjects/Account/01QU0000000DF?_HttpMethod=PATCH
If you are not aware of the URL syntax, here is the break down -
https://[Destination URL]/services/date/v32.0/sobjects/[Object to be updated]/[Object Id to be updated]?_HttpMethod=PATCH
Thanks
AR
Auth response: {
"error": "invalid_grant",
"error_description": "authentication failure"
}
Here is the code:
I do not find any issue in your code and the grant type for this call has to be 'password' only. I hope you appended the security token in the password value.
Did you get any other lead on this issue?
Thanks
AR