1. Thomas Chiu
  2. PowerBuilder
  3. Friday, 15 May 2020 15:34 PM UTC

We are trying to use the new RESTClient object to call some internally developed REST services (Appeon Powerbuilder 2019 R2 Build 2328)

This REST service requires several parameters that acts as filters for the actual data retrieval.  Because of this, we have to pass a JSON string as part of the REQUEST BODY to the "GET" REST service.

For example, the REQUEST BODY would contain something like this:

[
{
"soldToCustomers": [
{
"customerID": "000001"
}
],
"documentDateFrom": "2019-01-23",
"documentDateTo": "2019-05-25",
"salesOrderStatus": "ALL"
}
]

Does the RESTClient object allow us to attach a REQUEST BODY to the GET function (either the Retrieve method or the SendGetRequest method).  

Or does the RESTClient only accept "Path Parameters" right now?  

 

mike S Accepted Answer Pending Moderation
  1. Friday, 15 May 2020 15:55 PM UTC
  2. PowerBuilder
  3. # 1

see retrieve method from restclient:

objectname.Retrieve ( dwControl, urlName {, data} {, tokenrequest} )

 

In help, example #4 is sending JSON data 

 

 

Comment
  1. Miguel Leeuwe
  2. Saturday, 16 May 2020 13:46 PM UTC
I'm a noob on this, but what if you first do a POST to set whatever instance variable you might define on the server and then do a GET which makes use of that previously set variable?
  1. Helpful
  1. mike S
  2. Saturday, 16 May 2020 15:34 PM UTC
It can be done, but since it is stateless you would have to store that value somewhere (database or something) along with an id, then retrieve it back using that id. a lot of work for no benefit. However, that is pretty much what you would do if the post kicks off a long running process; you poll using (usually) get to see if it finished or not. So if it is a process that you want an immediate reply to, then you would either use a different verb (post), or use HTTPclient.











  1. Helpful
  1. Miguel Leeuwe
  2. Sunday, 17 May 2020 08:21 AM UTC
Thanks for the explanation Mike, yes, later I also thought about it a bit more and it would mean extra roundtrips.
  1. Helpful
There are no comments made yet.
Mark Lee @Appeon Accepted Answer Pending Moderation
  1. Monday, 18 May 2020 09:33 AM UTC
  2. PowerBuilder
  3. # 2

Hi Thomas, 

For your issue, I suggest that you can use the httpclient object instead of the Restclient object to test if it works:

You can refer to the following link for details:

https://docs.appeon.com/appeon_online_help/pb2019r2/powerscript_reference/ch10s684.html

objectname.SendRequest ( methodName, urlName, string data )

 And the string data argument value is the JSON string as part of the REQUEST BODY. 

 

If you still want to use the RestClient object, in theory, I think that you can use the SendGetRequest or SendPatchRequest or SendPostRequest or SendPutRequest function.

https://docs.appeon.com/appeon_online_help/pb2019r2/powerscript_reference/ch10s682.html

But you must encode the JSON string as part of the REQUEST BODY to the end of the urlName argument (such as the URL + "?parm=value" ). 

e.g: www.appeon.com/?parm='your JSON string' 

After encode the urlName is :

 www.appeon.com/?parm= %5b%7b%22soldToCustomers%22%3a+%5b%7bcustomerID%22%3a+%22000001%22%7d%5d%2c%22documentDateFrom%22%3a+%222019-01-23%22%2c%22documentDateTo%22%3a+%222019-05-25%22%2c%22salesOrderStatus%22%3a+%22ALL%22%7d%5d

 

Comment
  1. Thomas Chiu
  2. Monday, 18 May 2020 12:15 PM UTC
Thanks for the suggestion!! I tried this and it does work. My JSON string shouldn't be very long so the potential to go over the browser URL limit should be a problem. Thanks!
  1. Helpful
  1. Mark Lee @Appeon
  2. Tuesday, 19 May 2020 01:10 AM UTC
Yes, the browser URLs have the length limitation.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.