Lager API documentation

  1. API keys
  2. Products
  3. Orders
  4. Order items
  5. Deliveries
  6. Invoices and Login
  7. Copier
  8. Code examples
  9. Local Installation

API keys

Request a personal API key.

An API key is required for all requests.

If an API key is not provided the following error is given:

{
    "errors": {
        "status": 401,
        "source": "/products",
        "title": "Valid API key",
        "detail": "No valid API key provided."
    }
}

Products

A product has the following attributes:

id
article_number
name
description
specifiers
stock
location
price
api_key

To get all your products:

GET /v2/products?api_key=[YOUR_API_KEY]

Result:

{
    "data": [
        {
            "id": 1,
            "article_number": "1214-RNT",
            "name": "Skruv M14",
            "description": "Skruv M14, värmförsinkad",
            "specifiers": "{'length' : '60mm', 'width' : '14mm'}",
            "stock": 12,
            "location": "A1B4",
            "price": 10
        },
        {
            "id": 2,
            "article_number": "1212-RNT",
            "name": "Skruv M12",
            "description": "Skruv M12, värmförsinkad",
            "specifiers": "{'length' : '60mm', 'width' : '12mm'}",
            "stock": 14,
            "location": "A1B5",
            "price": 10
        },
        {
            "id": 3,
            "article_number": "1210-RNT",
            "name": "Skruv M10",
            "description": "Skruv M10, värmförsinkad",
            "specifiers": "{'length' : '60mm', 'width' : '10mm'}",
            "stock": 20,
            "location": "A1B6",
            "price": 10
        },
        {
            "id": 4,
            "article_number": "1208-RNT",
            "name": "Skruv M8",
            "description": "Skruv M8, värmförsinkad",
            "specifiers": "{'length' : '60mm', 'width' : '8mm'}",
            "stock": 2,
            "location": "A1B7",
            "price": 10
        },
        {
            "id": 5,
            "article_number": "1206-RNT",
            "name": "Skruv M6",
            "description": "Skruv M6, värmförsinkad",
            "specifiers": "{'length' : '60mm', 'width' : '6mm'}",
            "stock": 6,
            "location": "A1B8",
            "price": 10
        },
        {
            "id": 6,
            "article_number": "1214-TNT",
            "name": "Mutter M14",
            "description": "Mutter M14, värmförsinkad, passar 1214-RNT",
            "specifiers": "{'diameter' : '14mm'}",
            "stock": 13,
            "location": "A1C4",
            "price": 10
        },
        {
            "id": 7,
            "article_number": "1212-TNT",
            "name": "Mutter M12",
            "description": "Mutter M12, värmförsinkad, passar 1212-RNT",
            "specifiers": "{'diameter' : '12mm'}",
            "stock": 23,
            "location": "A1C4",
            "price": 10
        },
        {
            "id": 8,
            "article_number": "1210-TNT",
            "name": "Mutter M10",
            "description": "Mutter M10, värmförsinkad, passar 1210-RNT",
            "specifiers": "{'diameter' : '10mm'}",
            "stock": 12,
            "location": "A1C4",
            "price": 10
        },
        {
            "id": 9,
            "article_number": "1208-TNT",
            "name": "Mutter M8",
            "description": "Mutter M8, värmförsinkad, passar 1208-RNT",
            "specifiers": "{'diameter' : '8mm'}",
            "stock": 4,
            "location": "A1C4",
            "price": 10
        },
        {
            "id": 10,
            "article_number": "1206-TNT",
            "name": "Mutter M6",
            "description": "Mutter M6, värmförsinkad, passar 1206-RNT",
            "specifiers": "{'diameter' : '6mm'}",
            "stock": 1,
            "location": "A1C4",
            "price": 10
        }
    ]
}

To get a specific product:

GET /v2/products/:product_id?api_key=[YOUR_API_KEY]

Result:

{
    "data": {
        "id": 1,
        "article_number": "1214-RNT",
        "name": "Skruv M14",
        "description": "Skruv M14, värmförsinkad",
        "specifiers": "{'length' : '60mm', 'width' : '14mm'}",
        "stock": 12,
        "location": "A1B4",
        "price": 10
    }
}

To search for a product:

GET /v2/products/search/:query?api_key=[YOUR_API_KEY]

Result (search query was m14):

