I've only done one significant API project, Rene, so my experience is limited. But this one has been working fine for a year and a half and FWIW, this is the approach I took.
Other than getting the bearer token, my other interactions involve a ThisWebClient.Fetch method.
I've packaged that method in a separate Window procedure (SendGetPacket), and each of the data items I'm calling uses that procedure.
The prototype for SendGetPacket is (STRING pURL, STRING pToken,StringTheory pST),LONG
The URL is built by the calling procedure to have exactly what is needed for this particular fetch. The token is... um... the bearer token. And the StringTheory object is what will receive the data in the calling procedure.
On EVENT:OpenWindow, SendGetPacket runs the Fetch code I pasted in my earlier message.
There's the ErrorTrap code copied directly from Bruce's example.
There's no doubt a better way to do the next bit, but I wrote something that worked and haven't bothered trying to improve that. SendGetPacket has its own StringTheory object (ST1) which I just use to make sure there's a '200' success response in what I've received. LOC:RV is the LONG for the prototype's return.
In the ThisWebClient,PageReceived, after the parent, I have this code to remove the header and to put the body of what was received into the StringTheory object passed by the calling procedure:
st1.SetValue(ThisWebClient.ThisPage.GetValue())
ST1.split('<13>')
LOC:ResultLine = ST1.GetLine(1)
if Instring('200',LOC:ResultLine,1,1)
LOC:RV = TRUE
self.RemoveHeader()
pST.SetValue(ThisWebClient.ThisPage.GetValue())
ELSE
LOC:RV = FALSE
if Instring('ERROR',upper(LOC:ResultLine),1,1)
AddErrorLog(LOC:ResultLine)
loop ERR# = 1 to ST1.Records()
if instring('detailedm',ST1.GetLine(ERR#) ,1,1)
AddErrorLog(ST1.GetLine(ERR#))
BREAK
end ! if
end ! loop
end ! if
end ! if
post(event:closewindow)
The procedures calling this are also Window procedures, and I have one of them customized for each data item I'm receiving (doctors, patient appointments, service locations, etc.)
The "Web" object below is a simple class I wrote derived from StringTheory to built the parameter string URLs for the API calls.
As you can see, I basically prepare the URL, call my ClientSendPacket and pass it that URL and my calling StringTheory object.
Then load the contents of the StringTheory object into a jfiles object and do whatever processing after that.
ST.start()
web.ClearParms()
web.SetBaseURL(clip(GLO:PracticeID)&'/departments' )
web.AddParm('showalldepartments='&choose(pShowAllDepts,'true','false') )
web.AddParm('providerlist='&choose(pProviderList,'true','false') )
ClientSendPacket(web.GetURL(),ST)
JsonData.Start
JsonData.SetTagCase(jf:CaseAny)
JSONData.Load(ST)
HTH
Cheers,
Jane