modules

ac-apps-minimal-api-fortnox

api/fortnox.js

Makes it easy to work with Fortnox API.

Example:
app.api.fortnox.createOrder(options, order);
app.api.fortnox.updateCustomer(options, customer);
app.api.fortnox.getCustomers(options, email);

A module for ac-bundle-app, published by ac-bundle-module. namespace: ac-apps-minimal

Install from:

https://www.npmjs.com/package/ac-apps-minimal-api-fortnox
https://github.com/animatedcreativity/ac-apps-minimal-api-fortnox

Available Methods: createOrder, updateCustomer, createCustomer, getCustomers

createOrder

async function(options, newFnOrder) {
  var url = options.fnApiUrl + "orders";
  console.log(app.consoleColors.bgBlue, "POST Creating order:", newFnOrder.Order.YourOrderNumber + " " + url);
  var result = await fetch(url, {
    method: "POST",
    headers: {
      "Accept": "application/json",
      "Accept-Encoding": "application/json",
      "Content-Type": "application/json",
      "Access-Token": options.fnAccessToken,
      "Client-Secret": options.fnClientSecret,
    },
    body: JSON.stringify(newFnOrder)
  });
  if (result.status >= 200 && result.status <= 201) {
    return await result.json();
  }
}

updateCustomer

async function(options, CustomerNumber, updatedFnCustomer) {
  var url = options.fnApiUrl + "customers/" + CustomerNumber;
  console.log(app.consoleColors.bgBlue, "PUT Updating customer:", updatedFnCustomer.Customer.Email + " " + url);
  var result = await fetch(url, {
    method: "PUT",
    headers: {
      "Accept": "application/json",
      "Accept-Encoding": "application/json",
      "Content-Type": "application/json",
      "Access-Token": options.fnAccessToken,
      "Client-Secret": options.fnClientSecret,
    },
    body: JSON.stringify(updatedFnCustomer)
  });
  if (result.status >= 200 && result.status <= 201) {
    return await result.json();
  }
}

createCustomer

async function(options, newFnCustomer) {
  var url = options.fnApiUrl + "customers";
  console.log(app.consoleColors.bgBlue, "POST Creating customer:", newFnCustomer.Email + " " + url);
  var result = await fetch(url, {
    method: "POST",
    headers: {
      "Accept": "application/json",
      "Accept-Encoding": "application/json",
      "Content-Type": "application/json",
      "Access-Token": options.fnAccessToken,
      "Client-Secret": options.fnClientSecret,
    },
    body: JSON.stringify(newFnCustomer)
  });
  if (result.status >= 200 && result.status <= 201) {
    return await result.json();
  }
}

getCustomers

async function(options, email) {
  var url = options.fnApiUrl + "customers?email=" + email;
  console.log(app.consoleColors.bgBlue, "Getting customer:", email + " " + url);
  var result = await fetch(url, {
    method: "GET",
    headers: {
      "Accept": "application/json",
      "Accept-Encoding": "application/json",
      "Content-Type": "application/json",
      "Access-Token": options.fnAccessToken,
      "Client-Secret": options.fnClientSecret,
    }
  });
  if (result.status === 200) {
    var json = await result.json();
    return json.Customers;
  }
}

Happy Coding!

MIT License: https://choosealicense.com/licenses/mit/

Copyright 2022 Animated Creativity

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Leave a Reply

Your email address will not be published. Required fields are marked *