{
    "data": [
        {
            "id": 1,
            "article_number": "1214-RNT",
            "name": "Skruv M14",
            "description": "Skruv M14, värmförsinkad",
            "specifiers": "{'length' : '60mm', 'width' : '14mm'}",
            "stock": 12,
            "location": "A1B4",
            "price": 10
        },
        {
            "id": 6,
            "article_number": "1214-TNT",
            "name": "Mutter M14",
            "description": "Mutter M14, värmförsinkad, passar 1214-RNT",
            "specifiers": "{'diameter' : '14mm'}",
            "stock": 13,
            "location": "A1C4",
            "price": 10
        }
    ]
}

To add a product:

POST /v2/products

Required parameters:

name
api_key

Optional parameters:

article_number
description
specifiers
stock
location
price

To update a product:

PUT /v2/products

Required parameters:

id
name
api_key

Optional parameters:

name
article_number
description
specifiers
stock
location
price

N.B. All attributes are updated, send an entire product object.

Result:

HTTP Status Code 204 No Content

Possible error, besides errors returned from database:

{
    "errors": {
        "status": 400,
        "detail": "Required attribute product id (id) was not included in the request."
    }
}

To delete a product:

DELETE /v2/products

Required parameters:

id
api_key

Result:

HTTP Status Code 204 No Content

Possible error, besides errors returned from database:

{
    "errors": {
        "status": 400,
        "detail": "Required attribute product id (id) was not included in the request."
    }
}

Orders

An order has the following attributes:

id
name
address
zip
city
country
status_id
api_key

Status

All orders have a status, it can take the following numeric values, corresponding to the descriptions. Orders have a default status value of 100.

100: "Ny"
200: "Packad"
400: "Skickad"
600: "Fakturerad"
800: "Retur"
900: "Återbetald"

To get all your orders and associated order items:

GET /v2/orders?api_key=[YOUR_API_KEY]

Result:

{
  "data": [
    {
      "id": 1,
      "name": "Anders Andersson",
      "address": "Andersgatan 1",
      "zip": "12345",
      "city": "Anderstorp",
      "country": "Sweden",
      "status": "Ny",
      "status_id": 100,
      "order_items": [
        {
          "product_id": 1,
          "amount": 2,
          "article_number": "1214-RNT",
          "name": "Skruv M14",
          "description": "Skruv M14, värmförsinkad",
          "specifiers": "{'length' : '60mm', 'width' : '14mm'}",
          "stock": 12,
          "location": "A1B4",
          "price": 10
        },
        {
          "product_id": 2,
          "amount": 3,
          "article_number": "1212-RNT",
          "name": "Skruv M12",
          "description": "Skruv M12, värmförsinkad",
          "specifiers": "{'length' : '60mm', 'width' : '12mm'}",
          "stock": 14,
          "location": "A1B5",
          "price": 10
        }
      ]
    },
    {
      "id": 2,
      "name": "Bengt Bengtsson",
      "address": "Bengtsgatan 2",
      "zip": "23457",
      "city": "Bengtfors",
      "country": "Sweden",
      "status": "Ny",
      "status_id": 100,
      "order_items": [
        {
          "product_id": 3,
          "amount": 4,
          "article_number": "1210-RNT",
          "name": "Skruv M10",
          "description": "Skruv M10, värmförsinkad",
          "specifiers": "{'length' : '60mm', 'width' : '10mm'}",
          "stock": 20,
          "location": "A1B6",
          "price": 10
        }
      ]
    },
    {
      "id": 3,
      "name": "Nora Norrby",
      "address": "Norasgatan 3",
      "zip": "34567",
      "city": "Nora",
      "country": "Sweden",
      "status": "Ny",
      "status_id": 100,
      "order_items": [
        {
          "product_id": 6,
          "amount": 5,
          "article_number": "1214-TNT",
          "name": "Mutter M14",
          "description": "Mutter M14, värmförsinkad, passar 1214-RNT",
          "specifiers": "{'diameter' : '14mm'}",
          "stock": 13,
          "location": "A1C4",
          "price": 10
        }
      ]
    },
    {
      "id": 4,
      "name": "Ulla Ullman Davidsson",
      "address": "Ullasallén 4",
      "zip": "45678",
      "city": "Ullared",
      "country": "Sweden",
      "status": "Ny",
      "status_id": 100,
      "order_items": [
        {
          "product_id": 8,
          "amount": 6,
          "article_number": "1210-TNT",
          "name": "Mutter M10",
          "description": "Mutter M10, värmförsinkad, passar 1210-RNT",
          "specifiers": "{'diameter' : '10mm'}",
          "stock": 12,
          "location": "A1C4",
          "price": 10
        }
      ]
    }
  ]
}

