sqlrestrpgle

SQLSTATE=1H52/ SQLCODE=+462 with UPS API Tracking HTTPGETCLOBVERBOSE Request


I am new to REST API in RPGLE programming and after I get my POST Request fixed here POST Request, I know have a different problem with the GET for Tracking the UPS API

In the ACS Run SQL Script it works:

Select * from table(systools.httpgetclobverbose('https://wwwcie.ups.com/api/track/v1/details/xxxtrackingnumberxxx?locale=de_DE&returnSignature=false&returnMilestones=false&returnPOD=false',
'<httpHeader>
<header name="Authorization" value="Basic xxxacessTokenxxx(1308 charaters)"/>
<header name="transId" value="string"/>
<header name="transactionSrc" value="testing"/>
</httpHeader>'));

I have now a hard time to convert this into my RPG program. Here is the Definition and the code:

D myClob          S                   SQLType(CLOB:1000000) CCSID(1208) INZ
D respHeader      S                   SQLTYPE(CLOB:1000000) CCSID(1208) INZ
D myData          S         100000    VARYING INZ
D HEADER          S         100000    VARYING INZ
D myHeader        S           2000    VARYING INZ
D myUrl           S            512A   VARYING INZ
D accessToken     S           1500A
D null            S              2B 0 INZ  

C* HTTPPOST receives the accessToken here
    
C                   EVAL      myURL = 'https://wwwcie.ups.com/api/track/v1'
C                             +'/details/xxtrackingnumberxx?locale=en_US&r'
C                             +'eturnSignature=false&returnMilestones=fals'
C                             +'e&returnPOD=false'
C                   EVAL      myheader='<httpHeader><header name="Authoriz'
C                             +'ation" value="Basic '+%TRIM(accessToken)
C                             +'"/><header'
C                             +' name="transId" value="string"/><header na'
C                             +'me="transactionSrc" value="testing"/></htt'
C                             +'pHeader>'
C                   RESET                   respHeader
C                   RESET                   HEADER
C
C/EXEC SQL
C+ SELECT  CAST(RESPONSEMSG AS CLOB(1000000)),
C+         CAST(responseHttpHeader  AS CLOB(1000000))
C+         INTO :myClob:null,  :respHeader
C+         FROM TABLE( SYSTOOLS.HTTPGETCLOBVerbose(
C+                    CAST(:myURL AS VARCHAR(512)),
C+                    CAST (:myheader AS CLOB(2K))))
C/END-EXEC
C
C                   EVAL      myData = %SUBST(myClob_data:1:myClob_len)
C                   EVAL      HEADER   = %SUBST(respHeader_DATA:1:
C                                                 respHeader_LEN)

myClob_data is empty as well as respHeader_DATA. Both LEN is 0. SQLCOD = +462 SQLSTATE = 01H52 Very hard to find a lot of Infomation about those, but I was able to find more description here: IBM Memo to Users at page 22.

• The SQL statement fails to parse or The SQL statement parameter value is a blank string or NULL

I guess I have something that is formated or define incorrectly. I also get the same result with that:

Select * into :myClob:W_NULL, :W_RSPHDR from TABLE(SYSTOOLS.HTTPGETCLOBVerbose(:myURL, :myHeader).

The RDI debugger is not working. For some reason I get a decimal error in my program by a Code that isnt mention here. So I have to use the STRDBG. But it only shows 1025 characters when I use "EVAL myheader" and as the access token is 1308 characters long, I dont know how to see the full myHeader.

And as Charles mention in my previous question to look into QSYS2.HTTP_ or HTTPAPI by Scott, I can't right now sadly. Also dont wondering about the fixed form of RPG. I have to use it, but you can answer with free RPG ofc.

The SYSTOOLS works, I just need to convert it correctly, I think.. Thank you in advance.


Solution

  • I got the issue. As I mentioned, I was not able to see the end of my variables in STRDBG. To see it anyway, I just made multiple 1000 character long variables and substringed it all into them. The access token was not properly substringed by my code. I mixed up the length with the endposition in %SUBST. Now I get the expected result with the GET reqeust.