Skip to content

Instantly share code, notes, and snippets.

@domdomegg
Last active November 16, 2019 19:41
Show Gist options
  • Save domdomegg/3fee28e3f333553d21a1b9c3d5b2258e to your computer and use it in GitHub Desktop.
Save domdomegg/3fee28e3f333553d21a1b9c3d5b2258e to your computer and use it in GitHub Desktop.
Starling API examples

These programs use Starling's public API to print out details of and lock all the cards of an account holder

You'll want to run these something like:

ACCESS_TOKEN=youraccesstokenhere python example.py 

If using the sandbox API, like:

ACCESS_TOKEN=youraccesstokenhere STARLING_API=https://api-sandbox.starlingbank.com python example.py 
// npm install axios
const axios = require('axios')
const headers = {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: `Bearer ${process.env.ACCESS_TOKEN}`
}
const baseURL = process.env.STARLING_API || 'https://api.starlingbank.com'
const main = async () => {
const cards = await axios({
method: 'GET',
url: `${baseURL}/api/v2/cards`,
headers
}).then(res => res.data.cards)
console.log("I found these cards:", cards)
cards.forEach(card =>
axios({
method: 'PUT',
url: `${baseURL}/api/v2/cards/${card.cardUid}/controls/enabled`,
headers,
data: {
enabled: false
}
})
.then(() => console.log("I locked card", card.cardUid))
.catch(err => console.error(err.response.data ? err.response.data : err))
)
}
main().catch(err => console.error(err))
import os
# pip install requests
import requests
headers = {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + os.getenv('ACCESS_TOKEN', '')
}
baseURL = os.getenv('STARLING_API', 'https://api.starlingbank.com')
res = requests.get(
baseURL + '/api/v2/cards',
headers = headers
).json()
if 'error' in res:
print(res)
exit(1)
cards = res['cards']
print('I found these cards:', cards)
for card in cards:
res = requests.put(
baseURL + '/api/v2/cards/' + card['cardUid'] + '/controls/enabled',
headers = headers,
data = {
'enabled': False
}
)
if 'error' in res:
print(res)
exit(1)
print("I locked card", card['cardUid'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment