AutoIt
AutoIt
Rabobank GET /v3/accounts
See more Rabobank Examples
Demonstrates a call to a Rabobank API. Specifically this makes a call to the "Accounts AIS sb" API to deliver all the consented payments accounts for a specific Rabobank customer.(This includes source code to for signing requests for PSD2 APIs)
Chilkat AutoIt Downloads
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 GET \
; --url https://api-sandbox.rabobank.nl/openapi/sandbox/payments/account-information/ais/v3/accounts \
; --header 'accept: application/json' \
; --header 'authorization: Bearer REPLACE_BEARER_TOKEN' \
; --header 'date: REPLACE_THIS_VALUE' \
; --header 'digest: REPLACE_THIS_VALUE' \
; --header 'psu-ip-address: OPTIONAL' \
; --header 'signature: REPLACE_THIS_VALUE' \
; --header 'tpp-signature-certificate: MIIDkDCCAnigA ... cwE6gUl0rMA==' \
; --header 'x-ibm-client-id: Client ID' \
; --header 'x-request-id: REPLACE_THIS_VALUE'
; Load the previously fetched OAuth2 access token.
$oJsonToken = ObjCreate("Chilkat.JsonObject")
$bSuccess = $oJsonToken.LoadFile("qa_data/tokens/rabobank.json")
If ($bSuccess = False) Then
ConsoleWrite($oJsonToken.LastErrorText & @CRLF)
Exit
EndIf
; This adds the "authorization: Bearer REPLACE_BEARER_TOKEN" header.
$oHttp.AuthToken = $oJsonToken.StringOf("access_token")
; This is the TTP Signature certificate: The certificate used for signing the request.
$oSbTppCert = ObjCreate("Chilkat.StringBuilder")
$oSbTppCert.Append("MIIDkDCCAnigAwIBAgIEWs3AJDANBgkqhkiG9w0BAQsFADCBiTELMAkGA1UEBhMC")
$oSbTppCert.Append("TkwxEDAOBgNVBAgMB1V0cmVjaHQxEDAOBgNVBAcMB1V0cmVjaHQxETAPBgNVBAoM")
$oSbTppCert.Append("CFJhYm9iYW5rMRwwGgYDVQQLDBNPbmxpbmUgVHJhbnNhY3Rpb25zMSUwIwYDVQQD")
$oSbTppCert.Append("DBxQU0QyIEFQSSBQSSBTZXJ2aWNlcyBTYW5kYm94MB4XDTE4MDQxMTA3NTgyOFoX")
$oSbTppCert.Append("DTIzMDQxMTA3NTgyOFowgYkxCzAJBgNVBAYTAk5MMRAwDgYDVQQIDAdVdHJlY2h0")
$oSbTppCert.Append("MRAwDgYDVQQHDAdVdHJlY2h0MREwDwYDVQQKDAhSYWJvYmFuazEcMBoGA1UECwwT")
$oSbTppCert.Append("T25saW5lIFRyYW5zYWN0aW9uczElMCMGA1UEAwwcUFNEMiBBUEkgUEkgU2Vydmlj")
$oSbTppCert.Append("ZXMgU2FuZGJveDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANoAjqGW")
$oSbTppCert.Append("UgCIm2F+0sBSEwLal+T3u+uldLikpxHCB8iL1GD7FrRjcA+MVsxhvHly7vRsHK+t")
$oSbTppCert.Append("QyMSaeK782RHpY33qxPLc8LmoQLb2EuiQxXj9POYkYBQ74qkrZnvKVlR3WoyQWeD")
$oSbTppCert.Append("OXnSY2wbNFfkP8ET4ElwyuIIEriwYhab0OIrnnrO8X82/SPZxHwEd3aQjQ6uhiw8")
$oSbTppCert.Append("paDspJbS5WjEfuwY16KVVUYlhbtAwGjvc6aK0NBm+LH9fMLpAE6gfGZNy0gzMDor")
$oSbTppCert.Append("VNbkQK1IoAGD8p9ZHdB0F3FwkILEjUiQW6nK+/fKDNJ0TBbpgZUpY8bR460qzxKd")
$oSbTppCert.Append("eZ1yPDqX2Cjh6fkCAwEAATANBgkqhkiG9w0BAQsFAAOCAQEAYL4iD6noMJAt63kD")
$oSbTppCert.Append("ED4RB2mII/lssvHhcxuDpOm3Ims9urubFWEpvV5TgIBAxy9PBinOdjhO1kGJJnYi")
$oSbTppCert.Append("7F1jv1qnZwTV1JhYbvxv3+vk0jaiu7Ew7G3ASlzruXyMhN6t6jk9MpaWGl5Uw1T+")
$oSbTppCert.Append("gNRUcWQRR44g3ahQRIS/UHkaV+vcpOa8j186/1X0ULHfbcVQk4LMmJeXqNs8sBAU")
$oSbTppCert.Append("dKU/c6ssvj8jfJ4SfrurcBhY5UBTOdQOXTPY85aU3iFloerx7Oi9EHewxInOrU5X")
$oSbTppCert.Append("zqqTz2AQPXezexVeAQxP27lzqCmYC7CFiam6QBr06VebkmnPLfs76n8CDc1cwE6g")
$oSbTppCert.Append("Ul0rMA==")
$oHttp.SetRequestHeader "tpp-signature-certificate",$oSbTppCert.GetAsString()
; ----------------------------------------------------------------
; We're not going to add the psu-ip-address header in this example.
; ----------------------------------------------------------------
; X-Request-ID header...
; Generate a UUID v4.
$oCrypt = ObjCreate("Chilkat.Crypt2")
Local $sXRequestId = $oCrypt.GenerateUuid()
$oHttp.SetRequestHeader "x-request-id",$sXRequestId
; ----------------------------------------------------------------
; Date header...
$oDt = ObjCreate("Chilkat.CkDateTime")
$oDt.SetFromCurrentSystemTime()
Local $sDateHdrVal = $oDt.GetAsRfc822(False)
; The desire date/time format is the "RFC822" format.
$oHttp.SetRequestHeader "Date",$sDateHdrVal
; ----------------------------------------------------------------
; Digest header...
$oCrypt.HashAlgorithm = "SHA256"
$oCrypt.EncodingMode = "base64"
; A GET request has no HTTP request body. Therefore the payload is the empty string.
Local $sPayload = ""
Local $sPayloadDigest = $oCrypt.HashStringENC($sPayload)
$oSbDigestHdrVal = ObjCreate("Chilkat.StringBuilder")
$oSbDigestHdrVal.Append("SHA-256=")
$oSbDigestHdrVal.Append($sPayloadDigest)
$oHttp.SetRequestHeader "digest",$oSbDigestHdrVal.GetAsString()
; ----------------------------------------------------------------
; The HTTP request needs to be signed for PSD2 API's...
; Create the signing string (to use in signing the HTTP request).
; See https://developer.rabobank.nl/signing-requests-psd2-apis
;
; For "account information" HTTP requests, we must use the following headers in the signing string.
; date
; digest
; x-request-id
$oSbStringToSign = ObjCreate("Chilkat.StringBuilder")
$oSbStringToSign.Append("date: ")
$oSbStringToSign.AppendLine($sDateHdrVal,False)
$oSbStringToSign.Append("digest: ")
$oSbStringToSign.AppendLine($oSbDigestHdrVal.GetAsString(),False)
$oSbStringToSign.Append("x-request-id: ")
$oSbStringToSign.Append($sXRequestId)
; ----------------------------------------------------------------
; Sign with our private key...
$oSbPrivKey = ObjCreate("Chilkat.StringBuilder")
$oSbPrivKey.Append("MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDaAI6hllIAiJth")
$oSbPrivKey.Append("ftLAUhMC2pfk97vrpXS4pKcRwgfIi9Rg+xa0Y3APjFbMYbx5cu70bByvrUMjEmni")
$oSbPrivKey.Append("u/NkR6WN96sTy3PC5qEC29hLokMV4/TzmJGAUO+KpK2Z7ylZUd1qMkFngzl50mNs")
$oSbPrivKey.Append("GzRX5D/BE+BJcMriCBK4sGIWm9DiK556zvF/Nv0j2cR8BHd2kI0OroYsPKWg7KSW")
$oSbPrivKey.Append("0uVoxH7sGNeilVVGJYW7QMBo73OmitDQZvix/XzC6QBOoHxmTctIMzA6K1TW5ECt")
$oSbPrivKey.Append("SKABg/KfWR3QdBdxcJCCxI1IkFupyvv3ygzSdEwW6YGVKWPG0eOtKs8SnXmdcjw6")
$oSbPrivKey.Append("l9go4en5AgMBAAECggEAB8nsTqalwGIhFw8mbXuhNUFlGuek/arYLD6pv28swwQH")
$oSbPrivKey.Append("7v0ZlxFUcCHF+iBl0PsDwZTZQ4ePtgGS6ehoLkWHCzb1lEv5E1YVG5qKNE2UUwRl")
$oSbPrivKey.Append("fIyPakO6AzyV/UF3uzq7C+/GuXGNTKZxKewg5yD/DCFvKoCOpxu9u36FyqP/hw0S")
$oSbPrivKey.Append("ADVlmp35/zoPDPZzu1j4FiCo0pJ9LwJcHxeJHopNAKDw9k6I4z/grskdgupsGzK2")
$oSbPrivKey.Append("BiGiQ/+wmmO68/6Xa6KWfpr1PQ6ODJHgzZsdGCVi6Ebaqlj6BbsYWxP6h3lrsGt+")
$oSbPrivKey.Append("LmHBaN2jCD6cDp+lihqFgnm8hfdv0lmbPilp71EDfwKBgQD6U8PBzZtN8yXm5WuS")
$oSbPrivKey.Append("NL+/8q5GjNmeTJBSo1gM6Y8vOT4QAE147LbVuVBDwyHPoSrNejePae6Q14PswjBy")
$oSbPrivKey.Append("T7B8DZ0OeQyGa3trrFg/ib7Vv4ZMvJqX9+WzBrzZsxTg7oCKHzmCR4vIRItKHH3z")
$oSbPrivKey.Append("Wnnhqlo8ic2AZ2O43cdJosbO1wKBgQDe8UODOLu0vnHohOKeUqF3w/ZOB2+83/js")
$oSbPrivKey.Append("YyUbSkzsGvHIwTjObuMUFTQvdMZ6IkIyJdfnDZIbvlBSD8tzL5iKFTNCK2nL1i4G")
$oSbPrivKey.Append("iFr0CYLaHAlhJ5GEbTrTMDoJeBPerZq83HPrSa/Wb0xO18QTWsoVQPFfPFbbcQyI")
$oSbPrivKey.Append("9ryJ2iIDrwKBgQC6kuAefG46ZPVk6K2KZUJdgDUgZC52a75NuW0RAqszmUiGiJM1")
$oSbPrivKey.Append("g8ip9tq6BqAWrprGV0c93shusBKlzf5p1LdHXqYmeVY6gbWVhPipMrNHgN5KJ3BZ")
$oSbPrivKey.Append("v+w1yNnMsErpcxne2HL2hPjMJTpj3GSLkm2xIlTrNhIyl9ydlr7IRUhENQKBgQCv")
$oSbPrivKey.Append("i6HxbXa/90WSJTCcIcxqla8X+dsOCf3jhJ3vQy4Wq5C+1wZ35fCAG8Ifq/+so9Uj")
$oSbPrivKey.Append("z5CVqqXlmpF8TFuSs2OVNuRJsg14J4nOMwgLKIIUZAcurQ10DN5I9Kx+UEK1EFXL")
$oSbPrivKey.Append("aHsORdNjMfgQDO2jn9WHrr9gkg6CdB2+qyoCEfS+mQKBgBW08lcy9V5RzRWb/v/j")
$oSbPrivKey.Append("xsc7ovmgAhCJhDeV7dPbx4HbFeoQJlbA8g1thdcFlcatSGyNDbvNE1GPSd4NhkpR")
$oSbPrivKey.Append("Y6Hfv53kdEzjVkEtU8lUdL7HNVJqX7bU7oZlfbYcwxWQ1Gg8C1oLIAyEt71slQtd")
$oSbPrivKey.Append("RiNYBRZTQe2F0wxbXnuUqLAw")
$oPrivKey = ObjCreate("Chilkat.PrivateKey")
$bSuccess = $oPrivKey.LoadPem($oSbPrivKey.GetAsString())
If ($bSuccess = False) Then
ConsoleWrite($oPrivKey.LastErrorText & @CRLF)
Exit
EndIf
$oRsa = ObjCreate("Chilkat.Rsa")
$bSuccess = $oRsa.UsePrivateKey($oPrivKey)
If ($bSuccess = False) Then
ConsoleWrite($oRsa.LastErrorText & @CRLF)
Exit
EndIf
$oRsa.EncodingMode = "base64"
Local $sB64Signature = $oRsa.SignStringENC($oSbStringToSign.GetAsString(),"SHA256")
; ----------------------------------------------------------------
; Add the "signature" header.
;
; The signature header will look like this:
; signature: keyId="1523433508",algorithm="rsa-sha512",headers="date digest x-request-id",signature="y5o7gKxmfA6AT6...blE1A9Q=="
;
; The keyId is the serial number of the certificate as defined in 'TPP-Signing-Certificate' header, the format should be Integer not hex.
$oCert = ObjCreate("Chilkat.Cert")
$bSuccess = $oCert.SetFromEncoded($oSbTppCert.GetAsString())
If ($bSuccess = False) Then
ConsoleWrite($oCert.LastErrorText & @CRLF)
Exit
EndIf
$oSbSigHdrVal = ObjCreate("Chilkat.StringBuilder")
$oSbSigHdrVal.Append("keyId=""")
$oSbSigHdrVal.Append($oCert.SerialDecimal)
$oSbSigHdrVal.Append(""",")
$oSbSigHdrVal.Append("algorithm=""rsa-sha256"",")
$oSbSigHdrVal.Append("headers=""date digest x-request-id"",")
$oSbSigHdrVal.Append("signature=""")
$oSbSigHdrVal.Append($sB64Signature)
$oSbSigHdrVal.Append("""")
$oHttp.SetRequestHeader "signature",$oSbSigHdrVal.GetAsString()
; ----------------------------------------------------------------
; Add remaining headers...
$oHttp.SetRequestHeader "x-ibm-client-id","YOUR_APP_CLIENT_ID"
$oHttp.SetRequestHeader "accept","application/json"
; ----------------------------------------------------------------
; Add our certificate and key for mutual TLS
; (provide a registered X509 client certificate during TLS handhake)
$oTlsCert = ObjCreate("Chilkat.Cert")
$bSuccess = $oTlsCert.LoadFromFile("qa_data/certs_and_keys/ING/example_client_tls.cer")
If ($bSuccess = False) Then
ConsoleWrite($oTlsCert.LastErrorText & @CRLF)
Exit
EndIf
$oBdPrivKey = ObjCreate("Chilkat.BinData")
$bSuccess = $oBdPrivKey.LoadFile("qa_data/certs_and_keys/ING/example_client_tls.key")
If ($bSuccess = False) Then
ConsoleWrite("Failed to load example_client_tls.key" & @CRLF)
Exit
EndIf
; The OAuth 2.0 client_id for these certificates is e77d776b-90af-4684-bebc-521e5b2614dd.
; Please note down this client_id since you will need it in the next steps to call the API.
$oTlsPrivKey = ObjCreate("Chilkat.PrivateKey")
$bSuccess = $oTlsPrivKey.LoadAnyFormat($oBdPrivKey,"")
If ($bSuccess = False) Then
ConsoleWrite($oTlsPrivKey.LastErrorText & @CRLF)
Exit
EndIf
; Associate the private key with the certificate.
$bSuccess = $oTlsCert.SetPrivateKey($oTlsPrivKey)
If ($bSuccess = False) Then
ConsoleWrite($oTlsCert.LastErrorText & @CRLF)
Exit
EndIf
$bSuccess = $oHttp.SetSslClientCert($oTlsCert)
If ($bSuccess = False) Then
ConsoleWrite($oHttp.LastErrorText & @CRLF)
Exit
EndIf
; ----------------------------------------------------------------
; Finally, send the request...
$oSbResponseBody = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oHttp.QuickGetSb("https://api-sandbox.rabobank.nl/openapi/sandbox/payments/account-information/ais/v3/accounts",$oSbResponseBody)
If ($bSuccess = False) Then
ConsoleWrite($oHttp.LastErrorText & @CRLF)
ConsoleWrite($oSbResponseBody.GetAsString() & @CRLF)
Exit
EndIf
$oJResp = ObjCreate("Chilkat.JsonObject")
$oJResp.LoadSb($oSbResponseBody)
$oJResp.EmitCompact = False
ConsoleWrite("Response Body:" & @CRLF)
ConsoleWrite($oJResp.Emit() & @CRLF)
Local $iRespStatusCode = $oHttp.LastStatus
ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF)
If ($iRespStatusCode >= 400) Then
ConsoleWrite("Response Header:" & @CRLF)
ConsoleWrite($oHttp.LastHeader & @CRLF)
ConsoleWrite("Failed." & @CRLF)
Exit
EndIf
; Sample JSON response:
; (Sample code for parsing the JSON response is shown below)
; {
; "accounts": [
; {
; "_links": {
; "account": "/v3/accounts/dW9od2VIVUhGVypIZHVpaGRhdWR3OGRoY",
; "balances": "/v3/accounts/dW9od2VIVUhGVypIZHVpaGRhdWR3OGRoY/balances",
; "transactions": "/v3/accounts/dW9od2VIVUhGVypIZHVpaGRhdWR3OGRoY/transactions"
; },
; "currency": "EUR",
; "iban": "NL05RABO0812836782",
; "name": "Rosie Roy",
; "resourceId": "dW9od2VIVUhGVypIZHVpaGRhdWR3OGRoY",
; "status": "enabled"
; }
; ]
; }
; 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 $sV_linksAccount
Local $sV_linksBalances
Local $sV_linksTransactions
Local $sCurrency
Local $sIban
Local $sName
Local $sResourceId
Local $status
Local $i = 0
Local $iCount_i = $oJResp.SizeOfArray("accounts")
While $i < $iCount_i
$oJResp.I = $i
$sV_linksAccount = $oJResp.StringOf("accounts[i]._links.account")
$sV_linksBalances = $oJResp.StringOf("accounts[i]._links.balances")
$sV_linksTransactions = $oJResp.StringOf("accounts[i]._links.transactions")
$sCurrency = $oJResp.StringOf("accounts[i].currency")
$sIban = $oJResp.StringOf("accounts[i].iban")
$sName = $oJResp.StringOf("accounts[i].name")
$sResourceId = $oJResp.StringOf("accounts[i].resourceId")
$status = $oJResp.StringOf("accounts[i].status")
$i = $i + 1
Wend