Looking for examples or scenarios where pathparams and queryparams can be used in scripted rest api

Suggy
Giga Sage

Hello....

 

I know how pathparams and queryparams work in scritped rest api. but I feel both are the same or dedundant. ie I think both can be used interchangeable.

 

Can anyone give examples or scenarios where pathparams and queryparams can be used in scripted rest api where each has got its own significance?

6 REPLIES 6

Suggy
Giga Sage

.

Anand Kumar P
Giga Patron
Giga Patron

Hi @Suggy,

In ServiceNow Scripted REST APIs, path parameters and query parameters serve distinct purposes and are used in different scenarios.

1. Path Parameters:
 Purpose: Path parameters are part of the URL path and are used to identify a specific resource.
Example:

/api/v1/incident/{incident_id}

Scenario:You want to retrieve details of a specific incident identified by its unique ID. The incident_id is embedded in the URL path.

2. Query Parameters:
• Purpose: Query parameters are part of the URL query string and are used for filtering or modifying the results.
Example:

/api/v1/incidents?status=open&priority=high

 Scenario:You want to retrieve a list of incidents with specific criteria, like those with an open status and high priority. The parameters are appended to the URL as key-value pairs.

Real-time Example:
Suppose you have a Scripted REST API to manage tasks. Here’s how you might use both path parameters and query parameters:

• Path Parameters:
• GET /api/v1/task/{task_id}
• Purpose: Retrieve details of a specific task identified by its task_id.
• Query Parameters:
• GET /api/v1/tasks?status=incomplete&assigned_to=JohnDoe
• Purpose: Retrieve a list of tasks filtered by status and assigned_to.

In this example, path parameters help you specify a particular task, while query parameters allow you to filter the list of tasks based on various criteria.

 

Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand