> 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.

# Download e-invoices (XML or STAR JSON)

POST https://api.staple.io/v2/einvoice/{countryCode}/download
Content-Type: application/json

Download one or more e-invoices in the format you choose:

| `docType` | `data` returned |
|---|---|
| `XML` | The Peppol PINT-SG UBL XML (wrapped in its SBDH envelope), as a string — the XML that was sent, or that was received over Peppol. |
| `STAR_JSON` | The e-invoice as a STAR JSON object — the same format used to submit e-invoices. For received e-invoices it is mapped from the received XML. |

**Supported countries:** `sg` (Singapore). The country code is case-insensitive.

**Limit:** 1–100 `docIds` per request. Duplicate ids are returned once.

Each document is returned with its current `status`, whatever state it is in. Documents that cannot be returned are listed in `unresolved` with a reason, and the rest of the request still succeeds:

| `error` | Meaning |
|---|---|
| `INVALID_DOCUMENT_ID` | The id is not a positive integer. |
| `DOCUMENT_NOT_FOUND` | No document with this id exists in your organisation. |
| `NOT_AN_EINVOICE` | The document exists but is not an e-invoice for this country. |
| `XML_NOT_AVAILABLE` | The document has no XML (`docType: XML`). |
| `STAR_JSON_NOT_AVAILABLE` | The document has no STAR JSON (`docType: STAR_JSON`). |

**Access is all-or-nothing:** if any requested document belongs to a queue you are not assigned to, nothing is returned and the call fails with **403** listing those `docIds`.

Reference: https://docs.staple.ai/api-reference/v2/e-invoice/download

## Authentication

- `x-api-key` header (required) — API key issued by Staple.
- `Authorization` header (bearer token, required) — JWT obtained from the login endpoint.

## Request

### Path parameters

- `countryCode` (enum, required) — Country of the e-invoices. Supported: `sg`.
  - Allowed values: `sg`

### Body (application/json)

This endpoint expects an object.

- `docType` (enum, required) — Format to return. Case-sensitive.
  - Allowed values: `XML`, `STAR_JSON`
- `docIds` (list of integer, required) — Internal document IDs (1–100). Numeric strings are also accepted.

## Response

### 200

The documents that could be returned, plus `unresolved` for the rest.

- `documents` (list of V2EinvoiceCountryCodeDownloadPostResponsesContentApplicationJsonSchemaDocumentsItems, optional)
- `unresolved` (list of V2EinvoiceCountryCodeDownloadPostResponsesContentApplicationJsonSchemaUnresolvedItems, optional)

## Types

### V2EinvoiceCountryCodeDownloadPostResponsesContentApplicationJsonSchemaDocumentsItems

- `docId` (integer, optional)
- `status` (string, optional, nullable) — Current document status, e.g. `RECEIVED`, `PROCESSING`.
- `docType` (enum, optional)
  - Allowed values: `XML`, `STAR_JSON`
- `data` (V2EinvoiceCountryCodeDownloadPostResponsesContentApplicationJsonSchemaDocumentsItemsData, optional) — XML string (`XML`) or STAR JSON object (`STAR_JSON`).

### V2EinvoiceCountryCodeDownloadPostResponsesContentApplicationJsonSchemaUnresolvedItems

- `docId` (V2EinvoiceCountryCodeDownloadPostResponsesContentApplicationJsonSchemaUnresolvedItemsDocId, optional) — The id as sent.
- `error` (enum, optional)
  - Allowed values: `INVALID_DOCUMENT_ID`, `DOCUMENT_NOT_FOUND`, `NOT_AN_EINVOICE`, `XML_NOT_AVAILABLE`, `STAR_JSON_NOT_AVAILABLE`

### V2EinvoiceCountryCodeDownloadPostResponsesContentApplicationJsonSchemaDocumentsItemsData

XML string (`XML`) or STAR JSON object (`STAR_JSON`).

### V2EinvoiceCountryCodeDownloadPostResponsesContentApplicationJsonSchemaUnresolvedItemsDocId

The id as sent.

## Examples

### STAR JSON

**Response**

```json
{
  "documents": [
    {
      "docId": 245210,
      "status": "RECEIVED",
      "docType": "STAR_JSON",
      "data": {
        "Buyer": {
          "Address": {
            "City Name": "Singapore",
            "Country Code": "SG",
            "Postal Zone": "018982",
            "Street Name": "3 Marina Boulevard"
          },
          "Email": "ap@globex-trading.example",
          "Name": "Globex Trading Pte Ltd",
          "Peppol Endpoint ID": "SGUEN202098765B",
          "Peppol Scheme ID": "0195",
          "Registration Number": "202098765B",
          "Tax ID": "M90098765B"
        },
        "Buyer Reference": "BR-2026-0087",
        "Currency": "SGD",
        "Document Type": "Invoice",
        "Invoice Date": "2026-08-20",
        "Invoice Number": "INV-2026-0815",
        "Line Items": [
          {
            "Description": "Apples",
            "Line Amount": 900,
            "Line ID": "1",
            "Quantity": 10,
            "Tax Breakdown": [
              {
                "Tax Amount": 81,
                "Tax Category Code": "SR",
                "Tax Rate": 9,
                "Tax Scheme": "GST",
                "Taxable Amount": 900
              }
            ],
            "Unit Amount": 90,
            "Unit of Measure": "KGM"
          }
        ],
        "PO Number": "PO-450235963",
        "Payment": {
          "Due Date": "2026-09-19",
          "Means Text": "GIRO",
          "Terms": "Net 30 days"
        },
        "Period": {
          "End Date": "2026-08-31",
          "Start Date": "2026-08-01"
        },
        "Seller": {
          "Address": {
            "City Name": "Singapore",
            "Country Code": "SG",
            "Postal Zone": "018989",
            "Street Name": "11 Marina Blvd"
          },
          "Email": "billing@acme-supplies.example",
          "Name": "Acme Supplies Pte Ltd",
          "Peppol Endpoint ID": "SGUEN201912345A",
          "Peppol Scheme ID": "0195",
          "Registration Number": "201912345A",
          "Tax ID": "M90012345A"
        },
        "Tax Point Date": "2026-08-20",
        "Totals": {
          "Allowance Total": 0,
          "Charge Total": 0,
          "Prepaid Amount": 0,
          "Rounding Amount": 0,
          "Subtotal": 900,
          "Sum of Line Amounts": 900,
          "Tax Total": 81,
          "Total": 981,
          "Total incl Tax": 981
        },
        "Transaction Type": "Purchases",
        "UUID": "6f1c2a9e-3b7d-4e52-9a10-2c8d4f7b1e33"
      }
    }
  ],
  "unresolved": [
    {
      "docId": 245211,
      "error": "DOCUMENT_NOT_FOUND"
    }
  ]
}
```

**SDK Code**

```python STAR JSON
import requests

url = "https://api.staple.io/v2/einvoice/sg/download"

headers = {"x-api-key": "<apiKey>"}

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

print(response.json())
```

```javascript STAR JSON
const url = 'https://api.staple.io/v2/einvoice/sg/download';
const options = {method: 'POST', headers: {'x-api-key': '<apiKey>'}};

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

```go STAR JSON
package main

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

func main() {

	url := "https://api.staple.io/v2/einvoice/sg/download"

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

	req.Header.Add("x-api-key", "<apiKey>")

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

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

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

}
```

```ruby STAR JSON
require 'uri'
require 'net/http'

url = URI("https://api.staple.io/v2/einvoice/sg/download")

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

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<apiKey>'

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

```java STAR JSON
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.staple.io/v2/einvoice/sg/download")
  .header("x-api-key", "<apiKey>")
  .asString();
```

```php STAR JSON
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.staple.io/v2/einvoice/sg/download', [
  'headers' => [
    'x-api-key' => '<apiKey>',
  ],
]);

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

```csharp STAR JSON
using RestSharp;

var client = new RestClient("https://api.staple.io/v2/einvoice/sg/download");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift STAR JSON
import Foundation

let headers = ["x-api-key": "<apiKey>"]

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

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()
```

### XML

**Response**

```json
{
  "documents": [
    {
      "docId": 245210,
      "status": "RECEIVED",
      "docType": "XML",
      "data": "<?xml version=\"1.0\" standalone=\"yes\"?>\n<StandardBusinessDocument xmlns=\"http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader\">\n  <StandardBusinessDocumentHeader>\n    <HeaderVersion>1.0</HeaderVersion>\n    <Sender><Identifier Authority=\"iso6523-actorid-upis\">0195:SGUEN201912345A</Identifier></Sender>\n    <Receiver><Identifier Authority=\"iso6523-actorid-upis\">0195:SGUEN202098765B</Identifier></Receiver>\n    <DocumentIdentification>\n      <Standard>urn:oasis:names:specification:ubl:schema:xsd:Invoice-2</Standard>\n      <TypeVersion>2.1</TypeVersion>\n      <InstanceIdentifier>0d4e7a52-91c3-4b8e-a6f2-5e1b9c7d3a20</InstanceIdentifier>\n      <Type>Invoice</Type>\n      <CreationDateAndTime>2026-08-20T00:00:00Z</CreationDateAndTime>\n    </DocumentIdentification>\n    ...\n  </StandardBusinessDocumentHeader>\n  <Invoice xmlns=\"urn:oasis:names:specification:ubl:schema:xsd:Invoice-2\" ...>\n    <cbc:CustomizationID>urn:peppol:pint:billing-1@sg-1</cbc:CustomizationID>\n    <cbc:ID>INV-2026-0815</cbc:ID>\n    <cbc:UUID>6f1c2a9e-3b7d-4e52-9a10-2c8d4f7b1e33</cbc:UUID>\n    ...\n  </Invoice>\n</StandardBusinessDocument>"
    }
  ],
  "unresolved": []
}
```

**SDK Code**

```python XML
import requests

url = "https://api.staple.io/v2/einvoice/sg/download"

headers = {"x-api-key": "<apiKey>"}

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

print(response.json())
```

```javascript XML
const url = 'https://api.staple.io/v2/einvoice/sg/download';
const options = {method: 'POST', headers: {'x-api-key': '<apiKey>'}};

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

```go XML
package main

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

func main() {

	url := "https://api.staple.io/v2/einvoice/sg/download"

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

	req.Header.Add("x-api-key", "<apiKey>")

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

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

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

}
```

```ruby XML
require 'uri'
require 'net/http'

url = URI("https://api.staple.io/v2/einvoice/sg/download")

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

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<apiKey>'

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

```java XML
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.staple.io/v2/einvoice/sg/download")
  .header("x-api-key", "<apiKey>")
  .asString();
```

```php XML
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.staple.io/v2/einvoice/sg/download', [
  'headers' => [
    'x-api-key' => '<apiKey>',
  ],
]);

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

```csharp XML
using RestSharp;

var client = new RestClient("https://api.staple.io/v2/einvoice/sg/download");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift XML
import Foundation

let headers = ["x-api-key": "<apiKey>"]

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

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()
```

### Download as STAR JSON

**Request**

```json
{
  "docType": "STAR_JSON",
  "docIds": [
    245210,
    245211
  ]
}
```

**Response**

