1

I am Unable to query "SetupAuditTrail" through Rest call.

When I made "SELECT Id FROM SetupAuditTrail Where CreatedDate>2019-12-25T15:00:00Z"query, I got

RESPONSE: Object type 'SetupAuditTrail' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names

RESPONSE CODE: 400

ERROR CODE: INVALID_TYPE

I can see Audit logs in my UI. And when I tried to download these logs through an API got this. Please, could anyone tell me where I am wrong or what should I do to overcome this?

1 Answer 1

2

Welcome to SFSE.

SetupAuditTrail is valid for SOQL query.

Just make sure that you are executing the SOQL in the format applicable for GET REST call

The URI must be in this format:

/vXX.X/query/?q=SOQL query

Example of request via curl:

curl https://yourInstance.salesforce.com/services/data/v47.0/query/?q=SELECT+name+from+Account -H "Authorization: Bearer token"

So for querying SetupAuditTrail the URI will be similar to this:

https://yourInstance.salesforce.com/services/data/v47.0/query/?q=select+Action,CreatedById,CreatedDate,DelegateUser,Display,Id,ResponsibleNamespacePrefix,Section+from+SetupAuditTrail+Where+CreatedDate>2019-12-25T15:00:00Z

The INVALID_TYPE error could be resulting from a permission issue, ensure that the user profile executing the request has "View Setup and Configuration" which is required for viewing audit trail history.

References:

API REST Query

REST Execute SOQL query

7
  • Thanks for your response. I am using SOQL query only. The URI that I am using is https://Instance.salesforce.com/services/data/v39.0/query?q=SELECT+Id+FROM+SetupAuditTrail++Where+CreatedDate>2019-12-25T15:00:00Z. After querying this, I got the above response along with status code: 400 and "errorCode": "INVALID_TYPE"
    – trinadh
    Commented Dec 30, 2019 at 7:11
  • @trinadh could you try calling the URI to query from Account object and provide the result ?
    – Shamina
    Commented Dec 30, 2019 at 7:19
  • I got 200 response code for Account Object.
    – trinadh
    Commented Dec 30, 2019 at 7:40
  • 1
    @trinadh I was able to reproduce the INVALID_TYPE error by executing REST call with a user which does not have "View setup and configuration" permission. see updated answer for more details
    – Shamina
    Commented Dec 30, 2019 at 9:06
  • 1
    @Shamina It is because of the user with which I am trying to query don't have view setup and configuration permission. Thank You so much for your help. After adding the permission it is working good.
    – trinadh
    Commented Dec 30, 2019 at 10:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .