Labels are used to mark offers, orders and invoices with specific labels. The labels need to be predefined in this register before they can be used on a document.

List all labels

Retrieves a list of all the available labels.

Examples

Request

curl -X "GET" "https://api.fortnox.se/3/labels" \
     -H "Access-Token: 61cf63ae-4ab9-4a95-9db5-753781c4f41f" \
     -H "Client-Secret: 3Er4kHXZTJ" \
     -H "Content-Type: application/json" \
     -H "Accept: application/json"

Response

{
   "Labels": [
      {
         "Id": 1,
         "Description": "Campaign"
      },
      {
         "Id": 2,
         "Description": "Open"
      },
      {
         "Id": 3,
         "Description": "Closed"
      }
   ]
}

Using Guzzle

Request

// Include Guzzle. If using Composer:
// require 'vendor/autoload.php';

use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;

function send_request() {
    // Labels (GET https://api.fortnox.se/3/labels)

    $client = new Client();
    $request = $client->createRequest('GET', 'https://api.fortnox.se/3/labels');

    try {
        $request->addHeaders([
            'Access-Token'=>'61cf63ae-4ab9-4a95-9db5-753781c4f41f',
            'Client-Secret'=>'3Er4kHXZTJ',
            'Content-Type'=>'application/json',
            'Accept'=>'application/json',
        ]);

        $response = $client->send($request);
        echo "Response HTTP : " . $response->getStatusCode();
    }
    catch (RequestException $e) {
        echo "HTTP Request failed\n";
        echo $e->getRequest();
        if ($e->hasResponse()) {
            echo $e->getResponse();
        }
    }
}

Response

{
   "Labels": [
      {
         "Id": 1,
         "Description": "Campaign"
      },
      {
         "Id": 2,
         "Description": "Open"
      },
      {
         "Id": 3,
         "Description": "Closed"
      }
   ]
}

Request

require 'uri'
require 'net/https'

# Request: Labels (https://api.fortnox.se/3/labels)

uri = URI.parse("https://api.fortnox.se/3/labels")
http = Net::HTTP.new(uri.host, uri.port)
http.read_timeout = 30
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
request = Net::HTTP::Get.new(uri.request_uri)

# Headers

request["Client-Secret"] = "3Er4kHXZTJ"
request["Content-Type"] = "application/json"
request["Access-Token"] = "61cf63ae-4ab9-4a95-9db5-753781c4f41f"
request["Accept"] = "application/json"

# Send synchronously

response = http.request(request)

Response

{
   "Labels": [
      {
         "Id": 1,
         "Description": "Campaign"
      },
      {
         "Id": 2,
         "Description": "Open"
      },
      {
         "Id": 3,
         "Description": "Closed"
      }
   ]
}

Request

import httplib

# Request: Labels (https://api.fortnox.se/3/labels)

connection = httplib.HTTPSConnection('api.fortnox.se', 443, timeout = 30)

# Headers

headers = {"Client-Secret":"3Er4kHXZTJ",
           "Content-Type":"application/json",
           "Access-Token":"61cf63ae-4ab9-4a95-9db5-753781c4f41f",
           "Accept":"application/json"}

# Send synchronously

connection.request('GET', '/3/labels', None, headers)
try:
	response = connection.getresponse()
	content = response.read()
	# Success
	print('Response status ' + str(response.status))
except httplib.HTTPException, e:
	# Exception
	print('Exception during request')

Response

{
   "Labels": [
      {
         "Id": 1,
         "Description": "Campaign"
      },
      {
         "Id": 2,
         "Description": "Open"
      },
      {
         "Id": 3,
         "Description": "Closed"
      }
   ]
}

Create a label

The created label will be returned if everything succeeded, if there was any problems an error will be returned.

Examples

Request

curl -X "POST" "https://api.fortnox.se/3/labels" \
     -H "Access-Token: 61cf63ae-4ab9-4a95-9db5-753781c4f41f" \
     -H "Client-Secret: 3Er4kHXZTJ" \
     -H "Content-Type: application/json" \
     -H "Accept: application/json" \
     -d $'{
  "Label": {
    "Description": "Special"
  }
}'

Response

{
  "Label": {
    "Id": 25,
    "Description": "Special"
  }
}

Using Guzzle

Request

// Include Guzzle. If using Composer:
// require 'vendor/autoload.php';

use GuzzleHttp\Client;
use GuzzleHttp\Post\PostBody;
use GuzzleHttp\Stream\StreamInterface;
use GuzzleHttp\Exception\RequestException;

function send_request() {
    // Labels (POST https://api.fortnox.se/3/labels)

    $client = new Client();
    $request = $client->createRequest('POST', 'https://api.fortnox.se/3/labels');
    $postBody = $request->getBody();

    try {
        $request->addHeaders([
            'Access-Token'=>'61cf63ae-4ab9-4a95-9db5-753781c4f41f',
            'Client-Secret'=>'3Er4kHXZTJ',
            'Content-Type'=>'application/json',
            'Accept'=>'application/json',
        ]);
        $body = [
            "Label" => [
                "Description" => "Special"
            ]
        ];
        $request->setBody(GuzzleHttp\Stream\Stream::factory(json_encode($body)));

        $response = $client->send($request);
        echo "Response HTTP : " . $response->getStatusCode();
    }
    catch (RequestException $e) {
        echo "HTTP Request failed\n";
        echo $e->getRequest();
        if ($e->hasResponse()) {
            echo $e->getResponse();
        }
    }
}

Response

{
  "Label": {
    "Id": 25,
    "Description": "Special"
  }
}

Request

require 'net/http'
require 'json'

def send_request
    # Labels (POST https://api.fortnox.se/3/labels)

    begin
        uri = URI('https://api.fortnox.se/3/labels')

        http = Net::HTTP.new(uri.host, uri.port)
        req =  Net::HTTP::Post.new(uri)

        req.add_field "Access-Token, 61cf63ae-4ab9-4a95-9db5-753781c4f41f"
        req.add_field "Client-Secret, 3Er4kHXZTJ"
        req.add_field "Content-Type, application/json"
        req.add_field "Accept, application/json"

        data = JSON.dump({
            "Label": {
                "Description": "Special"
            }
        })
        req.body = data

        res = http.request(req)
        puts "Response HTTP #{res.code}"
    rescue Exception => e
        puts "HTTP Request failed (#{e.message})"
    end
end

Response

{
  "Label": {
    "Id": 25,
    "Description": "Special"
  }
}

Request

import requests
import json

def send_request():
    # Labels (POST https://api.fortnox.se/3/labels)

    try:
        r = requests.post(
            url="https://api.fortnox.se/3/labels",
            headers = {
                "Access-Token":"61cf63ae-4ab9-4a95-9db5-753781c4f41f",
                "Client-Secret":"3Er4kHXZTJ",
                "Content-Type":"application/json",
                "Accept":"application/json",
            },
            data = json.dumps({
                "Label": {
                    "Description": "Special"
                }
            })
        )
        print('Response HTTP {status_code}'.format(status_code=r.status_code))
    except requests.exceptions.RequestException as e:
        print('HTTP Request failed')

Response

{
  "Label": {
    "Id": 25,
    "Description": "Special"
  }
}

Update a label

Updates the specified label with the values provided in the properties. Any property not provided will be left unchanged.

Examples

Request

curl -X "PUT" "https://api.fortnox.se/3/labels/25" \
     -H "Access-Token: 61cf63ae-4ab9-4a95-9db5-753781c4f41f" \
     -H "Client-Secret: 3Er4kHXZTJ" \
     -H "Content-Type: application/json" \
     -H "Accept: application/json" \
     -d $'{
  "Label": {
    "Description": "SpecialDelivery"
  }
}'

Response

{
  "Label": {
    "Id": 25,
    "Description": "SpecialDelivery"
  }
}

Using Guzzle

Request

// Include Guzzle. If using Composer:
// require 'vendor/autoload.php';

use GuzzleHttp\Client;
use GuzzleHttp\Post\PostBody;
use GuzzleHttp\Stream\StreamInterface;
use GuzzleHttp\Exception\RequestException;

function send_request() {
    // Label (PUT https://api.fortnox.se/3/labels/25)

    $client = new Client();
    $request = $client->createRequest('PUT', 'https://api.fortnox.se/3/labels/25');
    $postBody = $request->getBody();

    try {
        $request->addHeaders([
            'Access-Token'=>'61cf63ae-4ab9-4a95-9db5-753781c4f41f',
            'Client-Secret'=>'3Er4kHXZTJ',
            'Content-Type'=>'application/json',
            'Accept'=>'application/json',
        ]);
        $body = [
            "Label" => [
                "Description" => "SpecialDelivery"
            ]
        ];
        $request->setBody(GuzzleHttp\Stream\Stream::factory(json_encode($body)));

        $response = $client->send($request);
        echo "Response HTTP : " . $response->getStatusCode();
    }
    catch (RequestException $e) {
        echo "HTTP Request failed\n";
        echo $e->getRequest();
        if ($e->hasResponse()) {
            echo $e->getResponse();
        }
    }
}

Response

{
  "Label": {
    "Id": 25,
    "Description": "SpecialDelivery"
  }
}

Request

require 'net/http'
require 'json'

