diff --git a/README.md b/README.md index bdd38d5..5477968 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,20 @@ await facturapi.invoices.sendByEmail(invoice.id, { }); ``` +## API error language + +For API V2, request English error messages with `Accept-Language` using the existing client configuration (Node SDK 4.17.0 or later): + +```javascript +import Facturapi from 'facturapi' + +const facturapi = new Facturapi('YOUR_API_KEY', { + headers: { 'Accept-Language': 'en' }, +}) +``` + +Use `es` for Spanish. Regional variants such as `en-US` and preferences such as `en;q=0.9, es;q=0.5` are also supported. Missing or unsupported language preferences fall back to Spanish. The setting applies to all requests from this instance; use separate instances for different languages. Codes remain unchanged, and external SAT/PAC messages and uncataloged legacy messages retain their original language. Localization requires server-side API V2 support; it does not translate local SDK errors. + ## Documentation Visit [docs.facturapi.io](https://docs.facturapi.io). diff --git a/test/node/runtime-compat.node.test.ts b/test/node/runtime-compat.node.test.ts index 0e5f97f..b8bd73a 100644 --- a/test/node/runtime-compat.node.test.ts +++ b/test/node/runtime-compat.node.test.ts @@ -53,6 +53,7 @@ describe('runtime compatibility (node)', () => { const client = new Facturapi('sk_test_123', { headers: { 'x-facturapi-client': 'MCP', + 'Accept-Language': 'en-US', authorization: 'Bearer ignored', 'content-type': 'text/plain', }, @@ -64,6 +65,7 @@ describe('runtime compatibility (node)', () => { 'Bearer sk_test_123', ) expect(getHeader(options?.headers, 'x-facturapi-client')).toBe('MCP') + expect(getHeader(options?.headers, 'Accept-Language')).toBe('en-US') expect(getHeader(options?.headers, 'Content-Type')).toBe( 'application/json', ) diff --git a/test/web/runtime-compat.web.test.ts b/test/web/runtime-compat.web.test.ts index d855cc9..830909d 100644 --- a/test/web/runtime-compat.web.test.ts +++ b/test/web/runtime-compat.web.test.ts @@ -66,6 +66,7 @@ describe('runtime compatibility (web simulation)', () => { const client = new Facturapi('sk_test_123', { headers: { 'x-facturapi-client': 'MCP', + 'Accept-Language': 'en-US', authorization: 'Bearer ignored', 'content-type': 'text/plain', }, @@ -77,6 +78,7 @@ describe('runtime compatibility (web simulation)', () => { 'Bearer sk_test_123', ) expect(getHeader(options?.headers, 'x-facturapi-client')).toBe('MCP') + expect(getHeader(options?.headers, 'Accept-Language')).toBe('en-US') expect(getHeader(options?.headers, 'Content-Type')).toBe( 'application/json', ) @@ -308,6 +310,7 @@ describe('runtime compatibility (web simulation)', () => { const client = new Facturapi('sk_test_123', { headers: { 'x-facturapi-client': 'MCP', + 'Accept-Language': 'en-US', 'content-type': 'text/plain', }, }) @@ -322,6 +325,7 @@ describe('runtime compatibility (web simulation)', () => { 'Bearer sk_test_123', ) expect(getHeader(options?.headers, 'x-facturapi-client')).toBe('MCP') + expect(getHeader(options?.headers, 'Accept-Language')).toBe('en-US') return new Response( JSON.stringify({