I have the oauth/token API working in Postman, but can't seem to get it right in the RPG. I am looking for any help I can get.
The url is https://partycity-sandbox-api.cbxcloud.com/oauth/token.
In Postman it shows the HTTP code snippet as:
Code: Select all
POST /oauth/token HTTP/1.1
Host: partycity-sandbox.cbxcloud.com
Content-Type: application/x-www-form-urlencoded
Authorization: Basic Y2J4OmNieEAxMjM=
Content-Length: 78
username=<our userid>&password=<our pwd>&grant_type=password
Code: Select all
Request = 'username='+ http_urlencode(Userid)
+ '&password='+http_urlencode(Pwd)
+'&grant_type=password';
URL = BaseURL + 'oauth/token';
rc = http_xproc(HTTP_POINT_ADDL_HEADER:%paddr(add_Auth_headers));
rc = http_req( 'POST'
: URL
: *omit
: response
: *omit
: request );
// : 'application/x-www-form-urlencoded');
if rc <> 1;
msg = http_error();
dsply msg;
endif;
//-------------------------------------------------------------------------------
dcl-proc add_Auth_headers;
dcl-pi *n;
headers varchar(32767);
end-pi;
headers = 'Host: partycity-sandbox.cbxcloud.com' + crlf +
'Content-Type: application/x-www-form-urlencoded' + crlf +
'Authorization: Basic Y2J4OmNieEAxMjM=' + crlf +
'Content-Length: ' + %Char(%Len(%Trim(request))) + crlf;
Return;
end-proc;
I have also tried:
Code: Select all
Form = WEBFORM_open();
WEBFORM_SetVar(Form: 'username': userid);
WEBFORM_SetVar(Form: 'password': pwd);
WEBFORM_SetVar(Form: 'grant_type': 'password');
WEBFORM_postData( Form : myPointer: dataSize );
rc = http_url_post( URL
: myPointer
: dataSize
: '/edi/testurlpost.html'
: HTTP_TIMEOUT
: HTTP_USERAGENT
: 'application/x-www-form-urlencoded' );
if rc <> 1;
msg = http_error();
dsply msg;
endif;
// When done, make sure you call this function to free up
// the memory that the web form used
//
WEBFORM_close(Form);
I have tried setting HTTP_SetOption, HTTP_SetAuth, HTTP_POST, HTTP_STring and various combinations.
Any input would be greatly appreciated. I can't get by this first step of just getting the token and project has a date in August!