I have a simple authorization routine. I copied much of the code from the recent OATH2 post. I POST a clientId and clientSecret to a webservice and it returns an expires variable and an access token variable in JSON. I'm trying to use the DATA-INTO procedure to parse the JSON.
I'm able to retrieve the resultstr vaiable and it appears to be formatted correctly. When the code hits the DATA-INTO code, I get the error: "The document for the DATA-INTO operation does not match the RPG variable". I've reviewed the related posts but haven't found an answer. Can anyone help?
I believe I have the qualifying variables set up correctly to match the return string.
resultStr displays as: {"Expires":180,"AccessToken":"xxxx... ...xxx"}
Code: Select all
H DFTACTGRP(*NO)
H BNDDIR('HTTPAPI':'YAJL')
/include yajl_h
/copy httpapi_h
dcl-s clientid varchar(4096) inz(
'xxxxxxxxxxxxxxxxxxxxxxx');
dcl-s clientsecret varchar(4096) inz(
'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$');
dcl-s sendData varchar(16384);
dcl-ds authResult qualified;
Expires int(3);
AccessToken varchar(4096);
end-ds;
dcl-s resultStr varchar(16000000);
d msg s 52A
d rc s 10I 0
http_debug(*on);
*inlr = *on;
//
// Build the variables
//
sendData = 'clientId=' + http_urlEncode(clientid)
+ '&clientSecret=' + http_urlEncode(clientsecret);
//
// post the credentials to retrieve the token
//
rc = http_req( 'POST'
:'https://xxxx.com/api/authenticate'
: *omit
: resultStr // String to receive the results
: *omit
: sendData
: 'application/x-www-form-urlencoded');
//
// error checking
//
if (rc <> 1);
msg = http_error();
dsply msg;
return;
else;
msg = resultStr;
dsply msg;
data-into authResult %DATA(resultStr)
%PARSER('YAJLINTO');
endif;
return;