The Programmable Card API allows you to access programmable card functionality via an API. The features available via the online IDE are also available via the API.
Using Postman
If you’re new to APIs and want to get familiar with using the endpoints, we recommend you create a Postman account (it's free) and use the Postman collections provided to test things out.
This will save code your card without publishing it.
Navigate to the Card folder and the POST Update Function code query.
Insert your cardkey variable from the previous query under the Params tab on the query page.
Replace the body of the request with the code you would like. Below is an example for you to use. The snippet declines card purchases that are made in bakeries (using a specified merchant code) transactions and that are over the R50 (or 5000 cents) limit.
This will run a simulation of your code for testing before you publish code.
Navigate to the Card folder and the POST Execute Function Code query.
Insert your cardkey variable from the previous query under the Params tab on the query page.
Replace the body of the code with the code you want to simulate. The below code snippet simulates and declines card purchases that are made in bakeries (using a specified merchant code) transactions and that are over the R50 (or 5000 cents) limit.
curl --location 'https://openapi.investec.com/za/v1/cards//code' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"code": "// This function runs during the card transaction authorization flow.\n// It has a limited execution time, so keep any code short-running.\nconst beforeTransaction = async (authorization) => {\n console.log(authorization);\n return true;\n};\n\n// This function runs after a transaction.\nconst afterTransaction = async (transaction) => {\n console.log(transaction)\n};\n\n// This function runs after a transaction.\nconst afterDecline = async (transaction) => {\n console.log(transaction)\n};"
}'
curl --location 'https://openapi.investec.com/za/v1/cards//code/execute' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"simulationcode": "// This function runs during the card transaction authorization flow.\n// It has a limited execution time, so keep any code short-running.\nconst beforeTransaction = async (authorization) => {\n console.log(authorization);\n return true;\n};\n\n// This function runs after a transaction.\nconst afterTransaction = async (transaction) => {\n console.log(transaction)\n};\n\n// This function runs after a transaction.\nconst afterDecline = async (transaction) => {\n console.log(transaction)\n};",
"centsAmount": "10100",
"currencyCode": "zar",
"merchantCode": 7996,
"merchantName": "USkaka",
"merchantCity": "Durban",
"countryCode": "ZA"
}'