Proclaim REST Services / JSON templates

Discuss your general Proclaim related queries here.
gcs
Posts: 2
Joined: Wed Mar 31, 2021 8:40 am

Proclaim REST Services / JSON templates

Post by gcs »

Hi All,

I've come up against an issue in REST services/creating JSON templates. Eclipse tell me that REST services/JSON templates currently do not support boolean or double data types and can only pass string values (enclosed in " ") - Apparently there is no way around this and it will be addressed in the next release.

I'm just wondering if anyone else has encountered this issue and has managed to find a way around it?

Thanks in advance

Gina

steve
Posts: 447
Joined: Wed Nov 30, 2011 10:20 pm
Been thanked: 106 times

Re: Proclaim REST Services / JSON templates

Post by steve »

Hi,
it works if you do the json parsing in maths
e.g.

Code: Select all

{
	"myBool":true,
	"myDouble":1.23
}
then in LA/Maths: (pseudocode):

Code: Select all

# Call rest, localise the response and convert to json obj
RESTSERVICE ("TEST01","test01","op-EntityString")
JSON-OBJECT-FROMFILE( json , op-EntityString ) 
#
# or construct from local json file
JSON-OBJECT-FROMFILE( json , "c:\temp\test.json" ) 
#
# grab values to local variables
v1 = JSON-GET-PROPERTY( json , "myBool" ) 
v2 = JSON-GET-PROPERTY( json , "myDouble" ) 
#
# convert to option y/n and Decimal
IF v1 = "true" THEN 
    PUT( "yes" , {temp option yn.Code} )  
ELSE 
    PUT( "no" , {temp option yn.Code} ) 
END 
#
# TODO for the decimal: sanity check valid chars - must only be numeric chars + fullstop and begin with a number 
# e.g https://www.proclaimforum.co.uk/viewtopic.php?t=245
PUT( v2 , {temp value.Value} ) 
MESSAGE( "option: " , {temp option yn.Code} , NEWLINE , "value: " , {temp value.Value} )

gcs
Posts: 2
Joined: Wed Mar 31, 2021 8:40 am

Re: Proclaim REST Services / JSON templates

Post by gcs »

Thanks Steve, this is really helpful :)

I'm guessing this approach would only work for parsing the json response and not constructing the request? The request I'm sending has a mandatory boolean & double and fails if I construct the request within a proclaim json template. (due to the "")

I can't think of an easy way to construct a json request / file using maths. Although messy, I could potentially use string manipulation to create the request content, but can't figure out a way of creating the actual .json file for the rest service to send. :?

Thanks

Gina

steve
Posts: 447
Joined: Wed Nov 30, 2011 10:20 pm
Been thanked: 106 times

Re: Proclaim REST Services / JSON templates

Post by steve »

Ah, outbound fields, hmm I can't see how to override those sorry, other than some hacky external proxy webservice that rewrites the request.
https://stackoverflow.com/questions/301 ... ipt-object

You've probably tried, but out of curiosity I tried to create the json object in Maths and add it to a template, but too fails

Code: Select all

result = CHR( 123 ) + CHR( 34 ) + "myBool" + CHR( 34 ) + ": true " + CHR( 125 ) 
then add this to a json template (your service would rely on a nested structure), but it fails:

Code: Select all

{
  "data": "{\"myBool\": true }"
}

revellbikes
Posts: 473
Joined: Fri Jun 15, 2012 12:44 pm
Has thanked: 15 times
Been thanked: 48 times

Re: Proclaim REST Services / JSON templates

Post by revellbikes »

We've experienced the same issue. Thankfully an internally created REST service so could code around it outside of Proclaim. It will need to be sorted by Eclipse for the up coming PI reforms as they're restful I am lead to believe.