Written by

CEO at Ellipse
Question Pierre LaFay · Aug 20, 2023

How to get param passed in GET REST query

Hi,

I don't found how to get params send by a GET REST query (not in url but by request param).

this is config of the call in postman

I try to get %request.Data, doesn't work : Data is undefined

I try to get %request.GetCgiEnv("Data"), doesn't work, return ""

I do ZW %request and see that my parameter is present in cgi parameters, but I don't now how to access it.

Comments

Pierre LaFay · Aug 20, 2023

I found a way by %request.Data("Top",1), but in this case, I get parameters one by one.

Is a method to get all my parameters in an object or an array exists ?

0
Ashok Kumar T · Aug 20, 2023

Hello Pierre,

You have two options to get query parameters

  1. You can merge the entire %request.Data into local array and use string function.
  2. User %request.Next(data) method to loop the %request.Data one by one and get query parameter values

ClassMethod GetQueryParams()
{
	set data=""For {
		set data  = %request.Next(data) quit:data=""write data,!
	}
}
OUTPUT
Bottom
Name
Top

For cgiEnvs. You can follow same merge option to get all values. Otherwise use %request.NextCgiEnv(cgi) to get the list of available values.

ClassMethod GetcgiEnvs()
{
    set cgi=""for {
        set cgi  = %request.NextCgiEnv(cgi) quit:cgi=""write cgi,!
    }
}
0
Pierre LaFay  Aug 21, 2023 to Ashok Kumar T

Hi Ashok,

Thank you for your answer, I understand and will apply looping by Next in Data.

However, I don't know how to merge the entire %request.Data into local array and use string function.

I'm sorry for asking questions that should be obvious, but I'm new to Iris for REST Api...

0
Ashok Kumar T  Aug 21, 2023 to Pierre LaFay

Hello Pierre,

No problem. You can use the merge command(sorry not a string function) to take a copy of entire global node and subtree

merge queryparam = %request.Datazwrite queryparam ;print the entire node and subtree
0
Pierre LaFay  Aug 21, 2023 to Ashok Kumar T

Many thanks, works fine and it's exactly what I need

0
Eduard Lebedyuk · Aug 21, 2023

To check all parts of the request you can use this utility method which outputs all objects as a response. Just add this to any part of your code:

set %response.ContentType = "html"
do ##class(%CSP.Utils).DisplayAllObjects()
return $$$OK
0
Pierre LaFay  Aug 21, 2023 to Eduard Lebedyuk

Hi Eduard,

Thanks for this utility method. I think I will use it for debugging

0
Chad Severtson · Aug 21, 2023

%request.Get("Top") will return the value which is stored in %request.Data("Top", 1). 

If you want to iterate through all the values, I'd use @Ashok Kumar T 's solution or $ORDER on %request.Data. 

0
Pierre LaFay  Aug 21, 2023 to Chad Severtson

Hi Chad,

Thanks for your alternative syntax !

0