Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Passing Parameters to RESTRequest

Hello

 

I am trying to develop a Job that exposes a rest end point and this end point tales in two parameters:

  1. areaCode
  2. groupNumber

I want to use these parameters later on in the flow to restrict a SQL Statement.

 

I have defined a 'tRESTrequest' and have added a API Mapping with a URI Pattern of "/{areaCode}/{groupNumber}/". In the Output Flow I have defined the two parameters.

 

 

0683p000009LxgR.png

0683p000009LxgH.png

When I execute this, I pass the two parameters

 

0683p000009LxKG.png

 

However the two parameters are evaluated to null. I have put a Java component to debug the the Request Object and it confirms that they are null.

 

The tJavaRow Component code is:

 

System.out.println("Area Code   : "+globalMap.get("groupCode.areaCode"));
System.out.println("Group Number: "+globalMap.get("groupCode.groupNumber"));

//The object with the key "restRequest" is a HashMap
java.util.Map<String, Object> myMap = ((java.util.Map<String, Object>)globalMap.get("restRequest"));

//Print out of what you are seeing already
System.out.println("MyMap = " +myMap.toString());

//Create an iterator over the keyset
java.util.Iterator<String> it = myMap.keySet().iterator();

//Iterate over the keyset and print out the keys
while(it.hasNext()){
	System.out.println(it.next());
}

//Retrieve the PARAMS HashMap
java.util.Map<String, Object> myParams = ((java.util.Map<String, Object>)myMap.get("PARAMS"));

//Create an Iterator for the PARAMS HashMap
java.util.Iterator<String> it2 = myParams.keySet().iterator();

//Iterate over the PARAMS HasMap
while(it2.hasNext()){
	System.out.println(it2.next());
}

The output is:

0683p000009LxYX.png

 

Am I missing some config ?

 

Any Ideas

 

Thanks

 

Patrice

Labels (4)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Okay I think I resolved it, when referencing REST Inbound parameters, you do NOT need to use the 'globalMap.get'.

 

You just refer directly...

 

FROM WalkDetails "+
"WHERE WalkDetails.Group_Code = '"+groupCode.areaCode+groupCode.groupNumber+"'"

 

This worked...

 

Anyway...I have another question.

 

I want to add a check after the SQL Query and count number of rows returned, if 0 then I want the REST Response to return a custom message saying "Now rows found etc"

 

Is this possible...

View solution in original post

12 Replies
Anonymous
Not applicable
Author

The AreaCode and GroupNumber are not stored in the globalMap. They are columns in the row from your tRESTRequest component.

 

I assume you are using globalMap.get("groupCode.areaCode")) and globalMap.get("groupCode.groupNumber")) in your query which is returning nothing. You can fix this by adding the following code to the very top of your tJavaRow....

 

globalMap.put("groupCode.areaCode",groupCode.areaCode);
globalMap.put("groupCode.groupNumber",groupCode.groupNumber);

Of course, a better way to resolve this is to remove the tJavaRow and use the globalMap variables automatically created by the tFlowToIterate. They will have the keys.....

 

"row3.areaCode"
"row3.groupNumber"

Anonymous
Not applicable
Author

Thanks Richard.

 

That is exactly how I had it originally. I only added the tJavaRow in order to debug the inbound parameters.

 

So I now deactivate the Java Component and rewire the flow...

 

0683p000009Lxig.png

 

So when I run the flow and pass : http://localhost:8088/walkDetails/ES/50/

 

As you can see the SQLInput component returns 0 rows..

 

The SQL Statement in the 'GetWalkDetails_GroupCode' component looks like this:

 

 

"SELECT WalkDetails.WalkID,
		WalkDetails.D_grade,
		WalkDetails.D_strand,
		WalkDetails.D_event,
		WalkDetails.D_festival,
		WalkDetails.D_restriction,
		WalkDetails.Title,
		WalkDetails.Summary,
		WalkDetails.Group_Code,
		WalkDetails.WalkDescription,
		WalkDetails.Date,
		WalkDetails.Distance_KM,
		WalkDetails.Distance_Miles,
		WalkDetails.Grade_Local,
		WalkDetails.Linear_Ind,
		WalkDetails.Time,
		WalkDetails.GridRef,
		WalkDetails.Easting,
		WalkDetails.Northing,
		WalkDetails.Latitude,
		WalkDetails.Longitude,
		WalkDetails.Postcode,
		WalkDetails.StartingPointDescription,
		WalkDetails.Display_Ind,
		WalkDetails.Postcode_Latitude,
		WalkDetails.Postcode_Logitude,
		WalkDetails.CreationSource,
		WalkDetails.CreationDate,
		WalkDetails.MaintenanceSource,
		WalkDetails.MaintenanceDate
FROM	WalkDetails "+
"WHERE WalkDetails.Group_Code = '"+globalMap.get("groupCode.areaCode")+globalMap.get("groupCode.groupNumber")+"'"

This should return some rows, because if I were to change the SQL and hard code the values that I pass via the URL, the SQL returns rows

 

 

		WalkDetails.MaintenanceSource,
		WalkDetails.MaintenanceDate
FROM	WalkDetails "+
"WHERE WalkDetails.Group_Code = 'ES50'"

and run the flow...

0683p000009LxSN.png

 

 

 

Let me know

 

Thanks for your help so far...

Anonymous
Not applicable
Author

Also I have tried, casting the globalMap return object to String before concatenating it... 

 

"WHERE WalkDetails.Group_Code = '"+((String)globalMap.get("groupCode.areaCode"))+((String)globalMap.get("groupCode.groupNumber"))+"'"

 

this also did not work....

Anonymous
Not applicable
Author

Have you tried printing....

 

((String)globalMap.get("groupCode.areaCode"))+((String)globalMap.get("groupCode.groupNumber"))

...to the System.out? Are you SURE it will produce a value that will return records? 

Anonymous
Not applicable
Author

Hi, There was an option to provide query params in the component API mapping.
look in component documentation “query“
And add the the 2 fields you are looking for in the schema as comment col (query)
Anonymous
Not applicable
Author

Okay so I have simplified it and just add one parameter  and just for a minute lets forget the SQL...All I want is to pass a parameter and have the flow acknowledge the receipt of that parameter and print the value that I passed....

 

0683p000009LxIK.png

0683p000009LxXA.png

 

I have added a Java Component to print the value of this parameter..

 

0683p000009LxJu.png

 

when I run this...

 

0683p000009LxP2.png

 

the output shows that the values in the parameters are null.

 

0683p000009LxhF.png

Anonymous
Not applicable
Author

I have added the 'query' in the comment field in the schema...the screen shot shows it.

Anonymous
Not applicable
Author

Append to your url in browser ?param=value
Anonymous
Not applicable
Author

I tried these ...

 

http://localhost:8088/walkDetails?areaCode=ES50

http://localhost:8088/walkDetails?param=ES50

http://localhost:8088/walkDetails/areaCode=ES50

 

none of them picks up the value of 'ES50' and passes it to the REST...