How to Send / Receive JSON to LANSA WAMS

This is some cool stuff.  I need to refresh some files on our application server from some presentation servers on AWS.  Here is my example so I don’t forget how to do this.  I hope this helps.

The easiest way to approach this is to build a wam *json that just dumps the file out.

  • JSONINPT WAM Below

Function Options(*DIRECT)
Begin_Com Role(*EXTENDS #PRIM_WAM) Layoutweblet(‘std_blank_layout’)

Webroutine Name(ShowWork) Response(*JSON)
Web_Map For(*OUTPUT) Fields(#outlist)

Def_List Name(#outlist) Fields(#EDIV #ESTAT #EPACH #EDNAM #EIMAG002 #EIMAG2001 #EIMAG3 #EHOMB #EHOMS #ETHEM #EDESG #ERETL #ERESD #ECOMD #EPR #EEXTR1 #EEXTR2 #ECRUSR) Type(*Working) Entrys(*MAX)

#std_num := 0

*
Select Fields(#EDIV #ESTAT #EPACH #EDNAM #EIMAG002 #EIMAG2001 #EIMAG3 #EHOMB #EHOMS #ETHEM #EDESG #ERETL #ERESD #ECOMD #EPR #EEXTR1 #EEXTR2 #ECRUSR) From_File(M55E100)
Add_Entry To_List(#outlist)
#std_num := #std_num + 1
*
Leave If(#STD_NUM *GT 9)
Endselect

Endroutine

YOURLANSASERVER/CGI-BIN/lansaweb?wam=JSONINPT&webrtn=ShowWork&ml=LANSA:XHTML&part=YWD&lang=ENG

 

THIS IS the OUTPUT WHEN FILE IS EMPTY

{“webroutine”:{“context”:{“action-request”:”/CGI-BIN/lansaweb”,”dec-separator”:”.”,”images-path”:”/IMAGES”,”iso-lang”:”en”,”language”:”ENG”,”partition”:”YWD”,”service-name”:”JSONINPT_ShowWork”,”session-key”:””,”session-key-method”:”hidden”,”session-key-name”:”_SESSIONKEY”,”technology-service”:”LANSA:XHTML”,”user-id”:”LANDEVPGM”,”webapplication”:”JSONINPT”,”webapplication-title”:”Test JSON input”,”webroutine”:”ShowWork”,”webroutine-title”:””},”lists”:{“OUTLIST”:{“header”:[{“name”:”EDIV”},{“name”:”ESTAT”},{“name”:”EPACH”},{“name”:”EDNAM”},{“name”:”EIMAG002″},{“name”:”EIMAG2001″},{“name”:”EIMAG3″},{“name”:”EHOMB”},{“name”:”EHOMS”},{“name”:”ETHEM”},{“name”:”EDESG”},{“name”:”ERETL”},{“name”:”ERESD”},{“name”:”ECOMD”},{“name”:”EPR”},{“name”:”EEXTR1″},{“name”:”EEXTR2″},{“name”:”ECRUSR”}],”entries”:[]}}}}

This is input with one entry in list

{“webroutine”:{“fields”:{“STD_NUM”:{“value”:1}},”lists”:{“MYLIST”:{“header”:[{“name”:”EDIV”},{“name”:”ESTAT”},{“name”:”EPACH”},{“name”:”EDNAM”},{“name”:”EIMAG002″},{“name”:”EIMAG2001″},{“name”:”EIMAG3″},{“name”:”EHOMB”},{“name”:”EHOMS”},{“name”:”ETHEM”},{“name”:”EDESG”},{“name”:”ERETL”},{“name”:”ERESD”},{“name”:”ECOMD”},{“name”:”EPR”},{“name”:”EEXTR1″},{“name”:”EEXTR2″},{“name”:”ECRUSR”}],”entries”:[[“ALL”,”P”,”P”,”Studio Source”,”/IMG/PRODUCTS/BRANDS/MASTHEAD/MAGNUMSOURCEMASTHEAD”,””,”/IMG/PRODUCTS/BRANDS/LOGOS/MAGNUMSOURCELOGO”,”N”,”N”,”N”,”N”,”N”,”Y”,”Y”,”Y”,””,””,””]]}}}}

 

This is WAM ROUTINE TO DIGEST JSON

Webroutine Name(TEST) Response(*JSON)

Web_Map For(*both) Fields(#STD_NUM)
Web_Map For(*input) Fields(#mylist)
Web_Map For(*output) Fields(#mylist2)
Def_List Name(#mylist) Fields(#EDIV #ESTAT #EPACH #EDNAM #EIMAG002 #EIMAG2001 #EIMAG3 #EHOMB #EHOMS #ETHEM #EDESG #ERETL #ERESD #ECOMD #EPR #EEXTR1 #EEXTR2 #ECRUSR) Type(*Working) Entrys(*MAX)
Def_List Name(#mylist2) Fields(#EDIV #ESTAT #EPACH #EDNAM #EIMAG002 #EIMAG2001 #EIMAG3 #EHOMB #EHOMS #ETHEM #EDESG #ERETL #ERESD #ECOMD #EPR #EEXTR1 #EEXTR2 #ECRUSR) Type(*Working) Entrys(*MAX)
#std_num := #std_num + 1

 

Clr_List Named(#mylist2)

Selectlist Named(#mylist)
Insert Fields(#EDIV #ESTAT #EPACH #EDNAM #EIMAG002 #EIMAG2001 #EIMAG3 #EHOMB #EHOMS #ETHEM #EDESG #ERETL #ERESD #ECOMD #EPR #EEXTR1 #EEXTR2 #ECRUSR) To_File(M55E100) Issue_Msg(*YES)
Add_Entry To_List(#mylist2)
Endselect

 

Endroutine

 

OK Now the FUN PART.  You will download fiddler to send the JSON Data.  Look at picture.   Also, I am available for projects..

Click on the Composer tab

COPY your URLand Select POST http/1.1
and use

Host: YOURURL
Content-Length: 0
Content-Type: application/json; charset=UTF-8

PUT YOUR JSON in THE REQUEST BODY

 

WAM JSON
LANSA WAM JSON EXAMPLE