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

@rantalainen/fortnox-api-client

v1.1.1

Published

**FortnoxApiClient** is a third party [Fortnox API](https://apps.fortnox.se/apidocs) client for NodeJS. It is a wrapper around an API client that has been [automatically generated](https://www.npmjs.com/package/swagger-typescript-api) using the [OpenAPI s

Downloads

17

Readme

fortnox-api-client

FortnoxApiClient is a third party Fortnox API client for NodeJS. It is a wrapper around an API client that has been automatically generated using the OpenAPI schema provided by Fortnox.

Installation

Add to project's package.json:

npm install @rantalainen/fortnox-api-client

Import

import { FortnoxApiClient } from '@rantalainen/fortnox-api-client';

Authentication/Authorization

One must authorize integration to use company data and to acquire accessToken and refreshToken for Fortnox API. This API client provides static helper functions to achieve the tokens.

In order to obtain your client id, client secret and redirect uri please see Fortnox documentation.

Generate Authorization URI

Please see Fortnox Authorization Code docs for more information on the topic.

const authorizationUri = FortnoxApiClient.createAuthorizationUri(
  'your client id',
  'your integration redirect uri',

  // required scope
  ['companyinformation'],

  // state that should match while getting tokens in the next step
  'state',

  // type of authorization
  'service'
);

Fetch access token and refresh token

// Authorization Code acquired from previous step
const code = 'xxxx';

// State acquired from previous step
const state = 'xxxx';

// Validate state
if (state !== expectedState) {
  // Something wrong with authorization
}

const tokens = await FortnoxApiClient.getTokensByAuthorizationCode(
  'your client id',
  'your client secret',
  'your integration redirect uri'
  code
);

// tokens.accessToken = 1hour token to use Fortnox API
// tokens.refreshToken = 45day long lived token to refresh access token when necessary

Setup client with options

const fortnox = new FortnoxApiClient({
  clientId: 'your client id',
  clientSecret: 'your client secret',

  // To use endpoints you need to provide either accessToken or refreshToken to the client
  // If refreshToken is provided, the accessToken will be acquired on first request and refreshToken will also refresh
  // To acquire these tokens see above information about authentication/authorization
  accessToken: 'token for Fortnox API',
  refreshToken: 'token for Fortnox API'
});

Example usage after initialization:

const company = await fortnox.api.companyinformation.getCompanyInformationResource();

console.log(company);

Available methods can be found in the API documentation.

Resources

  • Fortnox: https://www.fortnox.se/
  • Fortnox API Guide: https://apps.fortnox.se/apidocs
  • Fortnox Authorization Guide: https://www.fortnox.se/developer/authorization
  • Fortnox API scopes: https://www.fortnox.se/developer/guides-and-good-to-know/scopes