def send_request
    # Label (PUT )

    begin
        uri = URI('https://api.fortnox.se/3/labels/25')

        # Create client          
        http = Net::HTTP.new(uri.host, uri.port)

        dict = {
            "Label" => {
                "Description" => "SpecialDelivery"
            }
        }
        body = JSON.dump(dict)

        # Create Request
        req =  Net::HTTP::Put.new(uri)
        # Add headers
        req.add_field "Access-Token", "61cf63ae-4ab9-4a95-9db5-753781c4f41f"
        # Add headers
        req.add_field "Client-Secret", "3Er4kHXZTJ"
        # Add headers
        req.add_field "Content-Type", "application/json"
        # Add headers
        req.add_field "Accept", "application/json"
        # Set header and body
        req.add_field "Content-Type", "application/json"
        req.body = body

        # Fetch Request
        res = http.request(req)
        puts "Response HTTP Status Code: #{res.code}"
        puts "Response HTTP Response Body: #{res.body}"
    rescue Exception => e
        puts "HTTP Request failed (#{e.message})"
    end
end

Response

{
  "Label": {
    "Id": 25,
    "Description": "Special"
  }
}

Request

# Install the Python Requests library:
# `pip install requests`

import requests
import json

def send_request():
    # Label (PUT https://api.fortnox.se/3/labels/25)

    try:
        r = requests.put(
            url="https://api.fortnox.se/3/labels/25",
            headers = {
                "Access-Token":"61cf63ae-4ab9-4a95-9db5-753781c4f41f",
                "Client-Secret":"3Er4kHXZTJ",
                "Content-Type":"application/json",
                "Accept":"application/json",
            },
            data = json.dumps({
                "Account": {
                    "Description": "SpecialDelivery"
                }
            })
        )
        print('Response HTTP Status Code : {status_code}'.format(status_code=r.status_code))
        print('Response HTTP Response Body : {content}'.format(content=r.content))
    except requests.exceptions.RequestException as e:
        print('HTTP Request failed')

Response

{
  "Label": {
    "Id": 25,
    "Description": "Special"
  }
}

Delete a label

Deletes the label and it’s connection to documents permanently.

You need to supply the unique label id that was returned when the label was created or retrieved from the list of labels.

Examples

Request

curl -X "DELETE" "https://api.fortnox.se/3/labels/25" \
     -H "Access-Token: 61cf63ae-4ab9-4a95-9db5-753781c4f41f" \
     -H "Client-Secret: 3Er4kHXZTJ" \
     -H "Content-Type: application/json" \
     -H "Accept: application/json"

Response

No response body will be returned

Using Guzzle

Request

// Include Guzzle. If using Composer:
// require 'vendor/autoload.php';

use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;

function send_request() {
    // Label (DELETE https://api.fortnox.se/3/labels/25)

    $client = new Client();
    $request = $client->createRequest('DELETE', 'https://api.fortnox.se/3/labels/25');

    try {
        $request->addHeaders([
            'Access-Token'=>'61cf63ae-4ab9-4a95-9db5-753781c4f41f',
            'Client-Secret'=>'3Er4kHXZTJ',
            'Content-Type'=>'application/json',
            'Accept'=>'application/json',
        ]);

        $response = $client->send($request);
        echo "Response HTTP : " . $response->getStatusCode();
    }
    catch (RequestException $e) {
        echo "HTTP Request failed\n";
        echo $e->getRequest();
        if ($e->hasResponse()) {
            echo $e->getResponse();
        }
    }
}

Response

No response body will be returned

Request

require 'net/http'

def send_request
    # Label (DELETE )

    begin
        uri = URI('https://api.fortnox.se/3/labels/25')

        # Create client          
        http = Net::HTTP.new(uri.host, uri.port)

        # Create Request
        req =  Net::HTTP::Delete.new(uri)
        # Add headers
        req.add_field "Access-Token", "61cf63ae-4ab9-4a95-9db5-753781c4f41f"
        # Add headers
        req.add_field "Client-Secret", "3Er4kHXZTJ"
        # Add headers
        req.add_field "Content-Type", "application/json"
        # Add headers
        req.add_field "Accept", "application/json"

        # Fetch Request
        res = http.request(req)
        puts "Response HTTP Status Code: #{res.code}"
        puts "Response HTTP Response Body: #{res.body}"
    rescue Exception => e
        puts "HTTP Request failed (#{e.message})"
    end
end

Response

No response body will be returned

Request

# Install the Python Requests library:
# `pip install requests`

import requests

def send_request():
    # Label (DELETE https://api.fortnox.se/3/labels/25)

    try:
        r = requests.delete(
            url="https://api.fortnox.se/3/labels/25",
            headers = {
                "Access-Token":"61cf63ae-4ab9-4a95-9db5-753781c4f41f",
                "Client-Secret":"3Er4kHXZTJ",
                "Content-Type":"application/json",
                "Accept":"application/json",
            },
        )
        print('Response HTTP Status Code : {status_code}'.format(status_code=r.status_code))
        print('Response HTTP Response Body : {content}'.format(content=r.content))
    except requests.exceptions.RequestException as e:
        print('HTTP Request failed')

Response

No response body will be returned

Properties

Property Description
Id integer, read-only
The ID of the label.
Description string, 25 characters, required
Description of the label