Never mind. I figured it out. I am still new to this, and did not really understand the difference between a *PATH_PARAM input source and a *QUERY_PARAM input source.
URI path template for method:
/getonestudent
Input source:
*QUERY_PARAM
Identifier:
student_id
URL to consume the REST API:
http://mysystem:myport/web/services/examscores/getonestudent?student_id=12345
This worked.
Thanks,
Kelly Cookson
Senior Software Engineer II
Dot Foods, Inc.
1-217-773-4486 ext. 12676
www.dotfoods.com<
http://www.dotfoods.com>
From: Kelly Cookson
Sent: Sunday, October 25, 2020 7:52 PM
To: Web Enabling the IBM i (AS/400 and iSeries) <web400@xxxxxxxxxxxxxxxxxx>
Subject: Calling a stored procedure from an IWS REST API - parameter problem
I want to call a SQL stored procedure using an IWS REST API. I have it working as long as I hardcode all stored procedure parameters in the SQL call statement. I can't get it to work when I try to pass in parameters in the REST API request.
My stored procedure is named MYSPROC. It contains 5 parameters.
(IN ACTION_PARM CHAR (20),
IN PARM_STUDENT_ID INT DEFAULT NULL,
IN PARM_FIRST_NAME CHAR (30) DEFAULT NULL,
IN PARM_LAST_NAME CHAR (30) DEFAULT NULL,
IN PARM_EXAM_NAME CHAR (15) DEFAULT NULL,
IN PARM_EXAM_SCORE INT DEFAULT NULL)
I have created a REST API in an IWS web services server. Here are the details:
* Base resource URL:
http://mysystem:myport/web/services/examscores
* Procedure name:
getonescore
* Procedure SQL statement:
CALL MYSPROC ('GETONESCORE',12345,' ',' ','20 FALL FINAL',0)
* HTTP request method:
GET
* The URI path template for method is:
/getonescore
This works. The URI "
http://mysystem:myport/web/services/examscores/getonescore" returns the score for student 12345 on the 20 FALL FINAL exam.
Now, I would like to switch out the hardcoded values for input parameters. I would like to get the same result as above, but pass in a student ID number and an exam name. I had imagined a URI something like this:
http://mysystem:myport/web/services/examscores/getonescore?PARM_STUDENT_ID=12345&PARM_EXAM_NAME="20<
http://mysystem:myport/web/services/examscores/getonescore?PARM_STUDENT_ID=12345&PARM_EXAM_NAME=%2220> FALL FINAL"
I redeployed the same procedure with a few modifications. Here are the details:
* Procedure name:
getonescore
* Procedure SQL statement:
CALL MYSPROC ('GETONESCORE',?,' ',' ',?,0)
PARM_STUDENT_ID input INTEGER
PARM_EXAM_NAME input CHAR
* HTTP request method:
GET
* The URI path template for method is...
This is where I think that I'm falling down. No matter what I try, I cannot seem to create a URI path template that will accept the parameters.
According to RCF 6570, this URI template:
/foo{?query,number}
is supposed to expand to this URI:
/foo?query=mycelium&number=100
So I tried this as a URI path template for the method:
/getonescore{?PARM_STUDENT_ID,PARM_EXAM_SCORE}
using *PATH_PARAM. But it didn't work.
I tried all kinds of variations:
/getonescore{?PARM_STUDENT_ID&PARM_EXAM_SCORE}
/gentonescore?{PARM_STUDENT_ID}{PARM_EXAM_SCORE}
/gentonescore?{PARM_STUDENT_ID}&{PARM_EXAM_SCORE}
/getonescore/{?PARM_STUDENT_ID,PARM_EXAM_SCORE}
Most of the time I get 404 Resource Not Found messages.
Any help with getting a correct URI path template for the method would be appreciated.
Thanks,
Kelly Cookson
Senior Software Engineer II
Dot Foods, Inc.
1-217-773-4486 ext. 12676
www.dotfoods.com<
http://www.dotfoods.com>
As an Amazon Associate we earn from qualifying purchases.