Scripted REST API - dynamic URL

Colleen
Tera Expert

Is it possible to create a scripted REST API method with a dynamic URL?

 

For example, using this URL to make the REST call:

https://<servicenowURL>/api/x_uob15_living/ticket/TCK12345/comments

 

Where TCK12345 is the reference number of an existing ticket and will change depending on the ticket being queried. 

 

I tried specifying the relative URL of the method as /${ticket_id}/comments, but it was not accepted.

2 ACCEPTED SOLUTIONS

M Iftikhar
Mega Sage

@Colleen ,

In ServiceNow, when creating a Scripted REST API, it is possible to have dynamic segments in your URL path like your example with a variable ticket ID — but it must be done using path parameters.

You should define your relative path using curly braces {} to indicate a path parameter. So for your case:

/{ticket_id}/comments

Then, inside your Scripted REST Resource, you can access the dynamic value using the request.pathParams object.

 

Thanks & Regards,  
Muhammad Iftikhar  

If my response helped, please mark it as the accepted solution so others can benefit as well. 

View solution in original post

Ankur Bawiskar
Tera Patron
Tera Patron

@Colleen 

why not?

It should work when you use GET Method.

you can grab the ticket_id in scripted rest api script

check solution shared below from me

How to use Query Parameter of Scripted API 

there are lot of OOTB Scripted REST API which you can check how to grab it

AnkurBawiskar_0-1758892968959.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

5 REPLIES 5

Bhuvan
Kilo Patron

@Colleen 

 

You can do this in Flow Designer Action easily rather than Scripted REST API. You can do same function in Scripted REST API as well.

 

Please see below for sample action and how to set it up,

Bhuvan_0-1758893390639.png

Bhuvan_1-1758893434511.png

You can pass the reference incident from main flow and call it in action.

 

If this helped to answer your query, please mark it helpful & accept the solution.

 

Thanks,

Bhuvan