gigstack API
  1. Retentions
gigstack API
  • Welcome to gigstack API
  • gigstack Connect API Guide
  • Migrar de API v1 a v2 de gigstack
  • Clients
    • Clients API Guide
    • List clients
      GET
    • Get client
      GET
    • Update client
      PUT
    • Create client
      POST
    • Validate client fiscal information
      POST
    • Get client customer portal access token
      POST
    • Stamp pending receipts
      POST
    • Delete client
      DELETE
    • Search clients
      GET
    • Upload CSF PDF to create or update client
      POST
    • Upload support document
      POST
    • List support documents
      GET
  • Services
    • Services API Guide
    • List services
      GET
    • Get service
      GET
    • Update service
      PUT
    • Create service
      POST
    • Delete service
      DELETE
  • Invoices
    • Invoices API Guide
    • Income
      • List income invoices
      • Create income invoice
      • Get income invoice
    • Egress
      • List egress invoices
      • Create egress invoice
      • Get egress invoice
    • Drafts
      • Create draft invoice (pre-factura)
      • Stamp draft invoice (finalize)
      • Generate draft preview PDF (pre-factura)
      • Delete draft invoice
      • Update draft invoice
      • Get draft invoice
      • List draft invoices
    • List CFDI errors
    • List payment complement invoices
    • Get payment complement invoice
    • Get invoice files
    • Upload support document
    • List support documents
    • Cancel invoice
    • Search invoices
  • Payments
    • Payments API Guide
    • List payments
    • Get payment
    • Request payment
    • Register payment
    • Mark payment as paid
    • Refund payment
    • Cancel payment
    • Search payments
    • Upload support document
    • List support documents
  • Receipts
    • Receipts API Guide
    • List receipts
    • Get receipt
    • Create receipt
    • Stamp receipt
    • Cancel receipt
    • Search receipts
  • Teams
    • Teams API Guide
    • List teams
    • Get team
    • Get team integrations
    • Get team series
    • Get team onboarding URL
    • Update team
    • Update team series
    • Update team settings
    • Create team
    • Add team member
    • Remove team member
    • Create team series
    • Upload SAT CSD certificates
    • Sign manifest document
  • Users
    • Users API Guide
    • List users
    • Get user
    • Update user
    • Create user
    • Reset user password
    • Generate login link
  • Catalogs
    • Tax Regimes Catalog (Régimen Fiscal)
    • Payment Forms | Formas de pago
    • CFDI Usage Catalog (Uso CFDI)
    • Payment Methods Catalog (Método de Pago)
    • Months and Bimesters Catalog (Meses y Bimestres)
    • Invoice Relationships Catalog (Relación entre Facturas)
  • Webhooks
    • Webhooks
    • List webhooks
    • Create webhook
    • Get webhook
    • Update webhook
    • Delete webhook
  • Retentions
    • Retentions
    • List retentions
      GET
    • Create retention
      POST
    • Get retention
      GET
    • Cancel retention
      DELETE
    • Get retention files
      GET
  • Apidog connectivity test
    GET
  • Schemas
    • Schemas
      • ApiResponse
      • Category
      • Pet
      • Tag
      • Order
      • StandardizedSuccessResponse
      • StandardizedErrorResponse
      • ApiErrorCode
    • RequestBodies
      • UserArray
    • OrderDirection
    • ApiPublicClient
    • Client
    • DateRangeFilter
    • Service
    • ListQueryParams
    • ClientInput
    • ApiPublicService
    • ServiceInput
    • PaginationMeta
    • Invoice
    • InvoiceIncomeInput
    • Payment
    • PaymentInput
    • PaymentItem
    • InvoiceInput
    • InvoiceEgressInput
    • Team
    • PaymentAllowedMethod
    • TeamInput
    • TeamSettingsInput
    • CfdiError
    • ApiPublicPaymentProcessorDetails
    • User
    • DraftInvoiceInput
    • ApiPublicPayment
    • UserInput
    • ClientAddress
    • DraftInvoiceUpdateInput
    • DraftInvoiceOutput
    • TaxSchema
    • RequestPaymentInput
    • StandardSuccessResponse
    • RegisterPaymentInput
    • ListResponse
    • ErrorResponse
    • ApiPublicIncomeInvoice
    • ValidationErrorResponse
    • RefundPaymentInput
    • ApiPublicTeam
    • MarkPaymentAsPaidInput
    • UnauthorizedError
    • ApiPublicUser
    • ApiPublicSearch
    • NotFoundError
    • ApiPublicThirdParty
    • InternalServerError
    • ApiPublicInvoiceConfig
    • ApiPublicRefund
    • ApiPublicAutomations
    • TeamSettings
    • TaxElement
    • SeriesInput
    • Series
    • ApiPublicWebhook
    • WebhookInput
    • ReceiptInput
    • WebhookUpdateInput
    • PaymentMethodEnum
    • PaymentFormEnum
    • AutomationTypeEnum
    • ItemSchema
    • SATDocument
    • UploadSupportDocumentInput
  1. Retentions

Retentions

Retentions API Guide#

Create, manage, and cancel CFDI retention documents (Constancias de Retenciones e Informacion de Pagos) with full SAT compliance. The Retentions API handles the complete lifecycle of withholding tax certificates required by Mexican tax law.

Overview#

Retentions are CFDI documents that certify taxes withheld by a payer on behalf of a recipient. They are required in scenarios such as interest payments, technology platform services, dividends, royalties, and other transactions where the payer is legally obligated to withhold taxes (ISR, IVA, IEPS) and report them to SAT.
Unlike standard invoices, retentions have a distinct structure: they are organized by retention key (type of operation), fiscal period, and withheld tax amounts rather than line items.

Key Features#

SAT Retention Keys - Support for all 26 retention types (01-26)
Automatic Tax Mapping - Friendly names (ISR, IVA, IEPS) mapped to SAT codes
Auto-Calculated Totals - Taxable, exempt, and retained amounts computed automatically
Complement Support - Built-in handling for Intereses (key 16), Plataformas Tecnologicas (key 26), and Otro tipo (key 25)
Folio Management - Automatic folio generation and stamping
File Generation - PDF and XML files generated on stamp
Cancellation - SAT-compliant cancellation with motive codes

Endpoints#

List Retentions#

Retrieve a paginated list of retention documents with filtering capabilities.
Query Parameters:
ParameterTypeDescription
limitinteger (1-100)Number of results per page (default: 10)
nextstringPagination cursor for next page
teamstringgigstack Connect: Target team ID
order_bystringField to sort by (default: created_at)
sortstringSort direction: asc or desc
created_gteintegerFilter by creation date (greater than or equal, unix timestamp ms)
created_lteintegerFilter by creation date (less than or equal, unix timestamp ms)
statusstringFilter by status: valid or canceled
retention_keystringFilter by retention type key (e.g., 14, 16, 26)
client_idstringFilter by client ID
Example Request:
Example Response:
{
    "message": "Retentions retrieved successfully",
    "data": [
        {
            "id": "ret_abc123",
            "uuid": "12345678-1234-1234-1234-123456789012",
            "status": "valid",
            "document_type": "retenciones",
            "retention_key": "14",
            "folio_number": "1",
            "series": "RET",
            "receiver": {
                "legal_name": "Juan Perez Garcia",
                "tax_id": "PEGJ800101ABC",
                "nationality": "Nacional"
            },
            "period": {
                "start": 1,
                "end": 12,
                "year": 2025
            },
            "totals": {
                "total_operation": 100000.00,
                "total_taxable": 100000.00,
                "total_exempt": 0,
                "total_retained": 10000.00,
                "tax_retained": [
                    {
                        "tax": "ISR",
                        "base": 100000.00,
                        "amount": 10000.00,
                        "payment_type": "03"
                    }
                ]
            },
            "stamp": {
                "uuid": "12345678-1234-1234-1234-123456789012",
                "stamped_at": "2025-06-15T10:30:00Z"
            },
            "livemode": true,
            "created_at": 1718451000000
        }
    ],
    "has_more": false,
    "total_results": 1
}

Create Retention#