To get a specific order and associated order items:

GET /v2/orders/:order_id?api_key=[YOUR_API_KEY]

Result:

{
  "data": {
    "id": 1,
    "name": "Anders Andersson",
    "address": "Andersgatan 1",
    "zip": "12345",
    "city": "Anderstorp",
    "country": "Sweden",
    "status": "Ny",
    "status_id": 100,
    "order_items": [
      {
        "product_id": 1,
        "amount": 2,
        "article_number": "1214-RNT",
        "name": "Skruv M14",
        "description": "Skruv M14, värmförsinkad",
        "specifiers": "{'length' : '60mm', 'width' : '14mm'}",
        "stock": 12,
        "location": "A1B4",
        "price": 10
      },
      {
        "product_id": 2,
        "amount": 3,
        "article_number": "1212-RNT",
        "name": "Skruv M12",
        "description": "Skruv M12, värmförsinkad",
        "specifiers": "{'length' : '60mm', 'width' : '12mm'}",
        "stock": 14,
        "location": "A1B5",
        "price": 10
      }
    ]
  }
}

To search for an order and associated order items:

You can search on the following parameters: name, address, zip, city and country.

GET /v2/orders/search/:query?api_key=[YOUR_API_KEY]

Result (search query was anders):

{
  "data": [
    {
      "id": 1,
      "name": "Anders Andersson",
      "address": "Andersgatan 1",
      "zip": "12345",
      "city": "Anderstorp",
      "country": "Sweden",
      "status": "Ny",
      "status_id": 100,
      "order_items": [
        {
          "product_id": 1,
          "amount": 2,
          "article_number": "1214-RNT",
          "name": "Skruv M14",
          "description": "Skruv M14, värmförsinkad",
          "specifiers": "{'length' : '60mm', 'width' : '14mm'}",
          "stock": 12,
          "location": "A1B4",
          "price": 10
        },
        {
          "product_id": 2,
          "amount": 3,
          "article_number": "1212-RNT",
          "name": "Skruv M12",
          "description": "Skruv M12, värmförsinkad",
          "specifiers": "{'length' : '60mm', 'width' : '12mm'}",
          "stock": 14,
          "location": "A1B5",
          "price": 10
        }
      ]
    }
  ]
}

To add an order:

POST /v2/orders

Required parameters:

name
api_key

Optional parameters:

address
zip
city
country
status_id (default value of 100)

NB! Use a numeric status_id value to add status.

To update an order:

PUT /v2/orders

Required parameters:

id
name
api_key

Optional parameters:

name
address
zip
city
country
status_id (default value of 100)

NB! Use a numeric status_id value to update status.

N.B. All attributes are updated, send an entire order object. Send only the order parameters when updating an order. order_items are updated seperately, see order items

Result:

HTTP Status Code 204 No Content

Possible error, besides errors returned from database:

{
    "errors": {
        "status": 400,
        "detail": "Required attribute order id (id) was not included in the request."
    }
}

To delete an order and associated order items:

DELETE /v2/orders

Required parameters:

id
api_key

Result:

HTTP Status Code 204 No Content

Possible error, besides errors returned from database:

{
    "errors": {
        "status": 400,
        "detail": "Required attribute order id (id) was not included in the request."
    }
}

Order items

An order item has the following attributes:

order_id
product_id
amount
api_key

To add an order item to an order:

POST /v2/order_items

Required parameters:

order_id
product_id
amount
api_key

To update an order item:

PUT /v2/order_items

Required parameters:

order_id
product_id
api_key

Optional parameter:

amount

N.B. All attributes are updated, send an entire order object.

Result:

HTTP Status Code 204 No Content

Possible error, besides errors returned from database:

{
    "errors": {
        "status": 400,
        "detail": "Required attributes order_id and product_id was not included in the request."
    }
}

To delete an order item:

DELETE /v2/order_items

Required parameters:

order_id
product_id
api_key

Result:

HTTP Status Code 204 No Content

Possible error, besides errors returned from database:

