Demonstrates how to get an OAuth2 Concur access token using the "client credentials" flow.
curl -X POST https://us.api.concursolutions.com/oauth2/v0/token \
-d "client_id=your-client_id" \
-d "client_secret=your-client_secret" \
-d "grant_type=client_credentials"
[Reflection.Assembly]::LoadFile("C:\myAssemblies\ChilkatDotNet2.dll")
$rest = New-Object Chilkat.Rest
# URL: https://us.api.concursolutions.com/oauth2/v0/token
$bTls = $true
$port = 443
$bAutoReconnect = $true
$success = $rest.Connect("us.api.concursolutions.com",$port,$bTls,$bAutoReconnect)
if ($success -ne $true) {
$("ConnectFailReason: " + $rest.ConnectFailReason)
$($rest.LastErrorText)
exit
}
$rest.AddQueryParam("client_id","your-client_id")
$rest.AddQueryParam("client_secret","your-client_secret")
$rest.AddQueryParam("grant_type","client_credentials")
$strResponseBody = $rest.FullRequestFormUrlEncoded("POST","/oauth2/v0/token")
if ($rest.LastMethodSuccess -ne $true) {
$($rest.LastErrorText)
exit
}
$respStatusCode = $rest.ResponseStatusCode
if ($respStatusCode -ge 400) {
$("Response Status Code = " + $respStatusCode)
$("Response Header:")
$($rest.ResponseHeader)
$("Response Body:")
$($strResponseBody)
exit
}
$jsonResponse = New-Object Chilkat.JsonObject
$jsonResponse.Load($strResponseBody)
$expires_in = $jsonResponse.StringOf("expires_in")
$scope = $jsonResponse.StringOf("scope")
$token_type = $jsonResponse.StringOf("token_type")
$access_token = $jsonResponse.StringOf("access_token")
$geolocation = $jsonResponse.StringOf("geolocation")
{
"expires_in": "3600",
"scope": "app-scopes",
"token_type": "Bearer",
"access_token": "access_token",
"geolocation": "https://us.api.concursolutions.com"
}