I was able to get this to work. Thank you Daryl for the request header tip. All of this stuff is new to me.
I'm posting the PowerBuilder code I'm using to grab the ping access cookie, and the call to the API. Genericized, but you get the idea.
Just in case someone needs to cut and paste a code block for this specific use case.
int li_rc
string ls_body, ls_userid, ls_password, ls_apibody
HttpClient lnv_HttpClient
string as_partition, as_command
string ls_responsestatuscode, ls_responsestatustext, ls_all_headers, ls_response_body
string ls_response_body_suffix, ls_response_body_left, ls_response_api
string ls_cookie, ls_content_type, ls_csrfToken
Long ll_remove_end
ls_userid = "Dan"
ls_password = "*****"
ls_partition = "command_prefix"
ls_command = "command"
//Start the ping access cookie retrieval
ls_body = '{"userId":"' + ls_userid + '", "password": "'+ ls_password + '"}'
lnv_HttpClient = Create HttpClient
lnv_HttpClient.SetRequestHeader('Content-Type', 'application/json')
li_rc = lnv_HttpClient.SendRequest("POST", "https://pingaccess.com/ping/getPACookie", ls_body)
if li_rc = 1 then
ls_responsestatuscode = string(lnv_HttpClient.GetResponseStatusCode())
ls_responsestatustext = lnv_HttpClient.GetResponseStatusText()
ls_all_headers = lnv_HttpClient.GetResponseHeaders()
lnv_HttpClient.GetResponseBody(ls_response_body, EncodingUTF8!)
ls_response_body = Mid ( ls_response_body, 14 )
ll_remove_end = Pos(ls_response_body,",")
ls_response_body_left = Left (ls_response_body,ll_remove_end - 2)
ls_response_body_suffix = ls_response_body_left+ ";Path=/; Domain=company.com; Secure; HttpOnly;"
MessageBox('Debug', 'Response Status Code = ' + ls_responsestatuscode &
+ '~r~nResponse Status Text = ' + ls_responsestatustext &
+ '~r~nHeaders = ~r~n' + ls_all_headers &
+ '~r~nBody = ~r~n' + ls_response_body &
+ '~r~nSuffix = ~r~n' + ls_response_body_suffix)
else
MessageBox('Debug', 'Something went wrong.~r~nReturn Code = ' + string(li_rc))
end if
//End the ping access cookie retrieval
//Start the api call with ping access cookie
ls_apibody = '{"PartitionCode":"' + ls_partition + '", "Command": "'+ ls_command + '"}'
lnv_HttpClient.Clearrequestheaders( )
lnv_HttpClient.SetRequestHeader('Content-Type', 'application/json')
lnv_HttpClient.SetRequestHeader('CSRFToken', 'Tokenbypass')
lnv_HttpClient.SetRequestHeader( "cookie", ls_response_body_suffix)
ls_content_type = lnv_HttpClient.GetRequestHeader( "content-type")
ls_csrfToken = lnv_HttpClient.GetRequestHeader( "CSRFToken")
ls_cookie = lnv_HttpClient.GetRequestHeader( "cookie")
li_rc = lnv_HttpClient.SendRequest("POST", "https://restapi.com/swagger/api/callapi/", ls_apibody)
if li_rc = 1 then
ls_responsestatuscode = string(lnv_HttpClient.GetResponseStatusCode())
ls_responsestatustext = lnv_HttpClient.GetResponseStatusText()
ls_all_headers = lnv_HttpClient.GetResponseHeaders()
lnv_HttpClient.GetResponseBody(ls_response_api, EncodingUTF8!)
MessageBox('Debug', 'Response Status Code = ' + ls_responsestatuscode &
+ '~r~nResponse Status Text = ' + ls_responsestatustext &
+ '~r~nHeaders = ~r~n' + ls_all_headers &
+ '~r~nBody = ~r~n' + ls_response_api)
else
MessageBox('Debug', 'Something went wrong.~r~nReturn Code = ' + string(li_rc))
end if
//End the api call with ping access cookie
destroy lnv_HttpClient