Insert or update an invoice
Creates a new invoice record or updates an existing one based on its unique identifier (id). This endpoint supports multiple invoice types (e.g. heat, fuel, electricity, wastes, etc.). - If the id exists, the record is updated. - If the id does not exist, a new record is inserted.
⚠️ Special rules: - emissionFactor in lines is optional. - companySplitOriginalValues is optional. - wasteType and wasteDisposalMethod are required only when type = waste.
curl --request POST \
--url https://www.manglai.io/api/v1/invoices \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"id": "<string>",
"companyId": "<string>",
"totalCost": 123,
"currency": "<string>",
"startDate": "2023-12-25",
"endDate": "2023-12-25",
"buildingId": "<string>",
"cup": "<string>",
"supplier": "<string>",
"rawProvider": "<string>",
"wasteType": "<string>",
"wasteDisposalMethod": "<string>",
"lines": [
{
"quantity": 123,
"unit": "<string>",
"fuel": "<string>",
"type": "<string>",
"emissions": 123,
"emissionFactor": 123,
"gdo": "<string>",
"prevGdo": "<string>",
"regoId": "<string>",
"renewablePercentage": 123,
"emissionEntityId": "<string>"
}
],
"attachedFilePath": "<string>",
"removedAt": "2023-12-25",
"countryCode": "<string>",
"externalId": "<string>",
"splitPercentage": 123,
"splitYear": 123,
"splitId": "<string>",
"wasValidated": true,
"validation": {},
"relationalId": "<string>",
"companySplitOriginalValues": {
"quantity": 123,
"totalCost": 123,
"configurationSnapshot": {}
}
}
'import requests
url = "https://www.manglai.io/api/v1/invoices"
payload = {
"id": "<string>",
"companyId": "<string>",
"totalCost": 123,
"currency": "<string>",
"startDate": "2023-12-25",
"endDate": "2023-12-25",
"buildingId": "<string>",
"cup": "<string>",
"supplier": "<string>",
"rawProvider": "<string>",
"wasteType": "<string>",
"wasteDisposalMethod": "<string>",
"lines": [
{
"quantity": 123,
"unit": "<string>",
"fuel": "<string>",
"type": "<string>",
"emissions": 123,
"emissionFactor": 123,
"gdo": "<string>",
"prevGdo": "<string>",
"regoId": "<string>",
"renewablePercentage": 123,
"emissionEntityId": "<string>"
}
],
"attachedFilePath": "<string>",
"removedAt": "2023-12-25",
"countryCode": "<string>",
"externalId": "<string>",
"splitPercentage": 123,
"splitYear": 123,
"splitId": "<string>",
"wasValidated": True,
"validation": {},
"relationalId": "<string>",
"companySplitOriginalValues": {
"quantity": 123,
"totalCost": 123,
"configurationSnapshot": {}
}
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
id: '<string>',
companyId: '<string>',
totalCost: 123,
currency: '<string>',
startDate: '2023-12-25',
endDate: '2023-12-25',
buildingId: '<string>',
cup: '<string>',
supplier: '<string>',
rawProvider: '<string>',
wasteType: '<string>',
wasteDisposalMethod: '<string>',
lines: [
{
quantity: 123,
unit: '<string>',
fuel: '<string>',
type: '<string>',
emissions: 123,
emissionFactor: 123,
gdo: '<string>',
prevGdo: '<string>',
regoId: '<string>',
renewablePercentage: 123,
emissionEntityId: '<string>'
}
],
attachedFilePath: '<string>',
removedAt: '2023-12-25',
countryCode: '<string>',
externalId: '<string>',
splitPercentage: 123,
splitYear: 123,
splitId: '<string>',
wasValidated: true,
validation: {},
relationalId: '<string>',
companySplitOriginalValues: {quantity: 123, totalCost: 123, configurationSnapshot: {}}
})
};
fetch('https://www.manglai.io/api/v1/invoices', 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://www.manglai.io/api/v1/invoices",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'id' => '<string>',
'companyId' => '<string>',
'totalCost' => 123,
'currency' => '<string>',
'startDate' => '2023-12-25',
'endDate' => '2023-12-25',
'buildingId' => '<string>',
'cup' => '<string>',
'supplier' => '<string>',
'rawProvider' => '<string>',
'wasteType' => '<string>',
'wasteDisposalMethod' => '<string>',
'lines' => [
[
'quantity' => 123,
'unit' => '<string>',
'fuel' => '<string>',
'type' => '<string>',
'emissions' => 123,
'emissionFactor' => 123,
'gdo' => '<string>',
'prevGdo' => '<string>',
'regoId' => '<string>',
'renewablePercentage' => 123,
'emissionEntityId' => '<string>'
]
],
'attachedFilePath' => '<string>',
'removedAt' => '2023-12-25',
'countryCode' => '<string>',
'externalId' => '<string>',
'splitPercentage' => 123,
'splitYear' => 123,
'splitId' => '<string>',
'wasValidated' => true,
'validation' => [
],
'relationalId' => '<string>',
'companySplitOriginalValues' => [
'quantity' => 123,
'totalCost' => 123,
'configurationSnapshot' => [
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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://www.manglai.io/api/v1/invoices"
payload := strings.NewReader("{\n \"id\": \"<string>\",\n \"companyId\": \"<string>\",\n \"totalCost\": 123,\n \"currency\": \"<string>\",\n \"startDate\": \"2023-12-25\",\n \"endDate\": \"2023-12-25\",\n \"buildingId\": \"<string>\",\n \"cup\": \"<string>\",\n \"supplier\": \"<string>\",\n \"rawProvider\": \"<string>\",\n \"wasteType\": \"<string>\",\n \"wasteDisposalMethod\": \"<string>\",\n \"lines\": [\n {\n \"quantity\": 123,\n \"unit\": \"<string>\",\n \"fuel\": \"<string>\",\n \"type\": \"<string>\",\n \"emissions\": 123,\n \"emissionFactor\": 123,\n \"gdo\": \"<string>\",\n \"prevGdo\": \"<string>\",\n \"regoId\": \"<string>\",\n \"renewablePercentage\": 123,\n \"emissionEntityId\": \"<string>\"\n }\n ],\n \"attachedFilePath\": \"<string>\",\n \"removedAt\": \"2023-12-25\",\n \"countryCode\": \"<string>\",\n \"externalId\": \"<string>\",\n \"splitPercentage\": 123,\n \"splitYear\": 123,\n \"splitId\": \"<string>\",\n \"wasValidated\": true,\n \"validation\": {},\n \"relationalId\": \"<string>\",\n \"companySplitOriginalValues\": {\n \"quantity\": 123,\n \"totalCost\": 123,\n \"configurationSnapshot\": {}\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://www.manglai.io/api/v1/invoices")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"id\": \"<string>\",\n \"companyId\": \"<string>\",\n \"totalCost\": 123,\n \"currency\": \"<string>\",\n \"startDate\": \"2023-12-25\",\n \"endDate\": \"2023-12-25\",\n \"buildingId\": \"<string>\",\n \"cup\": \"<string>\",\n \"supplier\": \"<string>\",\n \"rawProvider\": \"<string>\",\n \"wasteType\": \"<string>\",\n \"wasteDisposalMethod\": \"<string>\",\n \"lines\": [\n {\n \"quantity\": 123,\n \"unit\": \"<string>\",\n \"fuel\": \"<string>\",\n \"type\": \"<string>\",\n \"emissions\": 123,\n \"emissionFactor\": 123,\n \"gdo\": \"<string>\",\n \"prevGdo\": \"<string>\",\n \"regoId\": \"<string>\",\n \"renewablePercentage\": 123,\n \"emissionEntityId\": \"<string>\"\n }\n ],\n \"attachedFilePath\": \"<string>\",\n \"removedAt\": \"2023-12-25\",\n \"countryCode\": \"<string>\",\n \"externalId\": \"<string>\",\n \"splitPercentage\": 123,\n \"splitYear\": 123,\n \"splitId\": \"<string>\",\n \"wasValidated\": true,\n \"validation\": {},\n \"relationalId\": \"<string>\",\n \"companySplitOriginalValues\": {\n \"quantity\": 123,\n \"totalCost\": 123,\n \"configurationSnapshot\": {}\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://www.manglai.io/api/v1/invoices")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"id\": \"<string>\",\n \"companyId\": \"<string>\",\n \"totalCost\": 123,\n \"currency\": \"<string>\",\n \"startDate\": \"2023-12-25\",\n \"endDate\": \"2023-12-25\",\n \"buildingId\": \"<string>\",\n \"cup\": \"<string>\",\n \"supplier\": \"<string>\",\n \"rawProvider\": \"<string>\",\n \"wasteType\": \"<string>\",\n \"wasteDisposalMethod\": \"<string>\",\n \"lines\": [\n {\n \"quantity\": 123,\n \"unit\": \"<string>\",\n \"fuel\": \"<string>\",\n \"type\": \"<string>\",\n \"emissions\": 123,\n \"emissionFactor\": 123,\n \"gdo\": \"<string>\",\n \"prevGdo\": \"<string>\",\n \"regoId\": \"<string>\",\n \"renewablePercentage\": 123,\n \"emissionEntityId\": \"<string>\"\n }\n ],\n \"attachedFilePath\": \"<string>\",\n \"removedAt\": \"2023-12-25\",\n \"countryCode\": \"<string>\",\n \"externalId\": \"<string>\",\n \"splitPercentage\": 123,\n \"splitYear\": 123,\n \"splitId\": \"<string>\",\n \"wasValidated\": true,\n \"validation\": {},\n \"relationalId\": \"<string>\",\n \"companySplitOriginalValues\": {\n \"quantity\": 123,\n \"totalCost\": 123,\n \"configurationSnapshot\": {}\n }\n}"
response = http.request(request)
puts response.read_body{
"status": "ok",
"invoice": {}
}Autorizaciones
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Cuerpo
Invoice data to be inserted or updated.
Unique identifier of the invoice.
Type of the invoice.
heat, fuel, electricity, generated-energy, process-emissions, water, wastes, wastes-expenses, others, waste-water Company associated with the invoice.
Total cost of the invoice.
Currency of the invoice (e.g., USD, EUR).
Start date of the invoice period.
End date of the invoice period.
Building associated with the invoice.
Unique identifier for the invoice (e.g., CUP code).
Supplier name.
Raw provider for the invoice.
Waste type (⚠️ required only if type = waste).
Waste disposal method (⚠️ required only if type = waste).
Invoice status.
valid, draft Line items associated with the invoice.
Show child attributes
Show child attributes
Path to the attached file.
Date when the invoice was removed.
ISO country code of the company (e.g., ES, FR).
External identifier for the invoice.
Percentage for splitting the invoice.
Year associated with the split.
Identifier of the split.
Indicates if the invoice was validated.
Validation data for the invoice.
Relational ID for the invoice.
Snapshot of values before splitting. ⚠️ Optional: only provided if the invoice was split.
Show child attributes
Show child attributes
curl --request POST \
--url https://www.manglai.io/api/v1/invoices \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"id": "<string>",
"companyId": "<string>",
"totalCost": 123,
"currency": "<string>",
"startDate": "2023-12-25",
"endDate": "2023-12-25",
"buildingId": "<string>",
"cup": "<string>",
"supplier": "<string>",
"rawProvider": "<string>",
"wasteType": "<string>",
"wasteDisposalMethod": "<string>",
"lines": [
{
"quantity": 123,
"unit": "<string>",
"fuel": "<string>",
"type": "<string>",
"emissions": 123,
"emissionFactor": 123,
"gdo": "<string>",
"prevGdo": "<string>",
"regoId": "<string>",
"renewablePercentage": 123,
"emissionEntityId": "<string>"
}
],
"attachedFilePath": "<string>",
"removedAt": "2023-12-25",
"countryCode": "<string>",
"externalId": "<string>",
"splitPercentage": 123,
"splitYear": 123,
"splitId": "<string>",
"wasValidated": true,
"validation": {},
"relationalId": "<string>",
"companySplitOriginalValues": {
"quantity": 123,
"totalCost": 123,
"configurationSnapshot": {}
}
}
'import requests
url = "https://www.manglai.io/api/v1/invoices"
payload = {
"id": "<string>",
"companyId": "<string>",
"totalCost": 123,
"currency": "<string>",
"startDate": "2023-12-25",
"endDate": "2023-12-25",
"buildingId": "<string>",
"cup": "<string>",
"supplier": "<string>",
"rawProvider": "<string>",
"wasteType": "<string>",
"wasteDisposalMethod": "<string>",
"lines": [
{
"quantity": 123,
"unit": "<string>",
"fuel": "<string>",
"type": "<string>",
"emissions": 123,
"emissionFactor": 123,
"gdo": "<string>",
"prevGdo": "<string>",
"regoId": "<string>",
"renewablePercentage": 123,
"emissionEntityId": "<string>"
}
],
"attachedFilePath": "<string>",
"removedAt": "2023-12-25",
"countryCode": "<string>",
"externalId": "<string>",
"splitPercentage": 123,
"splitYear": 123,
"splitId": "<string>",
"wasValidated": True,
"validation": {},
"relationalId": "<string>",
"companySplitOriginalValues": {
"quantity": 123,
"totalCost": 123,
"configurationSnapshot": {}
}
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
id: '<string>',
companyId: '<string>',
totalCost: 123,
currency: '<string>',
startDate: '2023-12-25',
endDate: '2023-12-25',
buildingId: '<string>',
cup: '<string>',
supplier: '<string>',
rawProvider: '<string>',
wasteType: '<string>',
wasteDisposalMethod: '<string>',
lines: [
{
quantity: 123,
unit: '<string>',
fuel: '<string>',
type: '<string>',
emissions: 123,
emissionFactor: 123,
gdo: '<string>',
prevGdo: '<string>',
regoId: '<string>',
renewablePercentage: 123,
emissionEntityId: '<string>'
}
],
attachedFilePath: '<string>',
removedAt: '2023-12-25',
countryCode: '<string>',
externalId: '<string>',
splitPercentage: 123,
splitYear: 123,
splitId: '<string>',
wasValidated: true,
validation: {},
relationalId: '<string>',
companySplitOriginalValues: {quantity: 123, totalCost: 123, configurationSnapshot: {}}
})
};
fetch('https://www.manglai.io/api/v1/invoices', 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://www.manglai.io/api/v1/invoices",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'id' => '<string>',
'companyId' => '<string>',
'totalCost' => 123,
'currency' => '<string>',
'startDate' => '2023-12-25',
'endDate' => '2023-12-25',
'buildingId' => '<string>',
'cup' => '<string>',
'supplier' => '<string>',
'rawProvider' => '<string>',
'wasteType' => '<string>',
'wasteDisposalMethod' => '<string>',
'lines' => [
[
'quantity' => 123,
'unit' => '<string>',
'fuel' => '<string>',
'type' => '<string>',
'emissions' => 123,
'emissionFactor' => 123,
'gdo' => '<string>',
'prevGdo' => '<string>',
'regoId' => '<string>',
'renewablePercentage' => 123,
'emissionEntityId' => '<string>'
]
],
'attachedFilePath' => '<string>',
'removedAt' => '2023-12-25',
'countryCode' => '<string>',
'externalId' => '<string>',
'splitPercentage' => 123,
'splitYear' => 123,
'splitId' => '<string>',
'wasValidated' => true,
'validation' => [
],
'relationalId' => '<string>',
'companySplitOriginalValues' => [
'quantity' => 123,
'totalCost' => 123,
'configurationSnapshot' => [
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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://www.manglai.io/api/v1/invoices"
payload := strings.NewReader("{\n \"id\": \"<string>\",\n \"companyId\": \"<string>\",\n \"totalCost\": 123,\n \"currency\": \"<string>\",\n \"startDate\": \"2023-12-25\",\n \"endDate\": \"2023-12-25\",\n \"buildingId\": \"<string>\",\n \"cup\": \"<string>\",\n \"supplier\": \"<string>\",\n \"rawProvider\": \"<string>\",\n \"wasteType\": \"<string>\",\n \"wasteDisposalMethod\": \"<string>\",\n \"lines\": [\n {\n \"quantity\": 123,\n \"unit\": \"<string>\",\n \"fuel\": \"<string>\",\n \"type\": \"<string>\",\n \"emissions\": 123,\n \"emissionFactor\": 123,\n \"gdo\": \"<string>\",\n \"prevGdo\": \"<string>\",\n \"regoId\": \"<string>\",\n \"renewablePercentage\": 123,\n \"emissionEntityId\": \"<string>\"\n }\n ],\n \"attachedFilePath\": \"<string>\",\n \"removedAt\": \"2023-12-25\",\n \"countryCode\": \"<string>\",\n \"externalId\": \"<string>\",\n \"splitPercentage\": 123,\n \"splitYear\": 123,\n \"splitId\": \"<string>\",\n \"wasValidated\": true,\n \"validation\": {},\n \"relationalId\": \"<string>\",\n \"companySplitOriginalValues\": {\n \"quantity\": 123,\n \"totalCost\": 123,\n \"configurationSnapshot\": {}\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://www.manglai.io/api/v1/invoices")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"id\": \"<string>\",\n \"companyId\": \"<string>\",\n \"totalCost\": 123,\n \"currency\": \"<string>\",\n \"startDate\": \"2023-12-25\",\n \"endDate\": \"2023-12-25\",\n \"buildingId\": \"<string>\",\n \"cup\": \"<string>\",\n \"supplier\": \"<string>\",\n \"rawProvider\": \"<string>\",\n \"wasteType\": \"<string>\",\n \"wasteDisposalMethod\": \"<string>\",\n \"lines\": [\n {\n \"quantity\": 123,\n \"unit\": \"<string>\",\n \"fuel\": \"<string>\",\n \"type\": \"<string>\",\n \"emissions\": 123,\n \"emissionFactor\": 123,\n \"gdo\": \"<string>\",\n \"prevGdo\": \"<string>\",\n \"regoId\": \"<string>\",\n \"renewablePercentage\": 123,\n \"emissionEntityId\": \"<string>\"\n }\n ],\n \"attachedFilePath\": \"<string>\",\n \"removedAt\": \"2023-12-25\",\n \"countryCode\": \"<string>\",\n \"externalId\": \"<string>\",\n \"splitPercentage\": 123,\n \"splitYear\": 123,\n \"splitId\": \"<string>\",\n \"wasValidated\": true,\n \"validation\": {},\n \"relationalId\": \"<string>\",\n \"companySplitOriginalValues\": {\n \"quantity\": 123,\n \"totalCost\": 123,\n \"configurationSnapshot\": {}\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://www.manglai.io/api/v1/invoices")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"id\": \"<string>\",\n \"companyId\": \"<string>\",\n \"totalCost\": 123,\n \"currency\": \"<string>\",\n \"startDate\": \"2023-12-25\",\n \"endDate\": \"2023-12-25\",\n \"buildingId\": \"<string>\",\n \"cup\": \"<string>\",\n \"supplier\": \"<string>\",\n \"rawProvider\": \"<string>\",\n \"wasteType\": \"<string>\",\n \"wasteDisposalMethod\": \"<string>\",\n \"lines\": [\n {\n \"quantity\": 123,\n \"unit\": \"<string>\",\n \"fuel\": \"<string>\",\n \"type\": \"<string>\",\n \"emissions\": 123,\n \"emissionFactor\": 123,\n \"gdo\": \"<string>\",\n \"prevGdo\": \"<string>\",\n \"regoId\": \"<string>\",\n \"renewablePercentage\": 123,\n \"emissionEntityId\": \"<string>\"\n }\n ],\n \"attachedFilePath\": \"<string>\",\n \"removedAt\": \"2023-12-25\",\n \"countryCode\": \"<string>\",\n \"externalId\": \"<string>\",\n \"splitPercentage\": 123,\n \"splitYear\": 123,\n \"splitId\": \"<string>\",\n \"wasValidated\": true,\n \"validation\": {},\n \"relationalId\": \"<string>\",\n \"companySplitOriginalValues\": {\n \"quantity\": 123,\n \"totalCost\": 123,\n \"configurationSnapshot\": {}\n }\n}"
response = http.request(request)
puts response.read_body{
"status": "ok",
"invoice": {}
}
