Constructor
new MonzoApi(clientId, clientSecret)
Create a monzo api instance.
Parameters:
Name | Type | Description |
---|---|---|
clientId |
string | The client id value. |
clientSecret |
string | The client secret value. |
Members
accessToken
Get the accessToken value.
accessToken
Set the accessToken value.
authorizationUrl
Get the authorizationUrl value.
The user needs to be redirected to this url in order to authenticate
clientId
Get the clientId value.
clientId
Set the clientId value.
clientSecret
Set the clientSecret value.
clientSecret
Get the clientSecret value.
code
Get the code value. It will be set when authenticate method gets called
redirectUrl
Set the redirectUrl value.
redirectUrl
Get the redirectUrl value.
refreshToken
Get the refreshToken value.
refreshToken
Set the refreshToken value.
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
Methods
accounts(acessTokenopt) → {Promise.<object, Error>}
Returns the accounts for the authenticated user
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
acessToken |
string |
<optional> |
The accessToken for the request. |
Returns:
A promise that returns an object if resolved,
or an Error if rejected.
- Type
- Promise.<object, Error>
annotate(transactionId, metadata, acessTokenopt) → {Promise.<object, Error>}
Annotate transaction.
You may store your own key-value annotations against a transaction in its metadata.
Parameters:
Name | Type | Attributes | 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 |
<optional> |
The accessToken for the request. |
Returns:
A promise that returns an object if resolved,
or an Error if rejected.
- Type
- Promise.<object, Error>
authenticate(code, stateToken, verifyStateTokenopt) → {Promise.<object, Error>}
Authenticate the user given the code and the stateToken
found in the query string of the redirectUrl
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
code |
string | The code value. | ||
stateToken |
string | The state token value. | ||
verifyStateToken |
string |
<optional> |
false | Use this token instead of the one registered in the API. |
Returns:
A promise that returns an object if resolved,
or an Error if rejected.
- Type
- Promise.<object, Error>
balance(accountId, acessTokenopt) → {Promise.<object, Error>}
Reads the balance
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
accountId |
string | The account id to check the balance in. | |
acessToken |
string |
<optional> |
The accessToken for the request. |
Returns:
A promise that returns an object if resolved,
or an Error if rejected.
- Type
- Promise.<object, Error>
deleteWebhook(webhookId, acessTokenopt) → {Promise.<object, Error>}
Delete a webhook
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
webhookId |
string | The webhook to delete | |
acessToken |
string |
<optional> |
The accessToken for the request. |
Returns:
A promise that returns an object if resolved,
or an Error if rejected.
- Type
- Promise.<object, Error>
deregisterAttachment(attachmentId, acessTokenopt) → {Promise.<object, Error>}
Deregister attachment
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
attachmentId |
string | The id of the attachment to deregister. | |
acessToken |
string |
<optional> |
The accessToken for the request. |
Returns:
A promise that returns an object if resolved,
or an Error if rejected.
- Type
- Promise.<object, Error>
feedItem(accountId, urlopt, typeopt, paramsopt, acessTokenopt) → {Promise.<object, Error>}
Creates a new feed item on the user’s feed.
Check https://monzo.com/docs/#feed-items for the params details
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
accountId |
string | The account id to add the feed item | ||
url |
string |
<optional> |
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 |
<optional> |
basic | Type of feed item. |
params |
object |
<optional> |
{} | 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 |
<optional> |
The accessToken for the request. |
Returns:
A promise that returns an object if resolved,
or an Error if rejected.
- Type
- Promise.<object, Error>
makeRequest(requestType, requestEndpoint, requestData, useBeareropt) → {Promise.<object, Error>}
Makes any request to the Monzo API
Parameters:
Name | Type | Attributes | 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 |
<optional> |
true | Whether to insert the accessToken into the request header or not |
Returns:
A promise that returns an object if resolved,
or an Error if rejected.
- Type
- Promise.<object, Error>
ping(acessTokenopt) → {Promise.<object, Error>}
Pings the API to check whether everything is correct
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
acessToken |
string |
<optional> |
The accessToken for the request. |
Returns:
A promise that returns an object if resolved,
or an Error if rejected.
- Type
- Promise.<object, Error>
refreshAccess() → {Promise.<object, Error>}
Refreshes the user access token using the refresh one
Returns:
A promise that returns an object if resolved,
or an Error if rejected.
- Type
- Promise.<object, Error>
registerAttachment(externalId, fileUrl, fileType, acessTokenopt) → {Promise.<object, Error>}
Register attachment
Parameters:
Name | Type | Attributes | 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 |
<optional> |
The accessToken for the request. |
Returns:
A promise that returns an object if resolved,
or an Error if rejected.
- Type
- Promise.<object, Error>
registerWebhook(accountId, url, acessTokenopt) → {Promise.<object, Error>}
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.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
accountId |
string | The account id to add the webhook to | |
url |
string | The url to send notifications to | |
acessToken |
string |
<optional> |
The accessToken for the request. |
Returns:
A promise that returns an object if resolved,
or an Error if rejected.
- Type
- Promise.<object, Error>
transaction(transactionId, expandedopt, acessTokenopt) → {Promise.<object, Error>}
Returns an individual transaction, fetched by its id.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
transactionId |
string | The transaction id to check details in | ||
expanded |
boolean |
<optional> |
true | Whether the details for merchant are expanded or not |
acessToken |
string |
<optional> |
The accessToken for the request. |
Returns:
A promise that returns an object if resolved,
or an Error if rejected.
- Type
- Promise.<object, Error>
transactions(accountId, expandedopt, queryopt, acessTokenopt) → {Promise.<object, Error>}
List transactions
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
accountId |
string | The account id to check transactions in | ||
expanded |
boolean |
<optional> |
false | Whether the details for merchant are expanded or not |
query |
object |
<optional> |
{} | Can be used to add pagination. https://monzo.com/docs/#pagination |
acessToken |
string |
<optional> |
The accessToken for the request. |
Returns:
A promise that returns an object if resolved,
or an Error if rejected.
- Type
- Promise.<object, Error>
uploadImage(file, fileName, fileType) → {Promise.<object, Error>}
Hosts an image in Monzo S3 Bucket.
Will try to gzip the contents before uploading it
Parameters:
Name | 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 |
Returns:
A promise that returns an object if resolved,
or an Error if rejected.
- Type
- Promise.<object, Error>
webhooks(accountId, acessTokenopt) → {Promise.<object, Error>}
List the webhooks your application has registered on an account.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
accountId |
string | The account to list registered webhooks for | |
acessToken |
string |
<optional> |
The accessToken for the request. |
Returns:
A promise that returns an object if resolved,
or an Error if rejected.
- Type
- Promise.<object, Error>