API-V2

Application Programming Interface

InvoiceXpress Documentation

Change-state

PUT /:document-type/:document-id/change-state.json

Changes the state of an invoice, simplified_invoice, invoice_receipt, credit_note or debit_note.

FromToState on Request BodyNotes
draftfinalfinalizedAll documents.
draftsettledfinalizedOnly invoice_receipt.
draftdeleteddeletedAll documents.
finalcanceledcanceledAll documents.
settledcanceledcanceledOnly invoice_receipt.
finalsettledsettledAll documents.
settledfinalunsettledOnly credit_note and debit_note.

Any other transitions will fail. When cancelling a document you must specify a reason.

Example Request

curl

curl --request PUT \
  --url 'https://account_name.app.invoicexpress.com/:document-type/:document-id/change-state.json?api_key=YOUR%20API%20KEY%20HERE' \
  --header 'accept: application/json' \
  --header 'content-type: application/json' \
  --data '{"invoice":{"state":"finalized","message":"Wrong invoice totals."}}'

Ruby

require 'uri'
require 'net/http'

url = URI("https://account_name.app.invoicexpress.com/:document-type/:document-id/change-state.json?api_key=YOUR%20API%20KEY%20HERE")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Put.new(url)
request["accept"] = 'application/json'
request["content-type"] = 'application/json'
request.body = "{\"invoice\":{\"state\":\"finalized\",\"message\":\"Wrong invoice totals.\"}}"

response = http.request(request)
puts response.read_body

Node

var http = require("https");

var options = {
  "method": "PUT",
  "hostname": "account_name.app.invoicexpress.com",
  "port": null,
  "path": "/:document-type/:document-id/change-state.json?api_key=YOUR%20API%20KEY%20HERE",
  "headers": {
    "accept": "application/json",
    "content-type": "application/json"
  }
};

var req = http.request(options, function (res) {
  var chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function () {
    var body = Buffer.concat(chunks);
    console.log(body.toString());
  });
});

req.write(JSON.stringify({ invoice: { state: 'finalized', message: 'Wrong invoice totals.' } }));
req.end();

Python

import http.client

conn = http.client.HTTPSConnection("account_name.app.invoicexpress.com")

payload = "{\"invoice\":{\"state\":\"finalized\",\"message\":\"Wrong invoice totals.\"}}"

headers = {
    'accept': "application/json",
    'content-type': "application/json"
    }

conn.request("PUT", "/:document-type/:document-id/change-state.json?api_key=YOUR%20API%20KEY%20HERE", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))

PHP

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://account_name.app.invoicexpress.com/:document-type/:document-id/change-state.json?api_key=YOUR%20API%20KEY%20HERE",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "PUT",
  CURLOPT_POSTFIELDS => "{\"invoice\":{\"state\":\"finalized\",\"message\":\"Wrong invoice totals.\"}}",
  CURLOPT_HTTPHEADER => array(
    "accept: application/json",
    "content-type: application/json"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

Go

package main

import (
    "fmt"
    "strings"
    "net/http"
    "io/ioutil"
)

func main() {

    url := "https://account_name.app.invoicexpress.com/:document-type/:document-id/change-state.json?api_key=YOUR%20API%20KEY%20HERE"

    payload := strings.NewReader("{\"invoice\":{\"state\":\"finalized\",\"message\":\"Wrong invoice totals.\"}}")

    req, _ := http.NewRequest("PUT", url, payload)

    req.Header.Add("accept", "application/json")
    req.Header.Add("content-type", "application/json")

    res, _ := http.DefaultClient.Do(req)

    defer res.Body.Close()
    body, _ := ioutil.ReadAll(res.Body)

    fmt.Println(res)
    fmt.Println(string(body))

}

Path Parameters

NameTypeRequiredDescriptionExample
document-typeStringRequiredThe type of document you wish to change state. For example: invoicessimplified_invoicesinvoice_receiptscredit_notes or debit_notes.invoices
document-idIntegerRequiredID of the document to change state..1

Request Body

NameTypeRequiredDescription
invoiceObjectRequiredDocument state transition.
stateStringRequiredState which the invoice will be changed to. Options are: finalized, deleted, second_copy, canceled, settled, unsettled.
messageStringDependsReason for cancelling the invoice or reason for cancelling a payment. Only required when state is “canceled”, otherwise ignored.

Example Request Body

{
  "invoice": {
    "state": "finalized",
    "message": "Wrong invoice totals."
  }
}

Responses

200SUCCESS
Document changed state successfully.
(Empty Response)
401ACCESS DENIED
The API Key parameter is missing or is incorrectly entered.
(Empty Response)
404NOT FOUND
The supplied :document-id doesn’t match any existing document.
(Empty Response)
422UNPROCESSABLE ENTITY
Some parameters were incorrect.
(Empty Response)

Example Success Body Response

{
  "invoice": {
    "id": 123456789,
    "status": "final",
    "archived": false,
    "type": "Invoice",
    "sequence_number": "5/A",
    "inverted_sequence_number": "A/5",
    "atcud": "ABCD1234-5",
    "sequence_id": 987654321,
    "date": "14/11/2022",
    "due_date": "14/11/2022",
    "reference": null,
    "observations": null,
    "retention": null,
    "permalink": "https://www.app.invoicexpress.com/documents/123456789qwertyuiop",
    "saft_hash": "p6Ex",
    "sum": 2.02,
    "discount": 0.0,
    "before_taxes": 2.02,
    "taxes": 0.47,
    "total": 2.49,
    "currency": "Euro",
    "client": {
      "id": 51452363,
      "name": "Gabriel Cunha",
      "email": "gabriel.cunha@rupeal.com",
      "country": "Portugal"
    },
    "items": [
      {
        "name": "Pencil",
        "description": "The best pencil in the world",
        "unit_price": "2.0244",
        "unit": null,
        "quantity": "1.0",
        "tax": {
          "id": 349454,
          "name": "IVA23",
          "value": 23.0
        },
        "discount": 0.0,
        "subtotal": 2.0244,
        "tax_amount": 0.465612,
        "discount_amount": 0.0,
        "total": 2.49
      }
    ]
  }
}

Possible values for field atcud:

  • ABCD1234-1 or similar: Unique document identifier to the Tax Authority, when the sequence is registered.
  • N/D: The document’s sequence is relevant for ATCUD but is not registered in the Tax Authority.
  • N/A: The document’s sequence is not relevant for ATCUD and is not registered in the Tax Authority.

Change-state