> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.staple.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.staple.ai/_mcp/server.

# Einvoice XML Validation

POST https://api.staple.io/v2/einvoice/mexico/validate
Content-Type: application/json

# Validate Mexico E-Invoice

Run SAT validation on an already-created document. Executes three steps in order and records the outcome (audit log + validation-history row):

1.  **Schema** — CFDI 4.0 structure + required attributes.
    
2.  **SAT status** — queries SAT's `ConsultaCFDIService` for the invoice status (`Vigente` = valid).
    
3.  **RFC** — the receiver RFC matches the configured company RFC.
    

The document must have finished importing (creation `status = SUCCESS`) before it can be validated.

## Endpoint

`POST /v2/einvoice/mexico/validate`

## Request Headers

| Attribute | Type | Option | Description |
| --- | --- | --- | --- |
| `x-api-key` | String | Required | A unique string |
| `Authorization` | String | Required | Bearer token |
| `Content-Type` | String | Required | `application/json` |
| `Accept` | String | Optional | `application/json` |

## Request Payload

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `documentId` | String | ✅ | The Staple document id to validate |

```
{
  "documentId": "245234"
}

```

## Response (Success — VALID)

```
{
  "documentId": "245234",
  "uuid": "699628be-2f06-4bc9-adc2-860b51eecbca",
  "validation_result": "VALID",
  "validatedAt": "2026-07-09T08:29:06.785Z",
  "invalid_reason": null,
  "steps": {
    "schema":    { "result": "PASS", "detail": null },
    "satStatus": { "result": "PASS", "detail": null },
    "rfc":       { "result": "PASS", "detail": null }
  }
}

```

## Response (INVALID)

```
{
  "documentId": "245234",
  "uuid": "699628be-2f06-4bc9-adc2-860b51eecbca",
  "validation_result": "INVALID",
  "validatedAt": "2026-07-09T08:29:06.785Z",
  "invalid_reason": "Cancelled E-Invoice",
  "steps": {
    "schema":    { "result": "PASS", "detail": null },
    "satStatus": { "result": "FAIL", "detail": "Cancelled E-Invoice" }
  }
}

```

## Response Fields

| Field | Type | Description |
| --- | --- | --- |
| `documentId` | String | The validated document id |
| `uuid` | String | CFDI Folio Fiscal (UUID) from the XML |
| `validation_result` | String | `VALID` or `INVALID` |
| `validatedAt` | String | ISO timestamp of the validation run |
| `invalid_reason` | String | null |
| `steps` | Object | Per-step results — `schema`, `satStatus`, `rfc` |

### `steps.\*` Fields

| Field | Type | Description |
| --- | --- | --- |
| `result` | String | `PASS` or `FAIL` |
| `detail` | String | null |

Only the steps that actually ran are present. Validation stops at the first failing step, so e.g. a schema failure returns `steps.schema` only; a SAT failure returns `schema` + `satStatus`.

## Notes

-   `documentId` is the main identifier for this endpoint.
    
-   Validation can only run once the document's creation `status = SUCCESS` (document is `RECEIVED`/`COMPLETED`).
    
-   Common `satStatus.detail` values: `Cancelled E-Invoice`, `E-Invoice Not Found`, `Unknown SAT Status:` , `SAT service unavailable: no response after 3 attempts`.
    
-   Every call is recorded as a validation-history row and an audit-trail entry (`validated_document`).
    

## Errors

| Status | When |
| --- | --- |
| `400 Bad Request` | Missing `documentId`; document not found; caller not authorized; document not yet processed (creation status not success); XML missing; or CFDI has no UUID |
| `401 / 403` | Missing/invalid `x-api-key` or `Authorization`, or no access to the document |
| `502 / 503` | SAT (or upstream dependency) temporarily unavailable |

* * *

Want the **example request/response pairs** formatted for Postman (so you can drop them into saved Examples — e.g. one `VALID`, one `INVALID – Cancelled`, one `400 – not processed`), or shall I paste the **status endpoint** next?

Reference: https://docs.staple.ai/api-reference/v2/e-invoice/einvoice-xml-validation

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: v2
  version: 1.0.0
paths:
  /v2/einvoice/mexico/validate:
    post:
      operationId: einvoiceXmlValidation
      summary: Einvoice XML Validation
      description: "# Validate Mexico E-Invoice\n\nRun SAT validation on an already-created document. Executes three steps in order and records the outcome (audit log + validation-history row):\n\n1.  **Schema**\_— CFDI 4.0 structure + required attributes.\n    \n2.  **SAT status**\_— queries SAT's\_`ConsultaCFDIService`\_for the invoice status (`Vigente`\_= valid).\n    \n3.  **RFC**\_— the receiver RFC matches the configured company RFC.\n    \n\nThe document must have finished importing (creation `status = SUCCESS`) before it can be validated.\n\n## Endpoint\n\n`POST /v2/einvoice/mexico/validate`\n\n## Request Headers\n\n| Attribute | Type | Option | Description |\n| --- | --- | --- | --- |\n| `x-api-key` | String | Required | A unique string |\n| `Authorization` | String | Required | Bearer token |\n| `Content-Type` | String | Required | `application/json` |\n| `Accept` | String | Optional | `application/json` |\n\n## Request Payload\n\n| Field | Type | Required | Description |\n| --- | --- | --- | --- |\n| `documentId` | String | ✅ | The Staple document id to validate |\n\n```\n{\n  \"documentId\": \"245234\"\n}\n\n```\n\n## Response (Success — VALID)\n\n```\n{\n  \"documentId\": \"245234\",\n  \"uuid\": \"699628be-2f06-4bc9-adc2-860b51eecbca\",\n  \"validation_result\": \"VALID\",\n  \"validatedAt\": \"2026-07-09T08:29:06.785Z\",\n  \"invalid_reason\": null,\n  \"steps\": {\n    \"schema\":    { \"result\": \"PASS\", \"detail\": null },\n    \"satStatus\": { \"result\": \"PASS\", \"detail\": null },\n    \"rfc\":       { \"result\": \"PASS\", \"detail\": null }\n  }\n}\n\n```\n\n## Response (INVALID)\n\n```\n{\n  \"documentId\": \"245234\",\n  \"uuid\": \"699628be-2f06-4bc9-adc2-860b51eecbca\",\n  \"validation_result\": \"INVALID\",\n  \"validatedAt\": \"2026-07-09T08:29:06.785Z\",\n  \"invalid_reason\": \"Cancelled E-Invoice\",\n  \"steps\": {\n    \"schema\":    { \"result\": \"PASS\", \"detail\": null },\n    \"satStatus\": { \"result\": \"FAIL\", \"detail\": \"Cancelled E-Invoice\" }\n  }\n}\n\n```\n\n## Response Fields\n\n| Field | Type | Description |\n| --- | --- | --- |\n| `documentId` | String | The validated document id |\n| `uuid` | String | CFDI Folio Fiscal (UUID) from the XML |\n| `validation_result` | String | `VALID`\_or\_`INVALID` |\n| `validatedAt` | String | ISO timestamp of the validation run |\n| `invalid_reason` | String | null |\n| `steps` | Object | Per-step results —\_`schema`,\_`satStatus`,\_`rfc` |\n\n### `steps.\\*`\_Fields\n\n| Field | Type | Description |\n| --- | --- | --- |\n| `result` | String | `PASS`\_or\_`FAIL` |\n| `detail` | String | null |\n\nOnly the steps that actually ran are present. Validation stops at the first failing step, so e.g. a schema failure returns `steps.schema` only; a SAT failure returns `schema` + `satStatus`.\n\n## Notes\n\n-   `documentId`\_is the main identifier for this endpoint.\n    \n-   Validation can only run once the document's creation\_`status = SUCCESS`\_(document is\_`RECEIVED`/`COMPLETED`).\n    \n-   Common\_`satStatus.detail`\_values:\_`Cancelled E-Invoice`,\_`E-Invoice Not Found`,\_`Unknown SAT Status:` ,\_`SAT service unavailable: no response after 3 attempts`.\n    \n-   Every call is recorded as a validation-history row and an audit-trail entry (`validated_document`).\n    \n\n## Errors\n\n| Status | When |\n| --- | --- |\n| `400 Bad Request` | Missing\_`documentId`; document not found; caller not authorized; document not yet processed (creation status not success); XML missing; or CFDI has no UUID |\n| `401 / 403` | Missing/invalid\_`x-api-key`\_or\_`Authorization`, or no access to the document |\n| `502 / 503` | SAT (or upstream dependency) temporarily unavailable |\n\n* * *\n\nWant the **example request/response pairs** formatted for Postman (so you can drop them into saved Examples — e.g. one `VALID`, one `INVALID – Cancelled`, one `400 – not processed`), or shall I paste the **status endpoint** next?"
      tags:
        - eInvoice
      parameters:
        - name: x-api-key
          in: header
          description: API key issued by Staple.
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/E-Invoice_einvoiceXmlValidation_Response_200
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                documentId:
                  type: string
servers:
  - url: https://api.staple.io
    description: https://api.staple.io
components:
  schemas:
    E-Invoice_einvoiceXmlValidation_Response_200:
      type: object
      properties: {}
      description: Empty response body
      title: E-Invoice_einvoiceXmlValidation_Response_200
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: API key issued by Staple.

```

## Examples



**Request**

```json
{
  "documentId": "244957"
}
```

**Response**

```json
{}
```

**SDK Code**

```python E-Invoice_einvoiceXmlValidation_example
import requests

url = "https://api.staple.io/v2/einvoice/mexico/validate"

payload = { "documentId": "244957" }
headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript E-Invoice_einvoiceXmlValidation_example
const url = 'https://api.staple.io/v2/einvoice/mexico/validate';
const options = {
  method: 'POST',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"documentId":"244957"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go E-Invoice_einvoiceXmlValidation_example
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.staple.io/v2/einvoice/mexico/validate"

	payload := strings.NewReader("{\n  \"documentId\": \"244957\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("x-api-key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby E-Invoice_einvoiceXmlValidation_example
require 'uri'
require 'net/http'

url = URI("https://api.staple.io/v2/einvoice/mexico/validate")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"documentId\": \"244957\"\n}"

response = http.request(request)
puts response.read_body
```

```java E-Invoice_einvoiceXmlValidation_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.staple.io/v2/einvoice/mexico/validate")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"documentId\": \"244957\"\n}")
  .asString();
```

```php E-Invoice_einvoiceXmlValidation_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.staple.io/v2/einvoice/mexico/validate', [
  'body' => '{
  "documentId": "244957"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp E-Invoice_einvoiceXmlValidation_example
using RestSharp;

var client = new RestClient("https://api.staple.io/v2/einvoice/mexico/validate");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"documentId\": \"244957\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift E-Invoice_einvoiceXmlValidation_example
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = ["documentId": "244957"] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.staple.io/v2/einvoice/mexico/validate")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```