1. Daniel Ferrreira
  2. PowerBuilder
  3. Monday, 15 March 2021 15:28 PM UTC

Hello folks,

I'm calling a woocommerce API using PB REST Client. Using Postman it works, but when calling from PB (2019 R3 Build 2670), I get return code -14 (Code conversion failed).

I think it has to do with the headers, but I'm not being able to pin point what. Any advice? These are the prints for Postman and also my PB Script.

Thanks a lot.

iClientApi.ClearRequestHeaders()

iClientApi.SetRequestHeader('Authorization', 'Basic ' + is_authorization)
iClientApi.SetRequestHeader('Accept', '*/*')
iClientApi.SetRequestHeader('Accept-Encoding', 'gzip, deflate, br')
iClientApi.SetRequestHeader('Content-Encoding', 'br')
iClientApi.SetRequestHeader('Content-Type', 'application/json; charset=UTF-8')
iClientApi.SetRequestHeader('Connection', 'keep-alive')

 

 

Accepted Answer
Mark Lee @Appeon Accepted Answer Pending Moderation
  1. Tuesday, 16 March 2021 06:13 AM UTC
  2. PowerBuilder
  3. # Permalink

Hi Daniel,

 

Please refer to the help documentation below. Only gzip compression format is supported in PB at this moment. And it does not support any other format.

https://docs.appeon.com/pb2019r3/powerscript_reference/ch02s04s694.html 

If RESTClient fails to send a request or the server provides no response, the response value is an empty string. If the response value is compressed as gzip, it will be automatically decompressed. Only gzip compression format is supported at this moment. If the server specified the Content-Type response header, and in which the encoding charset is specified, this function will encode the data with the specified charset, if charset is not specified, this function will encode the data in UTF-8 by default.

 

Therefore, you need to modify the code below:

iClientApi.SetRequestHeader('Accept-Encoding', 'gzip, deflate, br')
iClientApi.SetRequestHeader('Content-Encoding', 'br')

to:

iClientApi.SetRequestHeader('Accept-Encoding', 'gzip')
iClientApi.SetRequestHeader('Content-Encoding', 'gzip')


Other related sample code can be found below:

https://docs.appeon.com/pb2019r3/application_techniques/ch04s07.html#d0e14110 


In addition, if your REST API only supports br Encoding and not GZIP, then the API may not be invoked in PB.

 

Regards,

Comment
  1. Daniel Ferrreira
  2. Tuesday, 16 March 2021 12:22 PM UTC
Mark, thank you very much!

Fortunately woocommerce API accepts gzip, so it worked! There's an interesting issue that my calls to other e-commerce are using SetRequestHeader('Accept-Encoding', 'gzip, deflate, br'), but this is the first time using Content-Encoding. But using both as gzip has worked, thanks a lot!

  1. Helpful
There are no comments made yet.


There are replies in this question but you are not allowed to view the replies from this question.