```json
{
  "documents": [
    {
      "docId": 245210,
      "status": "RECEIVED",
      "docType": "STAR_JSON",
      "data": {
        "Buyer": {
          "Address": {
            "City Name": "Singapore",
            "Country Code": "SG",
            "Postal Zone": "018982",
            "Street Name": "3 Marina Boulevard"
          },
          "Email": "ap@globex-trading.example",
          "Name": "Globex Trading Pte Ltd",
          "Peppol Endpoint ID": "SGUEN202098765B",
          "Peppol Scheme ID": "0195",
          "Registration Number": "202098765B",
          "Tax ID": "M90098765B"
        },
        "Buyer Reference": "BR-2026-0087",
        "Currency": "SGD",
        "Document Type": "Invoice",
        "Invoice Date": "2026-08-20",
        "Invoice Number": "INV-2026-0815",
        "Line Items": [
          {
            "Description": "Apples",
            "Line Amount": 900,
            "Line ID": "1",
            "Quantity": 10,
            "Tax Breakdown": [
              {
                "Tax Amount": 81,
                "Tax Category Code": "SR",
                "Tax Rate": 9,
                "Tax Scheme": "GST",
                "Taxable Amount": 900
              }
            ],
            "Unit Amount": 90,
            "Unit of Measure": "KGM"
          }
        ],
        "PO Number": "PO-450235963",
        "Payment": {
          "Due Date": "2026-09-19",
          "Means Text": "GIRO",
          "Terms": "Net 30 days"
        },
        "Period": {
          "End Date": "2026-08-31",
          "Start Date": "2026-08-01"
        },
        "Seller": {
          "Address": {
            "City Name": "Singapore",
            "Country Code": "SG",
            "Postal Zone": "018989",
            "Street Name": "11 Marina Blvd"
          },
          "Email": "billing@acme-supplies.example",
          "Name": "Acme Supplies Pte Ltd",
          "Peppol Endpoint ID": "SGUEN201912345A",
          "Peppol Scheme ID": "0195",
          "Registration Number": "201912345A",
          "Tax ID": "M90012345A"
        },
        "Tax Point Date": "2026-08-20",
        "Totals": {
          "Allowance Total": 0,
          "Charge Total": 0,
          "Prepaid Amount": 0,
          "Rounding Amount": 0,
          "Subtotal": 900,
          "Sum of Line Amounts": 900,
          "Tax Total": 81,
          "Total": 981,
          "Total incl Tax": 981
        },
        "Transaction Type": "Purchases",
        "UUID": "6f1c2a9e-3b7d-4e52-9a10-2c8d4f7b1e33"
      }
    }
  ],
  "unresolved": [
    {
      "docId": 245211,
      "error": "DOCUMENT_NOT_FOUND"
    }
  ]
}
```

**SDK Code**

```python Download as STAR JSON
import requests

url = "https://api.staple.io/v2/einvoice/sg/download"

payload = {
    "docType": "STAR_JSON",
    "docIds": [245210, 245211]
}
headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Download as STAR JSON
const url = 'https://api.staple.io/v2/einvoice/sg/download';
const options = {
  method: 'POST',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"docType":"STAR_JSON","docIds":[245210,245211]}'
};

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

```go Download as STAR JSON
package main

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

