API REST with LI 14.0

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
User avatar
Fabrice.geay
Posts: 19
Joined: Tue Dec 12, 2017 2:06 am
Location: FRANCE
Contact:

API REST with LI 14.0

Post by Fabrice.geay » Tue Jun 08, 2021 10:54 pm

Hy all,

i need to consume an REST API from EDM environnement. i have make the request on SOAP-ui and it works well, the document name was changed, but i do not have success with LI :
Command : ERROR "Erreur de réception de la réponse HTTP"
{"message":"[HttpMessageNotReadableException] Could not read JSON document: Unrecognized token 'clearCriterionList': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')\n at [Source: (PushbackInputStream); line: 1, column: 20]; nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'clearCriterionList': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')\n at [Source: (PushbackInputStream); line: 1, column: 20]"}

On SOAP-UI I used this URL :
http://servrged1/serviceweb/rest/api/us ... main/<parm 1>/base/<parm 2/document/<parm 3>/tag?clearCriterionList=false
"parm 1" is an identifiant of domains to work
"parm 2" is an identifiant of database to access
"parm 3" is the document id

I need also tha have in the body
{"criterionList": [{"categoryId": 38,"word": "ANNULE"},{"categoryId": 39,"word": " "},{"categoryId": 40,"word": " "},{"categoryId": 41,"word": " "}]}


With lansa i have used the HTTPService :

* Open service
Use Builtin(JSMX_OPEN) To_Get(£JSMXSTS £JSMXMSG £JSMXHDLE1)
* Load service
£JSMXCMD := 'SERVICE_LOAD SERVICE(HTTPService) SERViCE_CONTENT(*JSON)'
£JSMXCMD += ' TRACE(*YES) TRACE_NAME(APPEL_GED_REST)'
Use Builtin(JSMX_COMMAND) With_Args(£JSMXHDLE1 £JSMXCMD) To_Get(£JSMXSTS £JSMXMSG)
* Build POST Values
£W_NAME := 'clearCriterionList'
£W_VALUE := "false"
Add_Entry To_List(£LIST)

* Call the service£LIST
£JSMXCMD := 'SEND HANDLER(OutboundNameValue) HOST(' + £pHOSTname + ') URI(' + £pURIpath + ') METHOD(PATCH) SERVICE_LIST(W_NAME,W_VALUE) USER(webservice) PASSWORD(DOCUBASE) CONTENT(*JSON)'
Use Builtin(JSMX_COMMAND) With_Args(£JSMXHDLE1 £JSMXCMD) To_Get(£JSMXSTS £JSMXMSG £LIST)

