Node Monzo API easy integration
npm i monzo-api -S
import MonzoApi from 'monzo-api';
const clientId = 'your-app-client-id';
const clientSecret = 'your-app-client-secret';
const verificationCode = 'code-that-server-gets-after-the-redirection';
const verificationStateToken = 'state-token-received-in-query-string-after-redirection';
const monzoApi = new MonzoApi(clientId, clientSecret);
monzoApi.redirectUrl = 'http://127.0.0.1/monzo-validation';
console.log('Redirect the user to', monzoApi.authorizationUrl);
monzoApi.authenticate(code, 'exampleStateToken')
.then((res) => {
console.log("Congrats, you're logged in", res);
})
.catch((err) => {
console.error('Uh Oh! Something wrong happened. :(');
console.error(err);
});
- MonzoApi
- new MonzoApi(clientId, clientSecret)
- .clientId
- .clientId ⇒
string
- .clientSecret
- .clientSecret ⇒
string
- .redirectUrl
- .redirectUrl ⇒
string
- .refreshToken
- .refreshToken ⇒
string
- .accessToken
- .accessToken ⇒
string
- .code ⇒
string
- .stateToken ⇒
string
- .stateToken ⇒
string
- .authorizationUrl ⇒
string
- .generateStateToken() ⇒
String
- .authenticate(code, stateToken, [verifyStateToken]) ⇒
Promise.<object, Error>
- .refreshAccess([refreshToken]) ⇒
Promise.<object, Error>
- .ping([acessToken]) ⇒
Promise.<object, Error>
- .accounts([acessToken]) ⇒
Promise.<object, Error>
- .balance(accountId, [acessToken]) ⇒
Promise.<object, Error>
- .transaction(transactionId, [expanded], [acessToken]) ⇒
Promise.<object, Error>
- .transactions(accountId, [expanded], [query], [acessToken]) ⇒
Promise.<object, Error>
- .annotate(transactionId, metadata, [acessToken]) ⇒
Promise.<object, Error>
- .feedItem(accountId, [url], [type], [params], [acessToken]) ⇒
Promise.<object, Error>
- .registerWebhook(accountId, url, [acessToken]) ⇒
Promise.<object, Error>
- .webhooks(accountId, [acessToken]) ⇒
Promise.<object, Error>
- .deleteWebhook(webhookId, [acessToken]) ⇒
Promise.<object, Error>
- .uploadImage(file, fileName, fileType) ⇒
Promise.<object, Error>
- .registerAttachment(externalId, fileUrl, fileType, [acessToken]) ⇒
Promise.<object, Error>
- .deregisterAttachment(attachmentId, [acessToken]) ⇒
Promise.<object, Error>
- .makeRequest(requestType, requestEndpoint, requestData, [useBearer]) ⇒
Promise.<object, Error>
Create a monzo api instance.
Param | Type | Description |
---|---|---|
clientId | string |
The client id value. |
clientSecret | string |
The client secret value. |
Set the clientId value.
Kind: instance property of MonzoApi
Param | Type | Description |
---|---|---|
value | string |
The clientId value. |
Get the clientId value.
Kind: instance property of MonzoApi
Returns: string
- The clientId value.
Set the clientSecret value.
Kind: instance property of MonzoApi
Param | Type | Description |
---|---|---|
value | string |
The clientSecret value. |
Get the clientSecret value.
Kind: instance property of MonzoApi
Returns: string
- The clientSecret value.
Set the redirectUrl value.
Kind: instance property of MonzoApi
Param | Type | Description |
---|---|---|
value | string |
The redirectUrl value. |
Get the redirectUrl value.
Kind: instance property of MonzoApi
Returns: string
- The redirectUrl value.
Set the refreshToken value.
Kind: instance property of MonzoApi
Param | Type | Description |
---|---|---|
value | string |
The refreshToken value. |
Get the refreshToken value.
Kind: instance property of MonzoApi
Returns: string
- The refreshToken value.
Set the accessToken value.
Kind: instance property of MonzoApi
Param | Type | Description |
---|---|---|
value | string |
The accessToken value. |
Get the accessToken value.
Kind: instance property of MonzoApi
Returns: string
- The accessToken value.
Get the code value. It will be set when authenticate method gets called
Kind: instance property of MonzoApi
Returns: string
- The code value.
Get the stateToken value. Value that will be matched against the one provided when a user authenticates. The values must match otherwise the authentication won't proceed
Kind: instance property of MonzoApi
Returns: string
- The stateToken value.
Set the stateToken
Kind: instance property of MonzoApi
Returns: string
- The stateToken value.
Get the authorizationUrl value. The user needs to be redirected to this url in order to authenticate
Kind: instance property of MonzoApi
Returns: string
- The authorizationUrl value.
Create a state token that gets send on the authorizationUrl
Kind: instance method of MonzoApi
Returns: String
- The token value that was stored and needs to be compared on authorization
Authenticate the user given the code and the stateToken found in the query string of the redirectUrl
Kind: instance method of MonzoApi
Returns: Promise.<object, Error>
- A promise that returns an object if resolved,
or an Error if rejected.
Param | Type | Default | Description |
---|---|---|---|
code | string |
The code value. | |
stateToken | string |
The state token value. | |
[verifyStateToken] | string |
false |
Use this token instead of the one registered in the API. |
Refreshes the user access token using the refresh one
Kind: instance method of MonzoApi
Returns: Promise.<object, Error>
- A promise that returns an object if resolved,
or an Error if rejected.
Param | Type | Description |
---|---|---|
[refreshToken] | string |
Token to refresh the access |
Pings the API to check whether everything is correct
Kind: instance method of MonzoApi
Returns: Promise.<object, Error>
- A promise that returns an object if resolved,
or an Error if rejected.
Param | Type | Description |
---|---|---|
[acessToken] | string |
The accessToken for the request. |
Returns the accounts for the authenticated user
Kind: instance method of MonzoApi
Returns: Promise.<object, Error>
- A promise that returns an object if resolved,
or an Error if rejected.
Param | Type | Description |
---|---|---|
[acessToken] | string |
The accessToken for the request. |
Reads the balance
Kind: instance method of MonzoApi
Returns: Promise.<object, Error>
- A promise that returns an object if resolved,
or an Error if rejected.
Param | Type | Description |
---|---|---|
accountId | string |
The account id to check the balance in. |
[acessToken] | string |
The accessToken for the request. |
Returns an individual transaction, fetched by its id.
Kind: instance method of MonzoApi
Returns: Promise.<object, Error>
- A promise that returns an object if resolved,
or an Error if rejected.
Param | Type | Default | Description |
---|---|---|---|
transactionId | string |
The transaction id to check details in | |
[expanded] | boolean |
true |
Whether the details for merchant are expanded or not |
[acessToken] | string |
The accessToken for the request. |
List transactions
Kind: instance method of MonzoApi
Returns: Promise.<object, Error>
- A promise that returns an object if resolved,
or an Error if rejected.
Param | Type | Default | Description |
---|---|---|---|
accountId | string |
The account id to check transactions in | |
[expanded] | boolean |
false |
Whether the details for merchant are expanded or not |
[query] | object |
{} |
Can be used to add pagination. https://monzo.com/docs/#pagination |
[acessToken] | string |
The accessToken for the request. |
Annotate transaction. You may store your own key-value annotations against a transaction in its metadata.
Kind: instance method of MonzoApi
Returns: Promise.<object, Error>
- A promise that returns an object if resolved,
or an Error if rejected.
Param | Type | Description |
---|---|---|
transactionId | string |
The transaction id to add the annotation |
metadata | object |
The key values pairs to store in the metadata. Include each key you would like to modify. To delete a key, set its value to an empty string |
[acessToken] | string |
The accessToken for the request. |
Creates a new feed item on the user’s feed. Check https://monzo.com/docs/#feed-items for the params details
Kind: instance method of MonzoApi
Returns: Promise.<object, Error>
- A promise that returns an object if resolved,
or an Error if rejected.
Param | Type | Default | Description |
---|---|---|---|
accountId | string |
The account id to add the feed item | |
[url] | string |
A URL to open when the feed item is tapped. If no URL is provided, the app will display a fallback view based on the title & body. | |
[type] | string |
"basic" |
Type of feed item. |
[params] | object |
{} |
A map of parameters which vary based on type. basic type e.g. { title: 'My custom item', image_url: 'www.example.com/image.png', background_color: '#FCF1EE', body_color: '#FCF1EE', title_color: '#333', body: 'Some body text to display' } |
[acessToken] | string |
The accessToken for the request. |
Webhooks allow your application to receive real-time, push notification of events in an account. Each time a matching event occurs, monzo will make a POST call to the URL you provide. If the call fails, monzo will retry up to a maximum of 5 attempts, with exponential backoff.
Kind: instance method of MonzoApi
Returns: Promise.<object, Error>
- A promise that returns an object if resolved,
or an Error if rejected.
Param | Type | Description |
---|---|---|
accountId | string |
The account id to add the webhook to |
url | string |
The url to send notifications to |
[acessToken] | string |
The accessToken for the request. |
List the webhooks your application has registered on an account.
Kind: instance method of MonzoApi
Returns: Promise.<object, Error>
- A promise that returns an object if resolved,
or an Error if rejected.
Param | Type | Description |
---|---|---|
accountId | string |
The account to list registered webhooks for |
[acessToken] | string |
The accessToken for the request. |
Delete a webhook
Kind: instance method of MonzoApi
Returns: Promise.<object, Error>
- A promise that returns an object if resolved,
or an Error if rejected.
Param | Type | Description |
---|---|---|
webhookId | string |
The webhook to delete |
[acessToken] | string |
The accessToken for the request. |
Hosts an image in Monzo S3 Bucket. Will try to gzip the contents before uploading it
Kind: instance method of MonzoApi
Returns: Promise.<object, Error>
- A promise that returns an object if resolved,
or an Error if rejected.
Param | Type | Description |
---|---|---|
file | string | Buffer |
Can be the file absolute location, a base64 representation or the Buffer content of an image |
fileName | string |
A meaningful name for the image |
fileType | string |
The mime type of the image e.g. image/png |
Register attachment
Kind: instance method of MonzoApi
Returns: Promise.<object, Error>
- A promise that returns an object if resolved,
or an Error if rejected.
Param | Type | Description |
---|---|---|
externalId | string |
The id of the transaction to associate the attachment with. |
fileUrl | string |
The URL of the uploaded attachment. |
fileType | string |
The content type of the attachment. e.g. "image/png" |
[acessToken] | string |
The accessToken for the request. |
Deregister attachment
Kind: instance method of MonzoApi
Returns: Promise.<object, Error>
- A promise that returns an object if resolved,
or an Error if rejected.
Param | Type | Description |
---|---|---|
attachmentId | string |
The id of the attachment to deregister. |
[acessToken] | string |
The accessToken for the request. |
monzoApi.makeRequest(requestType, requestEndpoint, requestData, [useBearer]) ⇒ Promise.<object, Error>
Makes any request to the Monzo API
Kind: instance method of MonzoApi
Returns: Promise.<object, Error>
- A promise that returns an object if resolved,
or an Error if rejected.
Param | Type | Default | Description |
---|---|---|---|
requestType | string |
Can be 'GET', 'POST', 'PATCH' or 'DELETE' | |
requestEndpoint | string |
The path of the API url. e.g. 'ping/whoami' | |
requestData | object |
Any data that needs to be sent to the server | |
[useBearer] | boolean |
true |
Whether to insert the accessToken into the request header or not |