monzo-api
Node Monzo API easy integration
Instalation
npm i monzo-api -S
Usage
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);
});
Documentation
- 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>
new MonzoApi(clientId, clientSecret)
Create a monzo api instance.
Param | Type | Description |
---|---|---|
clientId | string |
The client id value. |
clientSecret | string |
The client secret value. |
monzoApi.clientId
Set the clientId value.
Kind: instance property of MonzoApi
Param | Type | Description |
---|---|---|
value | string |
The clientId value. |
string
monzoApi.clientId ⇒ Get the clientId value.
Kind: instance property of MonzoApi
Returns: string
- The clientId value.
monzoApi.clientSecret
Set the clientSecret value.
Kind: instance property of MonzoApi
Param | Type | Description |
---|---|---|
value | string |
The clientSecret value. |
string
monzoApi.clientSecret ⇒ Get the clientSecret value.
Kind: instance property of MonzoApi
Returns: string
- The clientSecret value.
monzoApi.redirectUrl
Set the redirectUrl value.
Kind: instance property of MonzoApi
Param | Type | Description |
---|---|---|
value | string |
The redirectUrl value. |
string
monzoApi.redirectUrl ⇒ Get the redirectUrl value.
Kind: instance property of MonzoApi
Returns: string
- The redirectUrl value.
monzoApi.refreshToken
Set the refreshToken value.
Kind: instance property of MonzoApi
Param | Type | Description |
---|---|---|
value | string |
The refreshToken value. |
string
monzoApi.refreshToken ⇒ Get the refreshToken value.
Kind: instance property of MonzoApi
Returns: string
- The refreshToken value.
monzoApi.accessToken
Set the accessToken value.
Kind: instance property of MonzoApi
Param | Type | Description |
---|---|---|
value | string |
The accessToken value. |
string
monzoApi.accessToken ⇒ Get the accessToken value.
Kind: instance property of MonzoApi
Returns: string
- The accessToken value.
string
monzoApi.code ⇒ Get the code value. It will be set when authenticate method gets called
Kind: instance property of MonzoApi
Returns: string
- The code value.
string
monzoApi.stateToken ⇒ 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.
string
monzoApi.stateToken ⇒ Set the stateToken
Kind: instance property of MonzoApi
Returns: string
- The stateToken value.
string
monzoApi.authorizationUrl ⇒ 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.
String
monzoApi.generateStateToken() ⇒ 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
Promise.<object, Error>
monzoApi.authenticate(code, stateToken, [verifyStateToken]) ⇒ 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. |
Promise.<object, Error>
monzoApi.refreshAccess([refreshToken]) ⇒ 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 |
Promise.<object, Error>
monzoApi.ping([acessToken]) ⇒ 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. |
Promise.<object, Error>
monzoApi.accounts([acessToken]) ⇒ 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. |
Promise.<object, Error>
monzoApi.balance(accountId, [acessToken]) ⇒ 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. |
Promise.<object, Error>
monzoApi.transaction(transactionId, [expanded], [acessToken]) ⇒ 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. |
Promise.<object, Error>
monzoApi.transactions(accountId, [expanded], [query], [acessToken]) ⇒ 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. |
Promise.<object, Error>
monzoApi.annotate(transactionId, metadata, [acessToken]) ⇒ 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. |
Promise.<object, Error>
monzoApi.feedItem(accountId, [url], [type], [params], [acessToken]) ⇒ 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. |
Promise.<object, Error>
monzoApi.registerWebhook(accountId, url, [acessToken]) ⇒ 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. |
Promise.<object, Error>
monzoApi.webhooks(accountId, [acessToken]) ⇒ 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. |
Promise.<object, Error>
monzoApi.deleteWebhook(webhookId, [acessToken]) ⇒ 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. |
Promise.<object, Error>
monzoApi.uploadImage(file, fileName, fileType) ⇒ 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 |
Promise.<object, Error>
monzoApi.registerAttachment(externalId, fileUrl, fileType, [acessToken]) ⇒ 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. |
Promise.<object, Error>
monzoApi.deregisterAttachment(attachmentId, [acessToken]) ⇒ 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. |
Promise.<object, Error>
monzoApi.makeRequest(requestType, requestEndpoint, requestData, [useBearer]) ⇒ 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 |