The CreatorCon Call for Content is officially open! Get started here.

404 Error in case of REST API not returning any data

Dan87
Tera Contributor

 

Hi Team,

I am using REST API to get data from tables.

However, it seems in case of nor records found in particular time range, API returns 404 and below response.

 

{
    "error": {
        "message": "No Record found",
        "detail": "Records matching query not found. Check query parameter or offset parameter"
    },
    "status": "failure"
}

 

 Is this correct behavior and we need to handle this 404 response in case of empty records.

Query used:

 

sys_created_on>=javascript&colon;gs.dateGenerate('2024-10-28','18:25:01')^sys_created_on<javascript&colon;gs.dateGenerate('2024-10-28','18:30:01')^ORDERBYDESCsys_created_on

 

 This query works well for other time range.

Please let me know if anything wrong with query as well.

 
3 REPLIES 3

Sheldon  Swift
ServiceNow Employee
ServiceNow Employee

Hi @Dan87 - I would expect 200 OK and an empty result set, not a 404. 

 

{
  "result": []
}

 

In this case, I suspect you're using the wrong endpoint.

 

  • Retrieving a single record:
    • GET /api/now/table/{table}/{sys_id}
  • Retrieving multiple records:
    • GET /api/now/table/{table}

Also, at a glance, your query appears to be malformed. The query parameters should look like:

 

?sysparm_query=sys_created_on>=javascript&colon;gs.dateGenerate('2024-10-28','18:25:01')^sys_created_on<javascript&colon;gs.dateGenerate('2024-10-28','18:30:01')

 

OR

 

?sysparm_query=sys_created_on%3E%3Djavascript%3Ags.dateGenerate('2024-10-28'%2C'18%3A25%3A01')%5Esys_created_on%3Cjavascript%3Ags.dateGenerate('2024-10-28'%2C'18%3A30%3A01')

 

Finally, if I understand correctly that your intended query parameters are Created >= 2024-10-28 18:25:01 AND Created < 2024-10-28 18:30:01, you might consider using the between operator instead.

Thanks Sheldon!

1. I want multiple records hence using below api

GET /api/now/v1/table/sys_audit


2. I pasted the parameters from curl command above.
Actual params looks like this

sysparm_limit:10000
sysparm_offset:0
sysparm_query:sys_created_on>=javascript&colon;gs.dateGenerate('2024-11-27','04:06:58')^sys_created_on<javascript&colon;gs.dateGenerate('2024-11-27','05:06:58')^ORDERBYDESCsys_created_on

3. And the response is 404:

{
    "error": {
        "message": "No Record found",
        "detail": "Records matching query not found. Check query parameter or offset parameter"
    },
    "status": "failure"
}

 

 I am trying to understand is this the current behavior of api.

You're using the v1 Table API...just switch to v2 (/api/now/v2/table/sys_audit) or latest (/api/now/table/sys_audit).

 


  • In version v1, if a GET query to retrieve multiple records matches no records, the response is the error No Record Found with status code 404.
  • In version v2, if a GET query to retrieve multiple records matches no records, the response is an empty array with status code 200.

Source: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0551763