Create and stamp a new retention CFDI document. The retention is normalized, stamped with SAT, and saved in a single operation.
Request Body:
FieldTypeRequiredDescription
retention_keystringYesSAT retention type code (01-26)
clientobjectYesClient reference (by ID, search, or inline data)
period_startnumberYesStart month of the fiscal period (1-12)
period_endnumberYesEnd month of the fiscal period (1-12)
period_yearnumberYesFiscal year
total_operationnumberYesTotal operation amount
taxesarrayYesArray of retained taxes
total_exemptnumberNoExempt amount (default: 0)
seriesstringNoInvoice series (default: "RET")
metadataobjectNoCustom metadata key-value pairs
idempotency_keystringNoUnique key to prevent duplicate creation
retention_descriptionstringNoRequired for key "25" (Otro tipo de retenciones)
interestobjectNoRequired for key "16" (Intereses)
platform_servicesobjectNoRequired for key "26" (Plataformas Tecnologicas)
Tax Object:
{
    "tax": "ISR",
    "base": 100000.00,
    "amount": 10000.00,
    "payment_type": "03"
}
tax (string, required) - Tax type: ISR, IVA, or IEPS. Mapped automatically to SAT codes (001, 002, 003).
base (number, required) - Taxable base amount.
amount (number, required) - Amount retained.
payment_type (string, optional) - SAT payment type code. Defaults to 03 (provisional) for ISR and 01 (definitivo) for IVA/IEPS.
Common Retention Keys:
KeyDescriptionComplement Required
01Servicios profesionalesNo
02Renta de inmueblesNo
06Enajenacion de accionesNo
14Dividendos o utilidadesNo
16InteresesYes (interest object)
25Otro tipo de retencionesYes (retention_description)
26Plataformas tecnologicasYes (platform_services object)
Example: Basic Retention (Dividends)
Example: Retention with Interest Complement (Key 16)
Example: Platform Services Retention (Key 26)
Example: Custom Retention Type (Key 25)
Response (201):
{
    "message": "Retention created successfully",
    "data": {
        "id": "ret_xyz789",
        "uuid": "98765432-1234-1234-1234-123456789012",
        "status": "valid",
        "document_type": "retenciones",
        "retention_key": "14",
        "folio_number": "1",
        "series": "RET",
        "issuer": {
            "legal_name": "Mi Empresa SA de CV",
            "tax_id": "MEM200101ABC",
            "tax_system": "601"
        },
        "receiver": {
            "legal_name": "Juan Perez Garcia",
            "tax_id": "PEGJ800101ABC",
            "nationality": "Nacional"
        },
        "period": {
            "start": 1,
            "end": 12,
            "year": 2025
        },
        "totals": {
            "total_operation": 500000.00,
            "total_taxable": 500000.00,
            "total_exempt": 0,
            "total_retained": 50000.00,
            "tax_retained": [
                {
                    "tax": "ISR",
                    "base": 500000.00,
                    "amount": 50000.00,
                    "payment_type": "03"
                }
            ]
        },
        "stamp": {
            "uuid": "98765432-1234-1234-1234-123456789012",
            "stamped_at": "2025-06-15T10:30:00Z"
        },
        "verification_url": "https://verificacfdi.facturaelectronica.sat.gob.mx/...",
        "livemode": true,
        "created_at": 1718451000000,
        "metadata": {
            "dividend_resolution": "ACT-2025-001"
        }
    }
}

Get Retention#

Retrieve a specific retention document by its UUID.
Example Request:

Get Retention Files#

Retrieve the PDF and XML files for a stamped retention.
Query Parameters:
file_type (string, optional) - Filter by file type: pdf or xml. Returns both if omitted.
team (string, optional) - gigstack Connect: Target team ID.
Example Request:
Example Response:
{
    "message": "Retention files retrieved successfully",
    "data": [
        {
            "content": "JVBERi0xLjQK...",
            "filename": "retention_98765432.pdf",
            "type": "application/pdf"
        }
    ]
}

Cancel Retention#

Cancel a stamped retention with SAT. Requires a cancellation motive.
Request Body:
{
    "motive": "02",
    "replace_uuid": null
}
Cancellation Motives:
CodeDescriptionRequires replace_uuid
01Comprobante emitido con errores con relacionYes
02Comprobante emitido con errores sin relacionNo
03No se llevo a cabo la operacionNo
04Operacion nominativa relacionada en factura globalNo
Example Request:
Example Response:
{
    "message": "Retention cancelled successfully",
    "data": {
        "id": "ret_xyz789",
        "uuid": "98765432-1234-1234-1234-123456789012",
        "status": "canceled",
        "cancellation": {
            "motive": "02",
            "canceled_at": "2025-06-20T15:00:00Z"
        }
    }
}

Retention Structure#

Retention Keys (Types)#

The retention_key identifies the type of operation that requires tax withholding. Common keys include:
KeyDescription
01Servicios profesionales
02Renta de inmuebles
03Comercio exterior
04Fideicomisos que no realizan actividades empresariales
05Planes de retiro
06Enajenacion de acciones
07Intereses reales hipotecarios
08Interes real por primas de seguro
09Premios
10Otras retenciones por ganancias
11Pagos a extranjeros
12Pagos a extranjeros consolidados
14Dividendos o utilidades
15Remanente distribuido
16Intereses
17Arrendamiento en fideicomiso
18Pagos a FIBRAS
22Enajenacion de FIBRAS
25Otro tipo de retenciones
26Plataformas tecnologicas

Tax Types#

Friendly NameSAT CodeDefault Payment Type
ISR00103 (Pago provisional)
IVA00201 (Pago definitivo)
IEPS00301 (Pago definitivo)

Auto-Calculated Fields#

When creating a retention, the following fields are computed automatically:
total_taxable = total_operation - total_exempt
total_retained = sum of all taxes[].amount
You do not need to send these values; they are derived from the input.

Complement-Specific Fields#

Interest Complement (Key 16)#

Required when retention_key is "16". Provides details about financial interest payments.
{
    "interest": {
        "financial_system": "02",
        "nominal_interest": 18500.00,
        "real_interest": 12300.00,
        "loss": 0,
        "withdrawal_aores": null,
        "financial_derivatives": null
    }
}
FieldTypeRequiredDescription
financial_systemstringYesFinancial system code
nominal_interestnumberYesNominal interest amount
real_interestnumberYesReal (inflation-adjusted) interest amount
lossnumberNoLoss amount (default: 0)
withdrawal_aoresstringNoAORES withdrawal code
financial_derivativesstringNoFinancial derivatives code

Platform Services Complement (Key 26)#

Required when retention_key is "26". Details technology platform service transactions.
{
    "platform_services": {
        "periodicity": "04",
        "services": [
            {
                "payment_form": "03",
                "service_type": "01",
                "service_date": "2025-03-15",
                "price_without_tax": 25000.00,
                "tax_rate": 0.16,
                "commission": 2500.00,
                "government_contribution": 0
            }
        ]
    }
}
Periodicity Codes:
CodeDescription
01Diario
02Semanal
03Quincenal
04Mensual
05Bimestral

Custom Retention Description (Key 25)#

Required when retention_key is "25". A free-text description of the retention type.
{
    "retention_description": "Retencion por servicios de asesoria fiscal especializada"
}

Use Cases#

1. Dividend Distribution#

A company distributes dividends to shareholders and must issue retention certificates for the ISR withheld.

2. Technology Platform (Uber, Rappi, etc.)#

A technology platform withholds taxes on behalf of service providers and must issue monthly retention certificates.

3. Professional Services Withholding#

A company paying a freelance consultant withholds ISR and IVA as required by law.

4. Bank Interest Payments#

A financial institution issues retention certificates for interest paid to account holders.

Best Practices#

1.
Use the correct retention key - Each type of withholding operation has a specific key. Using the wrong key will cause SAT validation errors.
2.
Provide complement data when required - Keys 16, 25, and 26 require additional fields. The API will reject requests missing required complement data.
3.
Verify client fiscal data - The receiver's RFC and tax system must be valid and registered with SAT.
4.
Use idempotency keys - Prevent duplicate retentions when retrying failed requests.
5.
Match fiscal periods accurately - The period_start, period_end, and period_year must correspond to the actual period covered by the retention.
6.
Review before stamping - Unlike draft invoices, retentions are stamped immediately on creation. Verify all data before submitting.
7.
Keep metadata organized - Use metadata to link retentions to internal records (resolutions, contracts, account numbers).

Related Resources#

Clients API - Manage retention recipients
Invoices API - Standard CFDI invoicing
Teams API - Configure team SAT certificates
CFDI Errors Reference - Error codes for stamping failures

Error Handling#

Missing Required Fields#

{
    "message": "Invalid request body",
    "error": "retention_key is required"
}

Invalid Retention Key#

{
    "message": "Invalid request body",
    "error": "retention_key must be a valid SAT retention type (01-26)"
}

Missing Complement Data#

{
    "message": "Invalid request body",
    "error": "interest object is required for retention key 16"
}

Retention Not Found#

{
    "message": "Resource not found"
}

Already Canceled#

{
    "message": "Retention is already canceled"
}

Stamping Error#

{
    "message": "An error occurred while creating retention",
    "error": {
        "code": "CFDI33106",
        "message": "El RFC del receptor no es valido"
    }
}

For additional assistance, contact support@gigstack.io
Modified at 2026-03-11 11:06:50
Previous
Delete webhook
Next
List retentions
Built with