Sample code for 30+ languages & platforms
AutoIt

citi Developer OAuth2 Client Credentials Grant

See more OAuth2 Examples

Get access token for your application credentials. You can use this for citi APIs which do not require customer credential verification and consent (e.g. Onboarding).

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.

$oHttp = ObjCreate("Chilkat.Http")

; Implements the following CURL command:

; curl --request POST \
;   --url https://sandbox.apihub.citi.com/gcb/api/clientCredentials/oauth2/token/us/gcb \
;   --header 'accept: application/json' \
;   --user client-id:client-secret \
;   --header 'content-type: application/x-www-form-urlencoded' \
;   --data 'grant_type=client_credentials&scope=%2Fapi'

$oHttp.Login = "client-id"
$oHttp.Password = "client-secret"

$oReq = ObjCreate("Chilkat.HttpRequest")
$oReq.HttpVerb = "POST"
$oReq.Path = "/gcb/api/clientCredentials/oauth2/token/us/gcb"
$oReq.ContentType = "application/x-www-form-urlencoded"
$oReq.AddParam "grant_type","client_credentials"
$oReq.AddParam "scope","/api"
$oReq.AddHeader "accept","application/json"

$oResp = ObjCreate("Chilkat.HttpResponse")
$bSuccess = $oHttp.HttpReq("https://sandbox.apihub.citi.com/gcb/api/clientCredentials/oauth2/token/us/gcb",$oReq,$oResp)
If ($bSuccess = False) Then
    ConsoleWrite($oHttp.LastErrorText & @CRLF)
    Exit
EndIf

$oSbResponseBody = ObjCreate("Chilkat.StringBuilder")
$oResp.GetBodySb($oSbResponseBody)
$oJResp = ObjCreate("Chilkat.JsonObject")
$oJResp.LoadSb($oSbResponseBody)
$oJResp.EmitCompact = False

ConsoleWrite("Response Body:" & @CRLF)
ConsoleWrite($oJResp.Emit() & @CRLF)

Local $iRespStatusCode = $oResp.StatusCode
ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF)
If ($iRespStatusCode >= 400) Then
    ConsoleWrite("Response Header:" & @CRLF)
    ConsoleWrite($oResp.Header & @CRLF)
    ConsoleWrite("Failed." & @CRLF)
    Exit
EndIf

$bSuccess = $oJResp.WriteFile("qa_data/tokens/citi_client_credentials.json")
If ($bSuccess = False) Then
    ConsoleWrite("Failed to save JSON access token file." & @CRLF)
    Exit
EndIf

;  Sample JSON response:
;  (Sample code for parsing the JSON response is shown below)

;  {
;    "token_type": "bearer",
;    "access_token": "AAIkMjdh ... 3fsWb7zJ0s",
;    "expires_in": 1800,
;    "consented_on": 1584817860,
;    "scope": "/api"
;  }

;  Sample code for parsing the JSON response...
;  Use the following online tool to generate parsing code from sample JSON:
;  Generate Parsing Code from JSON

Local $sToken_type = $oJResp.StringOf("token_type")
Local $sAccess_token = $oJResp.StringOf("access_token")
Local $iExpires_in = $oJResp.IntOf("expires_in")
Local $iConsented_on = $oJResp.IntOf("consented_on")
Local $scope = $oJResp.StringOf("scope")