func main() {

	url := "https://api.staple.io/v2/einvoice/sg/download"

	payload := strings.NewReader("{\n  \"docType\": \"STAR_JSON\",\n  \"docIds\": [\n    245210,\n    245211\n  ]\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 Download as STAR JSON
require 'uri'
require 'net/http'

url = URI("https://api.staple.io/v2/einvoice/sg/download")

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  \"docType\": \"STAR_JSON\",\n  \"docIds\": [\n    245210,\n    245211\n  ]\n}"

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

```java Download as STAR JSON
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.staple.io/v2/einvoice/sg/download")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"docType\": \"STAR_JSON\",\n  \"docIds\": [\n    245210,\n    245211\n  ]\n}")
  .asString();
```

```php Download as STAR JSON
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.staple.io/v2/einvoice/sg/download', [
  'body' => '{
  "docType": "STAR_JSON",
  "docIds": [
    245210,
    245211
  ]
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

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

```csharp Download as STAR JSON
using RestSharp;

var client = new RestClient("https://api.staple.io/v2/einvoice/sg/download");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"docType\": \"STAR_JSON\",\n  \"docIds\": [\n    245210,\n    245211\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Download as STAR JSON
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "docType": "STAR_JSON",
  "docIds": [245210, 245211]
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.staple.io/v2/einvoice/sg/download")! 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()
```

### Download as XML

**Request**

```json
{
  "docType": "XML",
  "docIds": [
    245210
  ]
}
```

**Response**

```json
{
  "documents": [
    {
      "docId": 245210,
      "status": "RECEIVED",
      "docType": "STAR_JSON",
      "data": {
        "Buyer": {
          "Address": {
            "City Name": "Singapore",
            "Country Code": "SG",
            "Postal Zone": "018982",
            "Street Name": "3 Marina Boulevard"
          },
          "Email": "ap@globex-trading.example",
          "Name": "Globex Trading Pte Ltd",
          "Peppol Endpoint ID": "SGUEN202098765B",
          "Peppol Scheme ID": "0195",
          "Registration Number": "202098765B",
          "Tax ID": "M90098765B"
        },
        "Buyer Reference": "BR-2026-0087",
        "Currency": "SGD",
        "Document Type": "Invoice",
        "Invoice Date": "2026-08-20",
        "Invoice Number": "INV-2026-0815",
        "Line Items": [
          {
            "Description": "Apples",
            "Line Amount": 900,
            "Line ID": "1",
            "Quantity": 10,
            "Tax Breakdown": [
              {
                "Tax Amount": 81,
                "Tax Category Code": "SR",
                "Tax Rate": 9,
                "Tax Scheme": "GST",
                "Taxable Amount": 900
              }
            ],
            "Unit Amount": 90,
            "Unit of Measure": "KGM"
          }
        ],
        "PO Number": "PO-450235963",
        "Payment": {
          "Due Date": "2026-09-19",
          "Means Text": "GIRO",
          "Terms": "Net 30 days"
        },
        "Period": {
          "End Date": "2026-08-31",
          "Start Date": "2026-08-01"
        },
        "Seller": {
          "Address": {
            "City Name": "Singapore",
            "Country Code": "SG",
            "Postal Zone": "018989",
            "Street Name": "11 Marina Blvd"
          },
          "Email": "billing@acme-supplies.example",
          "Name": "Acme Supplies Pte Ltd",
          "Peppol Endpoint ID": "SGUEN201912345A",
          "Peppol Scheme ID": "0195",
          "Registration Number": "201912345A",
          "Tax ID": "M90012345A"
        },
        "Tax Point Date": "2026-08-20",
        "Totals": {
          "Allowance Total": 0,
          "Charge Total": 0,
          "Prepaid Amount": 0,
          "Rounding Amount": 0,
          "Subtotal": 900,
          "Sum of Line Amounts": 900,
          "Tax Total": 81,
          "Total": 981,
          "Total incl Tax": 981
        },
        "Transaction Type": "Purchases",
        "UUID": "6f1c2a9e-3b7d-4e52-9a10-2c8d4f7b1e33"
      }
    }
  ],
  "unresolved": [
    {
      "docId": 245211,
      "error": "DOCUMENT_NOT_FOUND"
    }
  ]
}
```

**SDK Code**

```python Download as XML
import requests

url = "https://api.staple.io/v2/einvoice/sg/download"

payload = {
    "docType": "XML",
    "docIds": [245210]
}
headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Download as XML
const url = 'https://api.staple.io/v2/einvoice/sg/download';
const options = {
  method: 'POST',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"docType":"XML","docIds":[245210]}'
};

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

```go Download as XML
package main

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

func main() {

	url := "https://api.staple.io/v2/einvoice/sg/download"

	payload := strings.NewReader("{\n  \"docType\": \"XML\",\n  \"docIds\": [\n    245210\n  ]\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 Download as XML
require 'uri'
require 'net/http'

url = URI("https://api.staple.io/v2/einvoice/sg/download")

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  \"docType\": \"XML\",\n  \"docIds\": [\n    245210\n  ]\n}"

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

```java Download as XML
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.staple.io/v2/einvoice/sg/download")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"docType\": \"XML\",\n  \"docIds\": [\n    245210\n  ]\n}")
  .asString();
```

```php Download as XML
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.staple.io/v2/einvoice/sg/download', [
  'body' => '{
  "docType": "XML",
  "docIds": [
    245210
  ]
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

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

```csharp Download as XML
using RestSharp;

var client = new RestClient("https://api.staple.io/v2/einvoice/sg/download");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"docType\": \"XML\",\n  \"docIds\": [\n    245210\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Download as XML
import Foundation

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

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.staple.io/v2/einvoice/sg/download")! 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()
```