Last active
November 19, 2017 19:24
-
-
Save ryanbateman/cc80b0ee63b37367f7ed5971ea636bda to your computer and use it in GitHub Desktop.
How to auth against Monzo's API in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(httr) | |
library(jsonlite) | |
# OAuth settings for Monzo: | |
# https://monzo.com/docs/#authentication | |
monzo <- oauth_endpoint( | |
authorize = "https://auth.getmondo.co.uk/", | |
access = "https://api.monzo.com/oauth2/token") | |
# You need to set up your own Monzo 'app' to play with the API | |
# To do so, visit: https://developers.monzo.com/apps/home | |
# Once you've done so, you need to add the Client ID and secret below | |
# It's worth noting that Monzo's refresh token approach means you may need to frequently wipe your R's oauth token cache manually | |
myapp <- oauth_app("monzo", | |
key = "", # Client ID | |
secret = "") # Client Secret | |
monzo_token <- oauth2.0_token(monzo, myapp, cache = TRUE) | |
# As an example to show it works, we use the API to retrieve an account ID. | |
# (We just get the first one) | |
accountRequest <- GET("https://api.monzo.com/accounts", config(token = monzo_token)) | |
accountsJson = fromJSON(content(accountRequest, as = "text")) | |
accountID = accountsJson$accounts[1, "id"] | |
accountID |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment