Question
· 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.

Discussion (9)1
Log in or sign up to continue

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,!
    }
}