{
    "errors": {
        "status": 400,
        "detail": "Required attribute order id and product id was not included in the request."
    }
}

Deliveries

A delivery has the following attributes:

id
product_id
product_name
amount
delivery_date
comment
api_key

Get all deliveries

GET /v2/deliveries?api_key=[YOUR_API_KEY]

Result

{
    "data": [
        {
            "id": 1,
            "product_id": 2,
            "product_name": "Geléhjärtan",
            "amount": 10,
            "delivery_date": "2018-02-14",
            "comment": "Inleverans för Alla Hjärtans dag"
        }
    ]
}

Add a delivery

POST /v2/deliveries

Required parameters:

product_id
amount
delivery_date
api_key

Optional parameter:

comment

Result:

{
    "data": {
        "id": 1,
        "product_id": 2,
        "product_name": "Geléhjärtan",
        "amount": 10,
        "delivery_date": "2018-02-14",
        "comment": "Inleverans för Alla Hjärtans dag"
    }
}

To delete a delivery

DELETE /v2/deliveries

Required parameters:

id
api_key

Result:

HTTP Status Code 204 No Content

Possible error, besides errors returned from database:

{
    "errors": {
        "status": 400,
        "detail": "Required attribute delivery id (id) was not included in the request."
    }
}

Invoices and Login

An invoice has the following attributes:

id
order_id
total_price
creation_date
due_date
api_key

To use the following routes, you need a valid JSON Web Token (JWT) set in the HTTP-header.
The 'x-access-token' header should contain the JWT.

GET /v2/invoices?api_key=[YOUR_API_KEY]
GET /v2/invoices/:invoice_id?api_key=[YOUR_API_KEY]
POST /v2/invoices

Register

POST /v2/auth/register

Required paramters:

api_key
email
password

Result:

{
    "data": {
        "message": "User successfully registered."
    }
}

Login

POST /v2/auth/login
api_key
email
password

Result:

{
    "data": {
        "type": "success",
        "message": "User logged in",
        "user": {
            "api_key": "...",
            "email": "unknown@example.com"
        },
        "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.ey..."
    }
}

N.B. The access token expires after 24 hours.

Get all invoices

GET /v2/invoices?api_key=[YOUR_API_KEY]

Result:

{
    "data": [
        {
            "id": 1,
            "order_id": 1,
            "name": "Anders Andersson",
            "address": "Andersgatan 1",
            "zip": "12345",
            "city": "Anderstorp",
            "country": "Sweden",
            "total_price": 100,
            "creation_date": "2019-02-13",
            "due_date": "2019-03-13"
        }
    ]
}

Get specific invoice

GET /v2/invoices/:invoice_id?api_key=[YOUR_API_KEY]

Result:

{
    "data": {
        "id": 1,
        "order_id": 1,
        "name": "Anders Andersson",
        "address": "Andersgatan 1",
        "zip": "12345",
        "city": "Anderstorp",
        "country": "Sweden",
        "total_price": 100,
        "creation_date": "2019-02-13",
        "due_date": "2019-03-13"
    }
}

Add invoice

POST /v2/invoices

Required parameters:

order_id
total_price
api_key

Optional parameters:

creation_date
due_date

Result:

{
    "data": {
        "id": 1,
        "order_id": 1,
        "name": "Anders Andersson",
        "address": "Andersgatan 1",
        "zip": "12345",
        "city": "Anderstorp",
        "country": "Sweden",
        "total_price": 100,
        "creation_date": "2019-02-13",
        "due_date": "2019-03-13"
    }
}

Copier

As always 'api_key' is a required parameter.

Copy products

POST /v2/copier/products

Result:

