Establish Connection & Store Cookie
Trouble seeing the images? Right click on images and open in new tab to enlarge or zoom in on the page (Ctrl + mousewheel).
In this article we provide an example API call to establish your connection and store cookies.
Why Establish Connection & Store Cookie?
This is needed to establish the connection and store the cookie on a successful login attempt. This will allow you to do API calls to the API client.
Video Tutorial:
Not yet available.
Example API to Establish Connection & Store Cookie
Note: This is an example.
Con.cookieContainer = New CookieContainer
Con.handler = New Http.HttpClientHandler With {.CookieContainer = Con.cookieContainer, .UseDefaultCredentials = Con.DConnection.Trusted}
Con.client = New HttpClient(Con.handler)
Con.client.Timeout = TimeSpan.FromHours(24)
Dim Param = New WROpenParameter With {
.UserName = Username,
.Password = Password
}
Dim URL As String = ""
URL = Con.DConnection.Server & "/api/ServiceAccount/Login"
Dim Params As StringContent = New StringContent(JsonConvert.SerializeObject(Param, Formatting.Indented), Encoding.UTF8, "application/json")
Con.openResponse = Con.client.PostAsync(URL, Params).GetAwaiter().GetResult()
If Con.openResponse.IsSuccessStatusCode Then
Dim loginResponse = Con.openResponse.Content.ReadAsStringAsync().GetAwaiter().GetResult()
Dim loginInfo = JsonConvert.DeserializeObject(Of OktaToken)(loginResponse)
Con.client.DefaultRequestHeaders.Authorization = New Headers.AuthenticationHeaderValue("Bearer", loginInfo.AccessToken)
Con.cookieContainer.GetCookies(New Uri(URL))
If loginInfo.MFA Then
Return "MFA"
End If
Return "Success"
Else
Return Con.openResponse.Content.ReadAsStringAsync().GetAwaiter().GetResult()
End If
Once you have established a connection, click here for API call examples.
Comments
0 comments
Please sign in to leave a comment.