i need help :(
Best regard

Fabrice GEAY

User avatar
Dino
Posts: 134
Joined: Fri Jul 19, 2019 7:49 am
Location: Robbinsville, NC
Contact:

Re: API REST with LI 14.0

Post by Dino » Fri Jun 11, 2021 7:21 am

I would think it will be something in this realm... this is a partial mockup/example based in other thing I did before... but you need to generate trace and check it to be sure the line it is correctly formed before is been sent. if you have the json file with the content already created, you dont need to use the JSONBINDFILESERVICE to parse fields into it.

Code: Select all

Def_List Name(#WRKLST) Fields(#ATNAME #ATVALUE) Type(*WORKING)
Clr_List Named(#WRKLST)
* watch out for lower and uppercase in the parameter
Change Field(#ATNAME) To('''clearCriterionList''')
Change Field(#ATVALUE) To('''false''')
Add_Entry To_List(#WRKLST)

* Open service
Use Builtin(JSM_OPEN) To_Get(#JSMSTS #JSMMSG)

* Load service
Change Field(#JSMCMD) To('SERVICE_LOAD SERVICE(JSONBINDFILESERVICE) TRACE(*YES)')
Use Builtin(JSM_COMMAND) With_Args(#JSMCMD) To_Get(#JSMSTS #JSMMSG)

* Bind service to create content
Change Field(#JSMCMD) To('BIND SERVICE(REQUESTREST888) TYPE(*OUTBOUND) SERVICE_EXCHANGE(*FIELD)')
Use Builtin(JSM_COMMAND) With_Args(#JSMCMD) To_Get(#JSMSTS #JSMMSG)

* Set fragment - DATA
Change Field(#JSMCMD) To('SET FRAGMENT(DATA) SERVICE_EXCHANGE(*FIELD)')
Use Builtin(JSM_COMMAND) With_Args(#JSMCMD) To_Get(#JSMSTS #JSMMSG)

* Write content
Change Field(#JSMCMD) To('WRITE FILE( criterionListjsonDocument.json) INDENT(*YES) BINDTRACE(*YES)')
Use Builtin(JSM_COMMAND) With_Args(#JSMCMD) To_Get(#JSMSTS #JSMMSG)

* Unload service
Use Builtin(JSM_COMMAND) With_Args('SERVICE_UNLOAD') To_Get(#JSMSTS #JSMMSG)

* Load service
Change Field(#JSMCMD) To('SERVICE_LOAD SERVICE(HTTPSERVICE) TRACE(*YES)')
Use Builtin(JSM_COMMAND) With_Args(#JSMCMD) To_Get(#JSMSTS #JSMMSG)

* Access the URL 
Change Field(#JSMCMD) To('''SEND HOST(servged1) URI(/serviceweb/rest/api/us...main/) SECURE(*YES) HANDLER(OutboundNameValue) METHOD(POST) WAIT(*YES) #WRKLST(NAME,VALUE) SERVICE_LIST(ATNAME,ATVALUE)''')
Use Builtin(JSM_COMMAND) With_Args(#JSMCMD) To_Get(#JSMSTS #JSMMSG #WRKLST)

* Receive
Change Field(#JSMCMD) To('RECEIVE HANDLER(IFILE) CONTENT(*JSON) TO(receivedjson.json)')
Use Builtin(JSM_COMMAND) With_Args(#JSMCMD) To_Get(#JSMSTS #JSMMSG)

* Unload service
Use Builtin(JSM_COMMAND) With_Args('SERVICE_UNLOAD') To_Get(#JSMSTS #JSMMSG)

* Load service
Change Field(#JSMCMD) To('SERVICE_LOAD SERVICE(JSONBindFileService) TRACE(*YES)')
Use Builtin(JSM_COMMAND) With_Args(#JSMCMD) To_Get(#JSMSTS #JSMMSG)

* Receive the content and put in a temporary file
Change Field(#JSMCMD) To('READ FILE(receivedjson.json)')
Use Builtin(JSM_COMMAND) With_Args(#JSMCMD) To_Get(#JSMSTS #JSMMSG)

* Bind service to read HTTP request content
Change Field(#JSMCMD) To('BIND SERVICE(REST888BW) TYPE(*INBOUND) BINDTRACE(*YES) SERVICE_EXCHANGE(*FIELD) CONTENT(*JSON)')
Use Builtin(JSM_COMMAND) With_Args(#JSMCMD) To_Get(#JSMSTS #JSMMSG)

* Unload service
Use Builtin(JSM_COMMAND) With_Args('SERVICE_UNLOAD') To_Get(#JSMSTS #JSMMSG)

* Close service
Use Builtin(JSM_CLOSE) To_Get(#JSMSTS #JSMMSG)


User avatar
Dino
Posts: 134
Joined: Fri Jul 19, 2019 7:49 am
Location: Robbinsville, NC
Contact:

Re: API REST with LI 14.0

Post by Dino » Fri Jun 11, 2021 7:28 am

Also you could send the clearCriterionList in the URI:

Code: Select all

SEND HOST(servged1) URI(/serviceweb/rest/...../tag?clearCriterionList=false) ....

User avatar
Fabrice.geay
Posts: 19
Joined: Tue Dec 12, 2017 2:06 am
Location: FRANCE
Contact:

Re: API REST with LI 14.0

Post by Fabrice.geay » Mon Jun 14, 2021 7:37 pm

Thank Dino for your response.

I go try.
Best regard

Fabrice GEAY

User avatar
Fabrice.geay
Posts: 19
Joined: Tue Dec 12, 2017 2:06 am
Location: FRANCE
Contact:

Re: API REST with LI 14.0

Post by Fabrice.geay » Wed Jun 16, 2021 12:01 am

bad way,

:(
Best regard

Fabrice GEAY

User avatar
Dino
Posts: 134
Joined: Fri Jul 19, 2019 7:49 am
Location: Robbinsville, NC
Contact:

Re: API REST with LI 14.0

Post by Dino » Wed Jun 16, 2021 1:09 am

got any trace?

Post Reply