[Ejemplos](https://fe.kembec.com/ejemplos/) / Guía de remisión remitente (09) / Caso 20 de 21

# Guía de remisión por venta

Transporte privado (02): dos placas, el conductor con su licencia, peso bruto, tres bultos, la factura relacionada y una línea con un «&» que el XML escapa.

Firma este JSON con el certificado de prueba y tu `DigestValue` tiene que ser `8Xl0WUzgswT/waYx0KA3GSQMcKc=`. El sello es ese valor, dibujado.

Los tres archivos, en el repositorio: [el JSON de entrada](https://github.com/Kembec/facturacion-electronica-sunat-sdk/blob/v0.1.0-beta.5/fixtures/09-despatch-sale.json), [el XML sin firmar](https://github.com/Kembec/facturacion-electronica-sunat-sdk/blob/v0.1.0-beta.5/tests/vectors/09-despatch-sale.unsigned.xml) y [el XML firmado](https://github.com/Kembec/facturacion-electronica-sunat-sdk/blob/v0.1.0-beta.5/tests/vectors/09-despatch-sale.signed.xml).

El SDK la envía con `sunat-sdk gre-send` y consulta su ticket con `sunat-sdk gre-ticket`: va al servicio REST de la SUNAT, no al `billService` de la factura ([Paso a producción](https://fe.kembec.com/empezar/paso-a-produccion/#beta-y-produccion)).

La SUNAT no tiene ambiente de pruebas para la guía, y lo que contrasta con sus registros (RUC, registro del MTC, establecimientos) se sabe al enviarla. Lo demás se comprueba aquí: este XML firmado valida contra el esquema UBL 2.1 de OASIS, y si tu JSON rompe una regla de la SUNAT que se verifica con el XML solo, `build` lo rechaza con el mismo código de error que daría la SUNAT.

## Entrada en JSON

`fixtures/09-despatch-sale.json`:

```json
{
  "kind": "despatch",
  "ubl_version": "2.1",
  "document_type": "09",
  "series": "T001",
  "number": "1",
  "issue_date": "2026-10-15T10:30:00-05:00",
  "note": "Entregar en almacén de recepción",
  "issuer": {
    "ruc": "20123456789",
    "legal_name": "EMPRESA DEMO ORACULO S.A.C.",
    "trade_name": "DEMO ORACULO",
    "address": {
      "ubigeo": "150101",
      "country_code": "PE",
      "department": "LIMA",
      "province": "LIMA",
      "district": "LIMA",
      "urbanization": "-",
      "street": "AV. EJEMPLO 123",
      "establishment_code": "0000"
    }
  },
  "recipient": {
    "document_type": "6",
    "document_number": "20987654321",
    "legal_name": "CLIENTE DEMO S.A."
  },
  "related_documents": [
    {
      "document_type": "01",
      "document_number": "F001-123",
      "description": "Factura",
      "issuer_ruc": "20123456789"
    }
  ],
  "shipment": {
    "reason_code": "01",
    "reason_description": "Venta",
    "transport_mode": "02",
    "start_date": "2026-10-15",
    "gross_weight": "125.500",
    "weight_unit": "KGM",
    "packages": "3",
    "vehicles": [
      {
        "plate": "ABC123"
      },
      {
        "plate": "XYZ9876"
      }
    ],
    "drivers": [
      {
        "document_type": "1",
        "document_number": "45678912",
        "first_name": "JUAN CARLOS",
        "family_name": "PÉREZ QUISPE",
        "license": "Q45678912"
      }
    ],
    "origin": {
      "ubigeo": "150101",
      "address": "AV. EJEMPLO 123, LIMA",
      "establishment_code": "0000",
      "establishment_ruc": "20123456789"
    },
    "destination": {
      "ubigeo": "040101",
      "address": "CALLE MERCADERES 456, AREQUIPA"
    }
  },
  "lines": [
    {
      "quantity": "10",
      "unit": "NIU",
      "description": "Cuaderno A4 cuadriculado 100 hojas",
      "product_code": "CUA-A4-100",
      "sunat_product_code": "14111514"
    },
    {
      "quantity": "2.5",
      "unit": "KGM",
      "description": "Papel bond reciclado & cartón"
    }
  ]
}
```

## XML sin firmar

`tests/vectors/09-despatch-sale.unsigned.xml`:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<DespatchAdvice xmlns="urn:oasis:names:specification:ubl:schema:xsd:DespatchAdvice-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"><ext:UBLExtensions><ext:UBLExtension><ext:ExtensionContent></ext:ExtensionContent></ext:UBLExtension></ext:UBLExtensions><cbc:UBLVersionID>2.1</cbc:UBLVersionID><cbc:CustomizationID>2.0</cbc:CustomizationID><cbc:ID>T001-1</cbc:ID><cbc:IssueDate>2026-10-15</cbc:IssueDate><cbc:IssueTime>10:30:00</cbc:IssueTime><cbc:DespatchAdviceTypeCode>09</cbc:DespatchAdviceTypeCode><cbc:Note>Entregar en almacén de recepción</cbc:Note><cac:AdditionalDocumentReference><cbc:ID>F001-123</cbc:ID><cbc:DocumentTypeCode>01</cbc:DocumentTypeCode><cbc:DocumentType>Factura</cbc:DocumentType><cac:IssuerParty><cac:PartyIdentification><cbc:ID schemeID="6">20123456789</cbc:ID></cac:PartyIdentification></cac:IssuerParty></cac:AdditionalDocumentReference><cac:Signature><cbc:ID>IDSignKG</cbc:ID><cac:SignatoryParty><cac:PartyIdentification><cbc:ID>20123456789</cbc:ID></cac:PartyIdentification><cac:PartyName><cbc:Name>EMPRESA DEMO ORACULO S.A.C.</cbc:Name></cac:PartyName></cac:SignatoryParty><cac:DigitalSignatureAttachment><cac:ExternalReference><cbc:URI>#signatureKG</cbc:URI></cac:ExternalReference></cac:DigitalSignatureAttachment></cac:Signature><cac:DespatchSupplierParty><cac:Party><cac:PartyIdentification><cbc:ID schemeID="6">20123456789</cbc:ID></cac:PartyIdentification><cac:PartyLegalEntity><cbc:RegistrationName>EMPRESA DEMO ORACULO S.A.C.</cbc:RegistrationName></cac:PartyLegalEntity></cac:Party></cac:DespatchSupplierParty><cac:DeliveryCustomerParty><cac:Party><cac:PartyIdentification><cbc:ID schemeID="6">20987654321</cbc:ID></cac:PartyIdentification><cac:PartyLegalEntity><cbc:RegistrationName>CLIENTE DEMO S.A.</cbc:RegistrationName></cac:PartyLegalEntity></cac:Party></cac:DeliveryCustomerParty><cac:Shipment><cbc:ID>SUNAT_Envio</cbc:ID><cbc:HandlingCode>01</cbc:HandlingCode><cbc:HandlingInstructions>Venta</cbc:HandlingInstructions><cbc:GrossWeightMeasure unitCode="KGM">125.500</cbc:GrossWeightMeasure><cbc:TotalTransportHandlingUnitQuantity>3</cbc:TotalTransportHandlingUnitQuantity><cac:ShipmentStage><cbc:TransportModeCode>02</cbc:TransportModeCode><cac:TransitPeriod><cbc:StartDate>2026-10-15</cbc:StartDate></cac:TransitPeriod><cac:DriverPerson><cbc:ID schemeID="1">45678912</cbc:ID><cbc:FirstName>JUAN CARLOS</cbc:FirstName><cbc:FamilyName>PÉREZ QUISPE</cbc:FamilyName><cbc:JobTitle>Principal</cbc:JobTitle><cac:IdentityDocumentReference><cbc:ID>Q45678912</cbc:ID></cac:IdentityDocumentReference></cac:DriverPerson></cac:ShipmentStage><cac:Delivery><cac:DeliveryAddress><cbc:ID>040101</cbc:ID><cac:AddressLine><cbc:Line>CALLE MERCADERES 456, AREQUIPA</cbc:Line></cac:AddressLine></cac:DeliveryAddress><cac:Despatch><cac:DespatchAddress><cbc:ID>150101</cbc:ID><cbc:AddressTypeCode listID="20123456789">0000</cbc:AddressTypeCode><cac:AddressLine><cbc:Line>AV. EJEMPLO 123, LIMA</cbc:Line></cac:AddressLine></cac:DespatchAddress></cac:Despatch></cac:Delivery><cac:TransportHandlingUnit><cac:TransportEquipment><cbc:ID>ABC123</cbc:ID><cac:AttachedTransportEquipment><cbc:ID>XYZ9876</cbc:ID></cac:AttachedTransportEquipment></cac:TransportEquipment></cac:TransportHandlingUnit></cac:Shipment><cac:DespatchLine><cbc:ID>1</cbc:ID><cbc:DeliveredQuantity unitCode="NIU">10</cbc:DeliveredQuantity><cac:OrderLineReference><cbc:LineID>1</cbc:LineID></cac:OrderLineReference><cac:Item><cbc:Description>Cuaderno A4 cuadriculado 100 hojas</cbc:Description><cac:SellersItemIdentification><cbc:ID>CUA-A4-100</cbc:ID></cac:SellersItemIdentification><cac:CommodityClassification><cbc:ItemClassificationCode>14111514</cbc:ItemClassificationCode></cac:CommodityClassification></cac:Item></cac:DespatchLine><cac:DespatchLine><cbc:ID>2</cbc:ID><cbc:DeliveredQuantity unitCode="KGM">2.5</cbc:DeliveredQuantity><cac:OrderLineReference><cbc:LineID>2</cbc:LineID></cac:OrderLineReference><cac:Item><cbc:Description>Papel bond reciclado &amp; cartón</cbc:Description></cac:Item></cac:DespatchLine></DespatchAdvice>
```

## Firma

Firmado con el certificado de prueba del SDK, el que baja la [guía de inicio](https://fe.kembec.com/empezar/guia-de-inicio/).

8Xl0WUzgswT/waYx0KA3GSQMcKc=

Si tu `DigestValue` es este, tu XML es el mismo que el del SDK. Con el certificado de prueba el `SignatureValue` también coincide; con el tuyo cambia, porque depende de tu clave.

- **DigestValue**: `8Xl0WUzgswT/waYx0KA3GSQMcKc=`
- **SignatureValue**: `yrYY1G940gsZ37TbsePakGNZnEaf+9ojsdPqCBizqCqfPXWiyH9m5GUAifiSCPsuJZZwszdNfhU1M7yO4BZ32zaLiXPuJejp0vdZeIFcDFddbfsDP+nl/+dA3FNwy59t2J078IbiOQQSXl6o4L1B0I5AEbE/HAODXHIgYIlWLtN6rDhCAPV6iQ8F8wuYgl1sDoB0duNS3x69ciK4/tH3av5R7ddML6l9tz+1HoNkJ6Q3yZMWzMVvyyx0GDcwKmwaSbSqdZR/piNQPlPJp9cR/PWL9RGKLKjDKPIm6EZLDxkN3sfkeO3Y5A1Mgck1aS59MKvgNzAC1N4Ba70GOFD0zg==`

### XML firmado

`tests/vectors/09-despatch-sale.signed.xml`:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<DespatchAdvice xmlns="urn:oasis:names:specification:ubl:schema:xsd:DespatchAdvice-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"><ext:UBLExtensions><ext:UBLExtension><ext:ExtensionContent><ds:Signature Id="signatureKG"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><ds:Reference URI=""><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><ds:DigestValue>8Xl0WUzgswT/waYx0KA3GSQMcKc=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>yrYY1G940gsZ37TbsePakGNZnEaf+9ojsdPqCBizqCqfPXWiyH9m5GUAifiSCPsuJZZwszdNfhU1M7yO4BZ32zaLiXPuJejp0vdZeIFcDFddbfsDP+nl/+dA3FNwy59t2J078IbiOQQSXl6o4L1B0I5AEbE/HAODXHIgYIlWLtN6rDhCAPV6iQ8F8wuYgl1sDoB0duNS3x69ciK4/tH3av5R7ddML6l9tz+1HoNkJ6Q3yZMWzMVvyyx0GDcwKmwaSbSqdZR/piNQPlPJp9cR/PWL9RGKLKjDKPIm6EZLDxkN3sfkeO3Y5A1Mgck1aS59MKvgNzAC1N4Ba70GOFD0zg==</ds:SignatureValue><ds:KeyInfo><ds:X509Data><ds:X509Certificate>MIID8zCCAtugAwIBAgIUY968iRS4gHDjt9RwTaDaujmFLO0wDQYJKoZIhvcNAQELBQAwgYgxCzAJBgNVBAYTAlBFMS8wLQYDVQQKDCZURVNUIE9OTFkgLSBOT1QgVkFMSUQgRk9SIEFOWSBUQVhQQVlFUjESMBAGA1UECwwJVEVTVCBPTkxZMRQwEgYDVQQFEwsyMDAwMDAwMDAwMTEeMBwGA1UEAwwVVEVTVCBPTkxZIDIwMDAwMDAwMDAxMB4XDTI2MTAxNTIxMjc0NVoXDTM2MTAxMjIxMjc0NVowgYgxCzAJBgNVBAYTAlBFMS8wLQYDVQQKDCZURVNUIE9OTFkgLSBOT1QgVkFMSUQgRk9SIEFOWSBUQVhQQVlFUjESMBAGA1UECwwJVEVTVCBPTkxZMRQwEgYDVQQFEwsyMDAwMDAwMDAwMTEeMBwGA1UEAwwVVEVTVCBPTkxZIDIwMDAwMDAwMDAxMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6GZTtpFyih4C6ETakE6Q4+SFBFWJ/TQi2pbxJRD7GkQ1tKeB+ENcBk8EjnOocxdYWvSBpOd9UYkpc2C+jlbVWd04ey8psznwCHzJJ1+qgQqVI8PpH5A4eEw5LGXupHmnJSYpGXFGIJ6+tlJRqvZbq7RTh7Rpxs4DkCjUhUke/BKIZahYDzSGFLlsWx01Dq8Xeb6xF2sLlZXy/b0MvRZAe7I/xplIftS/rrDQ/rE5DfS0Dibayc/uNIRw1+NiKpT0wwY/VCzRQrM27dG7sTyhNAy6C3vtRmO5Bl9+0wrXldZcR4VSm1yrg65KRWv6DNcG2MkxRYBphaM+sJfkNECs6wIDAQABo1MwUTAdBgNVHQ4EFgQUE359gu7BEXWLRhx+VNBeec2Pp/kwHwYDVR0jBBgwFoAUE359gu7BEXWLRhx+VNBeec2Pp/kwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAzjWgukifoL9gZckM2jWW7a+N6+5W/0EkGJVFV9RbCceNpDpdMyVD4QyVm1nOJ/bQzOLdDnjyD3J34/1pEwo/hS/HehPy50twvf/uKEwPU4TNQTyjChnM3k+IX7cOusuPIBsC6trufeHOSky5lWiKWusMHo8VsPvVinE0n/RqTo47enHPFa6huF3egiQEJ6H+lxerXvWT8IkaGFA2YKjAGGsenlCSw9rRGX4tzQtUkJx0oFaEZGNpq+OYr334J3cZp9LskUFnrvRoAz3Fk8HdbVlfQTovFunFY9VzxbKjBfyWa6hymTxcvBR9x4ZfUKM9P3REeBKaTWdqe2oz4d6LLA==</ds:X509Certificate></ds:X509Data></ds:KeyInfo></ds:Signature></ext:ExtensionContent></ext:UBLExtension></ext:UBLExtensions><cbc:UBLVersionID>2.1</cbc:UBLVersionID><cbc:CustomizationID>2.0</cbc:CustomizationID><cbc:ID>T001-1</cbc:ID><cbc:IssueDate>2026-10-15</cbc:IssueDate><cbc:IssueTime>10:30:00</cbc:IssueTime><cbc:DespatchAdviceTypeCode>09</cbc:DespatchAdviceTypeCode><cbc:Note>Entregar en almacén de recepción</cbc:Note><cac:AdditionalDocumentReference><cbc:ID>F001-123</cbc:ID><cbc:DocumentTypeCode>01</cbc:DocumentTypeCode><cbc:DocumentType>Factura</cbc:DocumentType><cac:IssuerParty><cac:PartyIdentification><cbc:ID schemeID="6">20123456789</cbc:ID></cac:PartyIdentification></cac:IssuerParty></cac:AdditionalDocumentReference><cac:Signature><cbc:ID>IDSignKG</cbc:ID><cac:SignatoryParty><cac:PartyIdentification><cbc:ID>20123456789</cbc:ID></cac:PartyIdentification><cac:PartyName><cbc:Name>EMPRESA DEMO ORACULO S.A.C.</cbc:Name></cac:PartyName></cac:SignatoryParty><cac:DigitalSignatureAttachment><cac:ExternalReference><cbc:URI>#signatureKG</cbc:URI></cac:ExternalReference></cac:DigitalSignatureAttachment></cac:Signature><cac:DespatchSupplierParty><cac:Party><cac:PartyIdentification><cbc:ID schemeID="6">20123456789</cbc:ID></cac:PartyIdentification><cac:PartyLegalEntity><cbc:RegistrationName>EMPRESA DEMO ORACULO S.A.C.</cbc:RegistrationName></cac:PartyLegalEntity></cac:Party></cac:DespatchSupplierParty><cac:DeliveryCustomerParty><cac:Party><cac:PartyIdentification><cbc:ID schemeID="6">20987654321</cbc:ID></cac:PartyIdentification><cac:PartyLegalEntity><cbc:RegistrationName>CLIENTE DEMO S.A.</cbc:RegistrationName></cac:PartyLegalEntity></cac:Party></cac:DeliveryCustomerParty><cac:Shipment><cbc:ID>SUNAT_Envio</cbc:ID><cbc:HandlingCode>01</cbc:HandlingCode><cbc:HandlingInstructions>Venta</cbc:HandlingInstructions><cbc:GrossWeightMeasure unitCode="KGM">125.500</cbc:GrossWeightMeasure><cbc:TotalTransportHandlingUnitQuantity>3</cbc:TotalTransportHandlingUnitQuantity><cac:ShipmentStage><cbc:TransportModeCode>02</cbc:TransportModeCode><cac:TransitPeriod><cbc:StartDate>2026-10-15</cbc:StartDate></cac:TransitPeriod><cac:DriverPerson><cbc:ID schemeID="1">45678912</cbc:ID><cbc:FirstName>JUAN CARLOS</cbc:FirstName><cbc:FamilyName>PÉREZ QUISPE</cbc:FamilyName><cbc:JobTitle>Principal</cbc:JobTitle><cac:IdentityDocumentReference><cbc:ID>Q45678912</cbc:ID></cac:IdentityDocumentReference></cac:DriverPerson></cac:ShipmentStage><cac:Delivery><cac:DeliveryAddress><cbc:ID>040101</cbc:ID><cac:AddressLine><cbc:Line>CALLE MERCADERES 456, AREQUIPA</cbc:Line></cac:AddressLine></cac:DeliveryAddress><cac:Despatch><cac:DespatchAddress><cbc:ID>150101</cbc:ID><cbc:AddressTypeCode listID="20123456789">0000</cbc:AddressTypeCode><cac:AddressLine><cbc:Line>AV. EJEMPLO 123, LIMA</cbc:Line></cac:AddressLine></cac:DespatchAddress></cac:Despatch></cac:Delivery><cac:TransportHandlingUnit><cac:TransportEquipment><cbc:ID>ABC123</cbc:ID><cac:AttachedTransportEquipment><cbc:ID>XYZ9876</cbc:ID></cac:AttachedTransportEquipment></cac:TransportEquipment></cac:TransportHandlingUnit></cac:Shipment><cac:DespatchLine><cbc:ID>1</cbc:ID><cbc:DeliveredQuantity unitCode="NIU">10</cbc:DeliveredQuantity><cac:OrderLineReference><cbc:LineID>1</cbc:LineID></cac:OrderLineReference><cac:Item><cbc:Description>Cuaderno A4 cuadriculado 100 hojas</cbc:Description><cac:SellersItemIdentification><cbc:ID>CUA-A4-100</cbc:ID></cac:SellersItemIdentification><cac:CommodityClassification><cbc:ItemClassificationCode>14111514</cbc:ItemClassificationCode></cac:CommodityClassification></cac:Item></cac:DespatchLine><cac:DespatchLine><cbc:ID>2</cbc:ID><cbc:DeliveredQuantity unitCode="KGM">2.5</cbc:DeliveredQuantity><cac:OrderLineReference><cbc:LineID>2</cbc:LineID></cac:OrderLineReference><cac:Item><cbc:Description>Papel bond reciclado &amp; cartón</cbc:Description></cac:Item></cac:DespatchLine></DespatchAdvice>
```

## Reproducirlo

Con el SDK instalado como dice la [guía de inicio](https://fe.kembec.com/empezar/guia-de-inicio/#2-instala-el-sdk), baja el caso y el certificado de prueba:

```bash
curl -fsSL --remote-name-all \
  https://fe.kembec.com/sdk/v0.1.0-beta.5/09-despatch-sale.json \
  https://fe.kembec.com/sdk/v0.1.0-beta.5/test-cert.pem \
  https://fe.kembec.com/sdk/v0.1.0-beta.5/test-key.pem
```

Fírmalo como en la [guía](https://fe.kembec.com/empezar/guia-de-inicio/#2-firma-el-caso-de-prueba): tu `DigestValue` tiene que ser el de arriba.

### PHP

En `firmar.php`, la línea del JSON queda así:

`firmar.php`:

```php
$factura = file_get_contents(__DIR__ . '/09-despatch-sale.json');
```

```bash
php firmar.php
```

### JavaScript

En `firmar.mjs`, la línea del JSON queda así:

`firmar.mjs`:

```js
const built = JSON.parse(sdk.build(leer('09-despatch-sale.json')));
```

```bash
node firmar.mjs
```

### Python

En `firmar.py`, la línea del JSON queda así:

`firmar.py`:

```python
built = sunat_sdk.build(leer('09-despatch-sale.json'))
```

```bash
python firmar.py
```

### CLI

```bash
sunat-sdk build < 09-despatch-sale.json \
  | sunat-sdk sign --cert test-cert.pem --key test-key.pem > firmada.json
grep -o '"digest_value":"[^"]*"' firmada.json
grep -q '"digest_value":"8Xl0WUzgswT/waYx0KA3GSQMcKc="' firmada.json && echo "digest ok"
```
