Invoice drafts
Invoice drafts allow you to save a preliminary or incomplete invoice, so you can send it to your client for review before applying the stamp and sending it to the SAT.
Once saved, you can download the PDF, but not the XML of a draft.
To create invoice drafts, your issuing organization must have the Advanced or higher plan. More information on our pricing page.
Create a draft
To create an invoice draft, simply create an invoice using the createInvoice
method, sending the data you want to save and specifying the status
field as draft
.
- Node.js
- C#
- PHP
- cURL
const Facturapi = require('facturapi');
const facturapi = new Facturapi('sk_test_API_KEY');
const invoice = await facturapi.invoices.create({
status: 'draft', // Save as draft
customer: null, // When saving a draft, all fields become optional
items: [{
quantity: 2,
product: {
description: 'Ukelele',
product_key: '60131324',
price: 345.60,
taxes: [
{
type: 'IVA',
rate: 0.16
}
]
}
}],
use: 'G01',
payment_form: "28"
});
var facturapi = new FacturapiClient("sk_test_API_KEY");
var invoice = await facturapi.Invoice.CreateAsync(new Dictionary<string, object>
{
["status"] = "draft", // Save as draft
["customer"] = null, // When saving a draft, all fields become optional
["items"] = new Dictionary<string, object>[]
{
new Dictionary<string, object>
{
["quantity"] = 2,
["product"] = new Dictionary<string, object>
{
["description"] = "Ukelele",
["product_key"] = "60131324",
["price"] = 345.60,
["taxes"] = new Dictionary<string, object>[]
{
new Dictionary<string, object>
{
["type"] = "IVA",
["rate"] = 0.16
}
}
}
}
},
["use"] = "G01",
["payment_form"] = "28"
});
$facturapi = new Facturapi( "sk_test_API_KEY" );
$invoice = $facturapi->Invoices->create([
"status" => "draft", // Save as draft
"customer" => null, // When saving a draft, all fields become optional
"items" => [
[
"quantity" => 2,
"product" => [
"description" => "Ukelele",
"product_key" => "60131324",
"price" => 345.60,
"taxes" => [
[
"type" => "IVA",
"rate" => 0.16,
]
]
]
],
],
"payment_form" => "28"
]);
curl https://www.facturapi.io/v2/invoices \
-H "Authorization: Bearer sk_test_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"status": "draft", // Save as draft
"customer": null, // When saving a draft, all fields become optional
"items": [{
"quantity": 2,
"product": {
"description": "Ukelele",
"product_key": "60131324",
"price": 345.60,
"taxes": [
{
"type": "IVA",
"rate": 0.16
}
]
}
}],
"use": "G01",
"payment_form": "28"
}'
Edit a draft
To edit a draft, you can use the
updateDraftInvoice
method
and update the invoice with the data you want to change.
- Node.js
- C#
- PHP
- cURL
const Facturapi = require('facturapi');
const facturapi = new Facturapi('sk_test_API_KEY');
const invoice = await facturapi.invoices.updateDraft('[INVOICE_ID]', {
customer: {
legal_name: 'Dunder Mifflin',
email: 'email@example.com',
tax_id: 'ABC101010111',
tax_system: '601',
address: {
zip: '85900'
}
}
});
var facturapi = new FacturapiClient("sk_test_API_KEY");
var invoice = await facturapi.Invoice.UpdateDraft(new Dictionary<string, object>
{
["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"
}
}
});
$facturapi = new Facturapi( "sk_test_API_KEY" );
$invoice = $facturapi->Invoices->create([
"customer" => [
"legal_name" => "Dunder Mifflin",
"email" => "email@example.com",
"tax_id" => "ABC101010111",
"tax_system" => "601",
"address" => [
"zip" => "85900"
]
]
]);
curl https://www.facturapi.io/v2/invoices \
-H "Authorization: Bearer sk_test_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"customer": {
"legal_name": "Dunder Mifflin",
"email": "email@example.com",
"tax_id": "ABC101010111",
"tax_system": "601",
"address": {
"zip": "85900"
}
}
}'
Check if a draft is ready to stamp
To check if a draft is ready to be stamped, you can use the getInvoice method and check the is_ready_to_stamp field, which will have the value true when all the required fields are completed.To check if a draft is ready to be stamped, you can use the getInvoice method and check the is_ready_to_stamp field, which will have the value true when all the required fields are completed.
Stamp a draft
Stamping a draft means that you are ready to send the invoice to the SAT, and sign it with the organization's digital signature.
To stamp a draft, use the method
stampDraftInvoice
and specify the invoice ID. If the invoice is not ready to be stamped,
you will receive an error in response.