"C'mon, Man!"
TMYour post asks about ThisPage, RemoveHeader, and ServerResponse but you wanted the reply to be about how to use a token.
"C'mon, Man!"
TM In working with APIs I've found the best strategy FOR ME has been
1. Make it work with Postman
2. Using the Postman stuff as a guide, make it work with the NetDemo app.
3. Having figured that out, code it into my app.
In my apps that need to call an API I typically have two procedures.
1. Fetches a token. In my case, it first checks to see whether it has an existing token available that hasn't expired.
2. A generic "fetch stuff" API call.
The "fetch stuff" procedure (sendGetPacket) is a generic window procedure having a prototype of
(STRING pURL, STRING pToken,StringTheory pST),LONG
The procedure that wants to fetch something creates the URL for the endpoint creates the required URL and passes the URL, the token, and a String Theory object to the sendGetPacket procedure. When it's done, the StringTheory parameter contains what I've fetched from the API endpoint and I do what I do with it in the calling procedure.
The sentGetPacket has this code, much of which is snipped out of the NetDemo web client procedure.
PacketSend ROUTINE
DATA
CODE
ThisWebClient.SetAllHeadersDefault()
ThisWebClient.HeaderOnly = 0
ThisWebClient.Cookie = ''
ThisWebClient.CustomHeader = 'Authorization: Bearer '&clip(pToken)
ThisWebClient.Referer = ''
ThisWebClient.AsyncOpenTimeOut = 2200 ! 22 seconds
ThisWebClient.InActiveTimeout = GLO:QueryTimeout ! 6000 ! 20 seconds
ThisWebClient.SSLMethod = NET:SSLMethodTLS
ThisWebClient.HTTPVersion = 'HTTP/1.1'
ThisWebClient.ContentType = 'application/x-www-form-urlencoded'
ThisWebClient.ConnectionKeepAlive = FALSE
ThisWebClient.CanUseProxy = GLO:CanUseProxy
ThisWebClient.ProxyServer = GLO:proxyServer
ThisWebClient.ProxyPort = GLO:proxyPort
ThisWebClient.Fetch(clip(pURL))
The EVENT:OpenWindow event has this embed
! End of "Window Event Handling"
OF EVENT:OpenWindow
! [Priority 5000]
DO PacketSend
Other embeds:
ThisWebClient.ErrorTrap PROCEDURE(string errorStr,string functionName)
! Start of "NetTalk Method Data Section"
! [Priority 5000]
! End of "NetTalk Method Data Section"
CODE
! Start of "NetTalk Method Executable Code Section"
! [Priority 2500]
if self.Error <> 0
ud.debug('error trap before parent '&clip(errorstr)&' '&clip(functionName)&' code='&ThisWebClient.Error)
AddLog('net client error '&clip(errorstr),0,0)
AddErrorLog('net client error '&clip(errorstr)&' url='&left(pURL,80))
post(event:closewindow)
end ! if
! Parent Call
PARENT.ErrorTrap(errorStr,functionName)
! [Priority 7500]
ThisWebClient.PageReceived PROCEDURE
! Start of "NetTalk Method Data Section"
! [Priority 5000]
! End of "NetTalk Method Data Section"
CODE
! Start of "NetTalk Method Executable Code Section"
! [Priority 2500]
! Parent Call
PARENT.PageReceived
! [Priority 7500]
IF self.ServerResponse = 200
self.RemoveHeader()
LOC:RV = TRUE
pST.SetValue(self.ThisPage.GetValue())
ELSE
LOC:RV = FALSE
END !IF
post(event:closewindow)
This is all OLD CODE I wrote 6 1/2 years ago, but it's been working fine since then. YMMV. Much of it, as mentioned, appropriated from the handy dandy NetDemo example program. UD is the ClarionLive UltimateDebug object.
[edited] because I couldn't stand looking at the ugly pageReceived code I posted so I tweaked that app I pulled this from. [/edited]
HINT - that NetDemo example is handy