I am working on a project and need to pass HTTP request header for token Generation and use the token to pass other parameters for other endpoints. Each endpoint call is a combination of header and parameter call as indicated below. I am a new to this and running out of time and struggling figure it out. Any one who will like to work with me on this and also support in future snippets for a cost.
sub call
Private JOB As HttpJob
Private jsonstring As String
Private jp As JSONGenerator
Private jsonmap As Map
jsonmap.Initialize
jsonmap.Put("pos_id","1001")
' You can other things to the map here
jp.Initialize(jsonmap)
jsonstring = jp.ToString
' this is assuming your api was a POST.
JOB.Initialize("", Me)
JOB.PostString("localhost/payments_apis/index.php/pay/token",jsonstring)
JOB.Getrequest.SetContentType("application/json")
wait for (JOB) jobdone(jd As HttpJob)
If jd.Success Then
' add some appropriate error handling
Private jgen As JSONParser
jgen.Initialize(jd.GetString)
' assuming a JSON map is the return object
Private returnmap As Map = jgen.NextObject
Else
' handle error condition
End If
jd.Release
end sub
The second call is similar just need other items in the map.
to add the api key to the header you need
B4X:
JOB.GetRequest.SetHeader("api_key",token from token api) ' this is how you can add the api key to the header