### Installing Fortnox API Client - npm Source: https://github.com/rantalainen/fortnox-api-client/blob/main/README.md Installs the @rantalainen/fortnox-api-client package using the npm package manager. ```shell npm install @rantalainen/fortnox-api-client ``` -------------------------------- ### Importing FortnoxApiClient - JavaScript Source: https://github.com/rantalainen/fortnox-api-client/blob/main/README.md Imports the FortnoxApiClient class from the installed package into a JavaScript or TypeScript file. ```javascript import { FortnoxApiClient } from '@rantalainen/fortnox-api-client'; ``` -------------------------------- ### Initializing FortnoxApiClient - JavaScript Source: https://github.com/rantalainen/fortnox-api-client/blob/main/README.md Creates a new instance of the FortnoxApiClient, configuring it with client credentials and either an access token or a refresh token for API access. ```javascript 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' }); ``` -------------------------------- ### Fetching Company Information - JavaScript Source: https://github.com/rantalainen/fortnox-api-client/blob/main/README.md Demonstrates how to use the initialized FortnoxApiClient instance to call an API endpoint, specifically fetching company information. ```javascript const company = await fortnox.api.companyinformation.getCompanyInformationResource(); console.log(company); ``` -------------------------------- ### Generating Fortnox Authorization URI - JavaScript Source: https://github.com/rantalainen/fortnox-api-client/blob/main/README.md Uses the static createAuthorizationUri method to generate the URL for initiating the Fortnox authorization flow. Requires client ID, redirect URI, scope, state, and type. ```javascript 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' ); ``` -------------------------------- ### Fetching Fortnox Tokens by Authorization Code - JavaScript Source: https://github.com/rantalainen/fortnox-api-client/blob/main/README.md Retrieves access and refresh tokens from Fortnox using the authorization code obtained from the authorization flow. Requires client ID, client secret, redirect URI, and the authorization code. ```javascript // 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 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.