1.0.9 • Published 7 years ago

monzo-api v1.0.9

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

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

new MonzoApi(clientId, clientSecret)

Create a monzo api instance.

ParamTypeDescription
clientIdstringThe client id value.
clientSecretstringThe client secret value.

monzoApi.clientId

Set the clientId value.

Kind: instance property of MonzoApi

ParamTypeDescription
valuestringThe clientId value.

monzoApi.clientId ⇒ string

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

ParamTypeDescription
valuestringThe clientSecret value.

monzoApi.clientSecret ⇒ string

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

ParamTypeDescription
valuestringThe redirectUrl value.

monzoApi.redirectUrl ⇒ string

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

ParamTypeDescription
valuestringThe refreshToken value.

monzoApi.refreshToken ⇒ string

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

ParamTypeDescription
valuestringThe accessToken value.

monzoApi.accessToken ⇒ string

Get the accessToken value.

Kind: instance property of MonzoApi Returns: string - The accessToken value.

monzoApi.code ⇒ string

Get the code value. It will be set when authenticate method gets called

Kind: instance property of MonzoApi Returns: string - The code value.

monzoApi.stateToken ⇒ string

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.

monzoApi.stateToken ⇒ string

Set the stateToken

Kind: instance property of MonzoApi Returns: string - The stateToken value.

monzoApi.authorizationUrl ⇒ string

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.

monzoApi.generateStateToken() ⇒ String

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

monzoApi.authenticate(code, stateToken, verifyStateToken) ⇒ Promise.<object, Error>

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.

ParamTypeDefaultDescription
codestringThe code value.
stateTokenstringThe state token value.
verifyStateTokenstringfalseUse this token instead of the one registered in the API.

monzoApi.refreshAccess(refreshToken) ⇒ Promise.<object, Error>

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.

ParamTypeDescription
refreshTokenstringToken to refresh the access

monzoApi.ping(acessToken) ⇒ Promise.<object, Error>

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.

ParamTypeDescription
acessTokenstringThe accessToken for the request.

monzoApi.accounts(acessToken) ⇒ Promise.<object, Error>

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.

ParamTypeDescription
acessTokenstringThe accessToken for the request.

monzoApi.balance(accountId, acessToken) ⇒ Promise.<object, Error>

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.

ParamTypeDescription
accountIdstringThe account id to check the balance in.
acessTokenstringThe accessToken for the request.

monzoApi.transaction(transactionId, expanded, acessToken) ⇒ Promise.<object, Error>

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.

ParamTypeDefaultDescription
transactionIdstringThe transaction id to check details in
expandedbooleantrueWhether the details for merchant are expanded or not
acessTokenstringThe accessToken for the request.

monzoApi.transactions(accountId, expanded, query, acessToken) ⇒ Promise.<object, Error>

List transactions

Kind: instance method of MonzoApi Returns: Promise.<object, Error> - A promise that returns an object if resolved, or an Error if rejected.

ParamTypeDefaultDescription
accountIdstringThe account id to check transactions in
expandedbooleanfalseWhether the details for merchant are expanded or not
queryobject{}Can be used to add pagination. https://monzo.com/docs/#pagination
acessTokenstringThe accessToken for the request.

monzoApi.annotate(transactionId, metadata, acessToken) ⇒ Promise.<object, Error>

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.

ParamTypeDescription
transactionIdstringThe transaction id to add the annotation
metadataobjectThe 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
acessTokenstringThe accessToken for the request.

monzoApi.feedItem(accountId, url, type, params, acessToken) ⇒ Promise.<object, Error>

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.

ParamTypeDefaultDescription
accountIdstringThe account id to add the feed item
urlstringA 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.
typestring"basic"Type of feed item.
paramsobject{}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' }
acessTokenstringThe accessToken for the request.

monzoApi.registerWebhook(accountId, url, acessToken) ⇒ 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.

Kind: instance method of MonzoApi Returns: Promise.<object, Error> - A promise that returns an object if resolved, or an Error if rejected.

ParamTypeDescription
accountIdstringThe account id to add the webhook to
urlstringThe url to send notifications to
acessTokenstringThe accessToken for the request.

monzoApi.webhooks(accountId, acessToken) ⇒ Promise.<object, Error>

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.

ParamTypeDescription
accountIdstringThe account to list registered webhooks for
acessTokenstringThe accessToken for the request.

monzoApi.deleteWebhook(webhookId, acessToken) ⇒ Promise.<object, Error>

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.

ParamTypeDescription
webhookIdstringThe webhook to delete
acessTokenstringThe accessToken for the request.

monzoApi.uploadImage(file, fileName, fileType) ⇒ Promise.<object, Error>

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.

ParamTypeDescription
filestring | BufferCan be the file absolute location, a base64 representation or the Buffer content of an image
fileNamestringA meaningful name for the image
fileTypestringThe mime type of the image e.g. image/png

monzoApi.registerAttachment(externalId, fileUrl, fileType, acessToken) ⇒ Promise.<object, Error>

Register attachment

Kind: instance method of MonzoApi Returns: Promise.<object, Error> - A promise that returns an object if resolved, or an Error if rejected.

ParamTypeDescription
externalIdstringThe id of the transaction to associate the attachment with.
fileUrlstringThe URL of the uploaded attachment.
fileTypestringThe content type of the attachment. e.g. "image/png"
acessTokenstringThe accessToken for the request.

monzoApi.deregisterAttachment(attachmentId, acessToken) ⇒ Promise.<object, Error>

Deregister attachment

Kind: instance method of MonzoApi Returns: Promise.<object, Error> - A promise that returns an object if resolved, or an Error if rejected.

ParamTypeDescription
attachmentIdstringThe id of the attachment to deregister.
acessTokenstringThe 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.

ParamTypeDefaultDescription
requestTypestringCan be 'GET', 'POST', 'PATCH' or 'DELETE'
requestEndpointstringThe path of the API url. e.g. 'ping/whoami'
requestDataobjectAny data that needs to be sent to the server
useBearerbooleantrueWhether to insert the accessToken into the request header or not
1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago