'get the access token
Sub GetAccessToken() As ResumableSub
Log("GetAccessToken")
'set access token to blank
access_token = ""
Dim job As HttpJob
'initialize a http request
job.Initialize("",Me)
'pass the url to get the token
job.PostString("<endpoint>",$"grant_type=password&username=${userName}&password=${passWord}"$)
'set the content type
job.GetRequest.SetContentType("application/x-www-form-urlencoded")
'wait for the web service to complete
Wait For (job) JobDone(job As HttpJob)
If job.Success Then
'translate to a map
Dim strResponse As String = job.GetString
job.release
Dim access As Map = Json2Map(strResponse)
'assign variables
access_token = access.GetDefault("access_token","")
'save the token to a file
File.WriteString(File.DirApp,"access_token.txt",access_token)
Return True
Else
If File.Exists(File.DirApp,accessTokenFile) Then File.Delete(File.DirApp,accessTokenFile)
LogError($"A '${job.ErrorMessage}' has been experienced reading GetAccessToken!"$)
job.Release
Return False
End If
End Sub