{
    "data": [
        {
            "id": 1,
            "article_number": "1214-RNT",
            "name": "Skruv M14",
            "description": "Skruv M14, värmförsinkad",
            "specifiers": "{'length' : '60mm', 'width' : '14mm'}",
            "stock": 12,
            "location": "A1B4",
            "price": 10
        },
        {
            "id": 2,
            "article_number": "1212-RNT",
            "name": "Skruv M12",
            "description": "Skruv M12, värmförsinkad",
            "specifiers": "{'length' : '60mm', 'width' : '12mm'}",
            "stock": 14,
            "location": "A1B5",
            "price": 10
        },
        {
            "id": 3,
            "article_number": "1210-RNT",
            "name": "Skruv M10",
            "description": "Skruv M10, värmförsinkad",
            "specifiers": "{'length' : '60mm', 'width' : '10mm'}",
            "stock": 20,
            "location": "A1B6",
            "price": 10
        },
        {
            "id": 4,
            "article_number": "1208-RNT",
            "name": "Skruv M8",
            "description": "Skruv M8, värmförsinkad",
            "specifiers": "{'length' : '60mm', 'width' : '8mm'}",
            "stock": 2,
            "location": "A1B7",
            "price": 10
        },
        {
            "id": 5,
            "article_number": "1206-RNT",
            "name": "Skruv M6",
            "description": "Skruv M6, värmförsinkad",
            "specifiers": "{'length' : '60mm', 'width' : '6mm'}",
            "stock": 6,
            "location": "A1B8",
            "price": 10
        },
        {
            "id": 6,
            "article_number": "1214-TNT",
            "name": "Mutter M14",
            "description": "Mutter M14, värmförsinkad, passar 1214-RNT",
            "specifiers": "{'diameter' : '14mm'}",
            "stock": 13,
            "location": "A1C4",
            "price": 10
        },
        {
            "id": 7,
            "article_number": "1212-TNT",
            "name": "Mutter M12",
            "description": "Mutter M12, värmförsinkad, passar 1212-RNT",
            "specifiers": "{'diameter' : '12mm'}",
            "stock": 23,
            "location": "A1C4",
            "price": 10
        },
        {
            "id": 8,
            "article_number": "1210-TNT",
            "name": "Mutter M10",
            "description": "Mutter M10, värmförsinkad, passar 1210-RNT",
            "specifiers": "{'diameter' : '10mm'}",
            "stock": 12,
            "location": "A1C4",
            "price": 10
        },
        {
            "id": 9,
            "article_number": "1208-TNT",
            "name": "Mutter M8",
            "description": "Mutter M8, värmförsinkad, passar 1208-RNT",
            "specifiers": "{'diameter' : '8mm'}",
            "stock": 4,
            "location": "A1C4",
            "price": 10
        },
        {
            "id": 10,
            "article_number": "1206-TNT",
            "name": "Mutter M6",
            "description": "Mutter M6, värmförsinkad, passar 1206-RNT",
            "specifiers": "{'diameter' : '6mm'}",
            "stock": 1,
            "location": "A1C4",
            "price": 10
        }
    ]
}

Copy products & orders

POST /v2/copier/all

Result:

