Relationships between CFDI
In addition to the different types of invoices, there is a concept known as "Related CFDI" used when additional information about a transaction needs to be issued.
Some Examples of Invoice Relationships
To fully understand all the available options when creating an invoice, detailed descriptions of each field, and the most commonly used catalogs, please refer to the Create Invoice API reference.
When giving a discount
When making a sale with a discount, an outgoing CFDI can be issued to make that discount deductible.
- Node.js
- C#
- PHP
- cURL
const Facturapi = require('facturapi');
const facturapi = new Facturapi('sk_test_API_KEY');
const invoice = await facturapi.invoices.create({
type: "E",
customer: {
legal_name: 'Dunder Mifflin',
email: 'email@example.com',
tax_id: 'ABC101010111',
tax_system: '601',
address: {
zip: '85900'
}
},
items: [{
product: {
description: 'Descuento',
price: 400,
taxes: [
{
type: 'IVA',
rate: 0.16
}
]
}
}],
payment_form: "28", // "Debit card"
related_documents: [
{
relationship: "01", // "Credit note of related documents"
uuid: "UUID_DEL_CFDI_DE_INGRESO"
}
]
});
var facturapi = new FacturapiClient("sk_test_API_KEY");
var invoice = await facturapi.Invoice.CreateAsync(new Dictionary<string, object>
{
["type"] = "E",
["customer"] = new Dictionary<string, object>
{
["legal_name"] = "Dunder Mifflin",
["email"] = "email@example.com",
["tax_id"] = "ABC101010111",
["tax_system"] = "601",
["address"] = new Dictionary<string, object>
{
["zip"] = "85900"
}
},
["items"] = new Dictionary<string, object>[]
{
new Dictionary<string, object>
{
["product"] = new Dictionary<string, object>
{
["description"] = "Descuento",
["price"] = 400,
["taxes"] = new Dictionary<string, object>[]
{
new Dictionary<string, object>
{
["type"] = "IVA",
["rate"] = 0.16
}
}
}
}
},
["payment_form"] = "28", // "Debit card",
["related_documents"] = new Dictionary<string, object>[]
{
new Dictionary<string, object>
{
["relationship"] = "01", // "Credit note of related documents"
["uuid"] = "UUID_DEL_CFDI_DE_INGRESO"
}
}
});
$facturapi = new Facturapi( "sk_test_API_KEY" );
$invoice = $facturapi->Invoices->create([
"type" => "E",
"customer" => [
"legal_name" => "Dunder Mifflin",
"email" => "email@example.com",
"tax_id" => "ABC101010111",
"tax_system" => "601",
"address" => [
"zip" => "85900"
]
],
"items" => [
[
"product" => [
"description" => "Descuento",
"price" => 400,
"taxes" => [
[
"type" => "IVA",
"rate" => 0.16
]
]
]
]
],
"payment_form" => "28", // "Debit card",
"related_documents" => [
[
"relationship" => "01", // "Credit note of related documents"
"uuid" => "UUID_DEL_CFDI_DE_INGRESO"
]
]
]);
curl https://www.facturapi.io/v2/invoices \
-H "Authorization: Bearer sk_test_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": "E",
"customer": {
"legal_name": "Dunder Mifflin",
"email": "email@example.com",
"tax_id": "ABC101010111",
"tax_system": "601",
"address": {
"zip": "85900"
}
},
"items": [
{
"product": {
"description": "Descuento",
"price": 400,
"taxes": [
{
"type": "IVA",
"rate": 0.16
}
]
}
}
],
"payment_form": "28", // "Debit card"
"related_documents": [
{
"relationship": "01", // "Credit note of related documents"
"uuid": "UUID_DEL_CFDI_DE_INGRESO"
}
]
}'
Returns
When your customer returns a product that was previously invoiced you must issue an Egress invoice, adding the relation to the original Income invoice.
- Node.js
- C#
- PHP
- cURL
const Facturapi = require('facturapi');
const facturapi = new Facturapi('sk_test_API_KEY');
const invoice = await facturapi.invoices.create({
type: "E",
customer: {
legal_name: 'Dunder Mifflin',
email: 'email@example.com',
tax_id: 'ABC101010111',
tax_system: '601',
address: {
zip: '85900'
}
},
items: [{
product: {
description: 'Devolución total de mercancía',
price: 5000,
taxes: [
{
type: 'IVA',
rate: 0.16
}
]
}
}],
payment_form: "28", // "Debit card"
related_documents: [
{
relationship: "01", // "Credit note of related documents"
uuid: "UUID_DEL_CFDI_DE_INGRESO"
}
]
});
var facturapi = new FacturapiClient("sk_test_API_KEY");
var invoice = await facturapi.Invoice.CreateAsync(new Dictionary<string, object>
{
["type"] = "E",
["customer"] = new Dictionary<string, object>
{
["legal_name"] = "Dunder Mifflin",
["email"] = "email@example.com",
["tax_id"] = "ABC101010111",
["tax_system"] = "601",
["address"] = new Dictionary<string, object>
{
["zip"] = "85900"
}
},
["items"] = new Dictionary<string, object>[]
{
new Dictionary<string, object>
{
["product"] = new Dictionary<string, object>
{
["description"] = "Devolución total de mercancía",
["price"] = 5000,
["taxes"] = new Dictionary<string, object>[]
{
new Dictionary<string, object>
{
["type"] = "IVA",
["rate"] = 0.16
}
}
}
}
},
["payment_form"] = "28", // "Debit card",
["related_documents"] = new Dictionary<string, object>[]
{
new Dictionary<string, object>
{
["relationship"] = "01", // "Credit note of related documents"
["uuid"] = "UUID_DEL_CFDI_DE_INGRESO"
}
}
});
$facturapi = new Facturapi( "sk_test_API_KEY" );
$invoice = $facturapi->Invoices->create([
"type" => "E",
"customer" => [
"legal_name" => "Dunder Mifflin",
"email" => "email@example.com",
"tax_id" => "ABC101010111",
"tax_system" => "601",
"address" => [
"zip" => "85900"
]
],
"items" => [
[
"product" => [
"description" => "Devolución total de mercancía",
"price" => 5000,
"taxes" => [
[
"type" => "IVA",
"rate" => 0.16
]
]
]
]
],
"payment_form" => "28", // "Debit card",
"related_documents" => [
[
"relationship" => "01", // "Credit note of related documents"
"uuid" => "UUID_DEL_CFDI_DE_INGRESO"
]
]
]);
curl https://www.facturapi.io/v2/invoices \
-H "Authorization: Bearer sk_test_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": "E",
"customer": {
"legal_name": "Dunder Mifflin",
"email": "email@example.com",
"tax_id": "ABC101010111",
"tax_system": "601",
"address": {
"zip": "85900"
}
},
"items": [
{
"product": {
"description": "Devolución total de mercancía",
"price": 5000,
"taxes": [
{
"type": "IVA",
"rate": 0.16
}
]
}
}
],
"payment_form": "28", // "Debit card"
"related_documents": [
{
"relationship": "01", // "Credit note of related documents"
"uuid": "UUID_DEL_CFDI_DE_INGRESO"
}
]
}'
Cancellation of a previous CFDI
When an invoice is canceled and a new one is issued, it is possible to relate them to indicate that the new CFDI is the replacement of a previous document.
- Node.js
- C#
- PHP
- cURL
const Facturapi = require('facturapi');
const facturapi = new Facturapi('sk_test_API_KEY');
const invoice = await facturapi.invoices.create({
type: "I",
customer: {
legal_name: 'Dunder Mifflin',
email: 'email@example.com',
tax_id: 'ABC101010111',
tax_system: '601',
address: {
zip: '85900'
}
},
items: [{
product: {
description: 'Venta de mercancía',
price: 5000,
taxes: [
{
type: 'IVA',
rate: 0.16
}
]
}
}],
payment_form: "01", // "Efectivo"
related_documents: [
{
relationship: "04", // "Sustitución de los CFDI previos"
uuid: "UUID_DEL_CFDI_PREVIO"
}
]
});
var facturapi = new FacturapiClient("sk_test_API_KEY");
var invoice = await facturapi.Invoice.CreateAsync(new Dictionary<string, object>
{
["type"] = "I",
["customer"] = new Dictionary<string, object>
{
["legal_name"] = "Dunder Mifflin",
["email"] = "email@example.com",
["tax_id"] = "ABC101010111",
["tax_system"] = "601",
["address"] = new Dictionary<string, object>
{
["zip"] = "85900"
}
},
["items"] = new Dictionary<string, object>[]
{
new Dictionary<string, object>
{
["product"] = new Dictionary<string, object>
{
["description"] = "Venta de mercancía",
["price"] = 5000,
["taxes"] = new Dictionary<string, object>[]
{
new Dictionary<string, object>
{
["type"] = "IVA",
["rate"] = 0.16
}
}
}
}
},
["payment_form"] = "01", // "Efectivo",
["related_documents"] = new Dictionary<string, object>[]
{
new Dictionary<string, object>
{
["relationship"] = "04", // "Sustitución de los CFDI previos"
["uuid"] = "UUID_DEL_CFDI_PREVIO"
}
}
});
$facturapi = new Facturapi( "sk_test_API_KEY" );
$invoice = $facturapi->Invoices->create([
"type" => "I",
"customer" => [
"legal_name" => "Dunder Mifflin",
"email" => "email@example.com",
"tax_id" => "ABC101010111",
"tax_system" => "601",
"address" => [
"zip" => "85900"
]
},
"items" => [
[
"product" => [
"description" => "Venta de mercancía",
"price" => 5000,
"taxes" => [
[
"type" => "IVA",
"rate" => 0.16
]
]
}
]
],
"payment_form" => "01", // "Efectivo",
"related_documents" => [
[
"relationship" => "04", // "Sustitución de los CFDI previos"
"uuid" => "UUID_DEL_CFDI_PREVIO"
]
]
});
curl https://www.facturapi.io/v2/invoices \
-H "Authorization: Bearer sk_test_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": "I",
"customer": {
"legal_name": "Dunder Mifflin",
"email": "email@example.com",
"tax_id": "ABC101010111",
"tax_system": "601",
"address": {
"zip": "85900"
}
},
"items": [
{
"product": {
"description": "Venta de mercancía",
"price": 5000,
"taxes": [
{
"type": "IVA",
"rate": 0.16
}
]
}
}
],
"payment_form": "01", // "Efectivo"
"related_documents": [
{
"relationship": "04", // "Sustitución de los CFDI previos"
"uuid": "UUID_DEL_CFDI_PREVIO"
}
]
}'