Invoices
Add an invoice PDF attachment
Add an invoice PDF attachment through the public API.
POST
/
v1
/
invoices
/
{invoiceId}
/
pdf-attachments
Add an invoice PDF attachment
curl --request POST \
--url https://api.infinity.swiss/v1/invoices/{invoiceId}/pdf-attachments \
--header 'Content-Type: multipart/form-data' \
--header 'x-api-token: <api-key>' \
--form file=@example-file \
--form 'title=<string>'import requests
url = "https://api.infinity.swiss/v1/invoices/{invoiceId}/pdf-attachments"
files = { "file": ("example-file", open("example-file", "rb")) }
payload = { "title": "<string>" }
headers = {"x-api-token": "<api-key>"}
response = requests.post(url, data=payload, files=files, headers=headers)
print(response.text)const form = new FormData();
form.append('file', '<string>');
form.append('title', '<string>');
const options = {method: 'POST', headers: {'x-api-token': '<api-key>'}};
options.body = form;
fetch('https://api.infinity.swiss/v1/invoices/{invoiceId}/pdf-attachments', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.infinity.swiss/v1/invoices/{invoiceId}/pdf-attachments",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"title\"\r\n\r\n<string>\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Content-Type: multipart/form-data",
"x-api-token: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.infinity.swiss/v1/invoices/{invoiceId}/pdf-attachments"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"title\"\r\n\r\n<string>\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-token", "<api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.infinity.swiss/v1/invoices/{invoiceId}/pdf-attachments")
.header("x-api-token", "<api-key>")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"title\"\r\n\r\n<string>\r\n-----011000010111000001101001--")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.infinity.swiss/v1/invoices/{invoiceId}/pdf-attachments")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-token"] = '<api-key>'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"title\"\r\n\r\n<string>\r\n-----011000010111000001101001--"
response = http.request(request)
puts response.read_body{
"attachment": {
"id": "<string>",
"url": "<string>",
"name": "<string>",
"type": "application/pdf",
"size": 123
}
}{
"code": "general/unauthorised"
}{
"code": "rest-api/insufficient-scope"
}{
"code": "customer-invoices/not-found"
}Send the PDF as the
file part of a multipart request with a title field. The response contains the uploaded file under attachment. Its url opens the file for one hour, see download an invoice PDF attachment.
You can attach up to ten PDFs to an invoice. Each file may be at most 10 MiB (10,485,760 bytes). Infinity checks the actual file contents and rejects PDFs whose pages cannot be rendered.
Issued invoices allow attachment changes only while they have no payments, have not been annulled, belong to an editable fiscal year, and are outside settled VAT periods. Draft attachments remain editable.
Attachments added through the API also appear in the invoice editor and generated invoice PDF.Authorizations
Body
multipart/form-data
⌘I
Add an invoice PDF attachment
curl --request POST \
--url https://api.infinity.swiss/v1/invoices/{invoiceId}/pdf-attachments \
--header 'Content-Type: multipart/form-data' \
--header 'x-api-token: <api-key>' \
--form file=@example-file \
--form 'title=<string>'import requests
url = "https://api.infinity.swiss/v1/invoices/{invoiceId}/pdf-attachments"
files = { "file": ("example-file", open("example-file", "rb")) }
payload = { "title": "<string>" }
headers = {"x-api-token": "<api-key>"}
response = requests.post(url, data=payload, files=files, headers=headers)
print(response.text)const form = new FormData();
form.append('file', '<string>');
form.append('title', '<string>');
const options = {method: 'POST', headers: {'x-api-token': '<api-key>'}};
options.body = form;
fetch('https://api.infinity.swiss/v1/invoices/{invoiceId}/pdf-attachments', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.infinity.swiss/v1/invoices/{invoiceId}/pdf-attachments",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"title\"\r\n\r\n<string>\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Content-Type: multipart/form-data",
"x-api-token: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.infinity.swiss/v1/invoices/{invoiceId}/pdf-attachments"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"title\"\r\n\r\n<string>\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-token", "<api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.infinity.swiss/v1/invoices/{invoiceId}/pdf-attachments")
.header("x-api-token", "<api-key>")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"title\"\r\n\r\n<string>\r\n-----011000010111000001101001--")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.infinity.swiss/v1/invoices/{invoiceId}/pdf-attachments")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-token"] = '<api-key>'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"title\"\r\n\r\n<string>\r\n-----011000010111000001101001--"
response = http.request(request)
puts response.read_body{
"attachment": {
"id": "<string>",
"url": "<string>",
"name": "<string>",
"type": "application/pdf",
"size": 123
}
}{
"code": "general/unauthorised"
}{
"code": "rest-api/insufficient-scope"
}{
"code": "customer-invoices/not-found"
}