{
    "data": {
        "products": [
            {
                "id": 1,
                "article_number": "1214-RNT",
                "name": "Skruv M14",
                "description": "Skruv M14, värmförsinkad",
                "specifiers": "{'length' : '60mm', 'width' : '14mm'}",
                "stock": 12,
                "location": "A1B4",
                "price": 10
            },
            {
                "id": 2,
                "article_number": "1212-RNT",
                "name": "Skruv M12",
                "description": "Skruv M12, värmförsinkad",
                "specifiers": "{'length' : '60mm', 'width' : '12mm'}",
                "stock": 14,
                "location": "A1B5",
                "price": 10
            },
            {
                "id": 3,
                "article_number": "1210-RNT",
                "name": "Skruv M10",
                "description": "Skruv M10, värmförsinkad",
                "specifiers": "{'length' : '60mm', 'width' : '10mm'}",
                "stock": 20,
                "location": "A1B6",
                "price": 10
            },
            {
                "id": 4,
                "article_number": "1208-RNT",
                "name": "Skruv M8",
                "description": "Skruv M8, värmförsinkad",
                "specifiers": "{'length' : '60mm', 'width' : '8mm'}",
                "stock": 2,
                "location": "A1B7",
                "price": 10
            },
            {
                "id": 5,
                "article_number": "1206-RNT",
                "name": "Skruv M6",
                "description": "Skruv M6, värmförsinkad",
                "specifiers": "{'length' : '60mm', 'width' : '6mm'}",
                "stock": 6,
                "location": "A1B8",
                "price": 10
            },
            {
                "id": 6,
                "article_number": "1214-TNT",
                "name": "Mutter M14",
                "description": "Mutter M14, värmförsinkad, passar 1214-RNT",
                "specifiers": "{'diameter' : '14mm'}",
                "stock": 13,
                "location": "A1C4",
                "price": 10
            },
            {
                "id": 7,
                "article_number": "1212-TNT",
                "name": "Mutter M12",
                "description": "Mutter M12, värmförsinkad, passar 1212-RNT",
                "specifiers": "{'diameter' : '12mm'}",
                "stock": 23,
                "location": "A1C4",
                "price": 10
            },
            {
                "id": 8,
                "article_number": "1210-TNT",
                "name": "Mutter M10",
                "description": "Mutter M10, värmförsinkad, passar 1210-RNT",
                "specifiers": "{'diameter' : '10mm'}",
                "stock": 12,
                "location": "A1C4",
                "price": 10
            },
            {
                "id": 9,
                "article_number": "1208-TNT",
                "name": "Mutter M8",
                "description": "Mutter M8, värmförsinkad, passar 1208-RNT",
                "specifiers": "{'diameter' : '8mm'}",
                "stock": 4,
                "location": "A1C4",
                "price": 10
            },
            {
                "id": 10,
                "article_number": "1206-TNT",
                "name": "Mutter M6",
                "description": "Mutter M6, värmförsinkad, passar 1206-RNT",
                "specifiers": "{'diameter' : '6mm'}",
                "stock": 1,
                "location": "A1C4",
                "price": 10
            }
        ],
        "orders": [
          {
            "id": 1,
            "name": "Anders Andersson",
            "address": "Andersgatan 1",
            "zip": "12345",
            "city": "Anderstorp",
            "country": "Sweden",
            "status": "Ny",
            "status_id": 100,
            "order_items": [
              {
                "product_id": 1,
                "amount": 2,
                "article_number": "1214-RNT",
                "name": "Skruv M14",
                "description": "Skruv M14, värmförsinkad",
                "specifiers": "{'length' : '60mm', 'width' : '14mm'}",
                "stock": 12,
                "location": "A1B4",
                "price": 10
              },
              {
                "product_id": 2,
                "amount": 3,
                "article_number": "1212-RNT",
                "name": "Skruv M12",
                "description": "Skruv M12, värmförsinkad",
                "specifiers": "{'length' : '60mm', 'width' : '12mm'}",
                "stock": 14,
                "location": "A1B5",
                "price": 10
              }
            ]
          },
          {
            "id": 2,
            "name": "Bengt Bengtsson",
            "address": "Bengtsgatan 2",
            "zip": "23457",
            "city": "Bengtfors",
            "country": "Sweden",
            "status": "Ny",
            "status_id": 100,
            "order_items": [
              {
                "product_id": 3,
                "amount": 4,
                "article_number": "1210-RNT",
                "name": "Skruv M10",
                "description": "Skruv M10, värmförsinkad",
                "specifiers": "{'length' : '60mm', 'width' : '10mm'}",
                "stock": 20,
                "location": "A1B6",
                "price": 10
              }
            ]
          },
          {
            "id": 3,
            "name": "Nora Norrby",
            "address": "Norasgatan 3",
            "zip": "34567",
            "city": "Nora",
            "country": "Sweden",
            "status": "Ny",
            "status_id": 100,
            "order_items": [
              {
                "product_id": 6,
                "amount": 5,
                "article_number": "1214-TNT",
                "name": "Mutter M14",
                "description": "Mutter M14, värmförsinkad, passar 1214-RNT",
                "specifiers": "{'diameter' : '14mm'}",
                "stock": 13,
                "location": "A1C4",
                "price": 10
              }
            ]
          },
          {
            "id": 4,
            "name": "Ulla Ullman Davidsson",
            "address": "Ullasallén 4",
            "zip": "45678",
            "city": "Ullared",
            "country": "Sweden",
            "status": "Ny",
            "status_id": 100,
            "order_items": [
              {
                "product_id": 8,
                "amount": 6,
                "article_number": "1210-TNT",
                "name": "Mutter M10",
                "description": "Mutter M10, värmförsinkad, passar 1210-RNT",
                "specifiers": "{'diameter' : '10mm'}",
                "stock": 12,
                "location": "A1C4",
                "price": 10
              }
            ]
          }
        ]
    }
}

Code Examples

All examples below show the following API calls:

GET /v2/products
PUT /v2/order
GET /v2/invoices
  1. XMLHttpRequest
  2. fetch
  3. mithril m.request

XMLHttpRequest

GET /v2/products
                    var request = new XMLHttpRequest();

