Steps to Re-Authenticate a SalesForce instance with the API

As you may already know, you can re-authenticate Salesforce from Cloud Elements 2.0. However, you can also do this programmatically through API calls. Follow the steps below. 

1.  Make a GET request to /elements/sfdc/oauth/url.

curl -X GET \	
'https://api.cloud-elements.com/elements/api-v2/elements/sfdc/oauth/url?apiKey=<your_api_key>&apiSecret=<your_api_secret>&callbackUrl=<your_callback_url>'

2. Navigate to this URL to get the code as you would for the OAuth 2.0 flow.

3. Get the current instance configuration.

curl -X GET \
https://api.cloud-elements.com/elements/api-v2/instances/<instance_id> \
-H 'Authorization: User <Your_user_secret>, Organization <Your_organization_secret>' \
-H 'accept: application/json'

4. Take the body of the response from step 3 and delete the oauth.user.token and oauth.user.refresh_token

5. In the same body add a "providerData" object that contains the code.

"providerData": {
       "code": "xxxxxxxxxxx"
}

6. Now use the following endpoint with the body from the response in step 4 and 5.

PUT https://api.cloud-elements.com/elements/api-v2/api-v2/instances/{instanceId}?reAuthenticate=true

7. Make sure that in Step 6 you pass the correct authorization headers and OAuth token.