Salesforce Sales Cloud - How to Track the Field Change History for Different Resources

To retrieve the change history for a certain resource, use the Salesforce /query endpoint. This is an undocumented API on the Salesforce Sales Cloud element that lets the user pass a SOQL query directly to Salesforce.

Prior to making the request itself, there are some settings to be configured in the Salesforce UI to enable the field history tracking. The steps to be taken are reflected in the following Salesforce article for standard objects: https://help.salesforce.com/articleView?id=tracking_field_history_for_standard_objects.htm&type=5 and in this one for custom objects: https://help.salesforce.com/articleView?id=tracking_field_history_for_custom_objects.htm&type=5.

After configuring the field history tracking for the desired fields, the request can be made in Postman or any other tool using the /query endpoint mentioned above. It should have the structure as presented below, with a q(query) parameter having an SOQL statement as its value and the selected fields (id, NewValue, OldValue, Field) depending on what resource the user is going to query. We would suggest checking the documentation in order to correctly provide the field names in the query: https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_accounthistory.htm (this is for the AccountHistory resource, but searching the page for the word "history" will provide all the resources for which we can track the history of the fields).

The GET request example: 

curl -X GET \
  'https://{staging OR api}.cloud-elements.{com OR co.uk}/elements/api-v2/query?q=SELECT id, NewValue, OldValue, Field from AccountHistory' \
  -H 'Authorization: User xxxxxxxxxxx, Organization xxxxxxxxxxx, Element xxxxxxxxxxx' \

The response payload has the following structure: 

{
        "Field": "TextName",
        "NewValue": "Alex Entity",
        "IsDeleted": false,
        "Id": "xxxxxxxxx",
        "OldValue": "Alex Str"
 }

More information about the query endpoint can be found here.