request.addEventListener("load", [callbackFunction]);
request.open("GET", "https://lager.emilfolino.se/v2/products?api_key=[YOUR_API_KEY]");
request.send();
                
PUT /v2/orders
                    // Updating status for order, setting 200 as new status
var order = {
    id: 1,
    name: "Anders Andersson",
    address: "Andersgatan 1",
    zip: "12345",
    city: "Anderstorp",
    country: "Sweden",
    status_id: 200,
    api_key: [YOUR_API_KEY]
};
var json = JSON.stringify(order);

var request = new XMLHttpRequest();
request.addEventListener("load", [callbackFunction]);
request.open("PUT", "https://lager.emilfolino.se/v2/orders");
request.setRequestHeader('Content-type','application/json; charset=utf-8');
request.send(json);
                
POST /v2/deliveries
                    // Creating new delivery
var delivery = {
    product_id: 2,
    amount: 12,
    delivery_date: "2018-02-14",
    comment: "Delivery for Valentines Day",
    api_key: [YOUR_API_KEY]
};
var json = JSON.stringify(delivery);

var request = new XMLHttpRequest();
request.addEventListener("load", [callbackFunction]);
request.open("POST", "https://lager.emilfolino.se/v2/deliveries");
request.setRequestHeader('Content-type','application/json; charset=utf-8');
request.send(json);
                
GET /v2/invoices
                    var token = [TOKEN]; // Token received during login
var request = new XMLHttpRequest();
request.addEventListener("load", [callbackFunction]);
request.open("GET", "https://lager.emilfolino.se/v2/invoices?api_key=[YOUR_API_KEY]");
request.setRequestHeader('x-access-token', token);
request.send();
                

fetch

GET /v2/products
                    fetch("https://lager.emilfolino.se/v2/products?api_key=[YOUR_API_KEY]")
.then(function (response) {
    return response.json();
}).then(function(data) {

});
                
PUT /v2/orders
                    var order = {
    id: 1,
    name: "Anders Andersson",
    address: "Andersgatan 1",
    zip: "12345",
    city: "Anderstorp",
    country: "Sweden",
    status_id: 200,
    api_key: [YOUR_API_KEY]
};

fetch("https://lager.emilfolino.se/v2/orders", {
    body: JSON.stringify(order),
    headers: {
      'content-type': 'application/json'
    },
    method: 'PUT'
})
.then(function (response) {

});
                
POST /v2/deliveries
                    var delivery = {
    product_id: 2,
    amount: 12,
    delivery_date: "2018-02-14",
    comment: "Delivery for Valentines Day",
    api_key: [YOUR_API_KEY]
};

fetch("https://lager.emilfolino.se/v2/deliveries", {
    body: JSON.stringify(delivery),
    headers: {
      'content-type': 'application/json'
    },
    method: 'POST'
})
.then(function (response) {

});
                
GET /v2/invoices
                    fetch("https://lager.emilfolino.se/v2/invoices?api_key=[YOUR_API_KEY]", {
    headers: {
      'x-access-token': [TOKEN]
    },
})
.then(function (response) {
    return response.json();
}).then(function(data) {

});
                

mithril m.request

GET /v2/products
                    m.request({
    method: "GET",
    url: "https://lager.emilfolino.se/v2/products?api_key=[YOUR_API_KEY]"
})
.then(function(result) {

});
                
PUT /v2/orders
                    var order = {
    id: 1,
    name: "Anders Andersson",
    address: "Andersgatan 1",
    zip: "12345",
    city: "Anderstorp",
    country: "Sweden",
    status_id: 200,
    api_key: [YOUR_API_KEY]
};

m.request({
    method: "PUT",
    url: "https://lager.emilfolino.se/v2/orders",
    data: order
});
                
POST /v2/deliveries
                    var delivery = {
    product_id: 2,
    amount: 12,
    delivery_date: "2018-02-14",
    comment: "Delivery for Valentines Day",
    api_key: [YOUR_API_KEY]
};

m.request({
    method: "POST",
    url: "https://lager.emilfolino.se/v2/deliveries",
    data: delivery
});
                
GET /v2/invoices
                    m.request({
    method: "GET",
    url: "https://lager.emilfolino.se/v2/invoices?api_key=[YOUR_API_KEY]",
    headers: {
        'x-access-token': [TOKEN]
    }
})
.then(function(result) {

});