npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

monzo-api

v1.0.9

Published

Easy interaction with monzo-api

Downloads

90

Readme

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.

| 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. |

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

| Param | Type | Description | | --- | --- | --- | | value | string | The 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

| Param | Type | Description | | --- | --- | --- | | value | string | The 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

| Param | Type | Description | | --- | --- | --- | | value | string | The 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

| Param | Type | Description | | --- | --- | --- | | value | string | The 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.

| 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. |

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.

| Param | Type | Description | | --- | --- | --- | | [refreshToken] | string | Token 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.

| Param | Type | Description | | --- | --- | --- | | [acessToken] | string | The 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.

| Param | Type | Description | | --- | --- | --- | | [acessToken] | string | The 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.

| Param | Type | Description | | --- | --- | --- | | accountId | string | The account id to check the balance in. | | [acessToken] | string | The 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.

| 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. |

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.

| 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. |

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.

| 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. |

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.

| 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. |

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.

| 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. |

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.

| Param | Type | Description | | --- | --- | --- | | accountId | string | The account to list registered webhooks for | | [acessToken] | string | The 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.

| Param | Type | Description | | --- | --- | --- | | webhookId | string | The webhook to delete | | [acessToken] | string | The 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.

| 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 |

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.

| 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. |

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.

| 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 |