<!-- ZenPays documentation · https://docs.zenpayz.com/docs/rest-api/endpoints/billing/payment-links/linked-invoices -->

# Linked Invoices

Retrieve all invoices linked to a specific payment link.

<EndpointHeader verb="GET" path="/merchant/api/v1/payment-links/:linkId/invoices" />

## Request

### Headers

<ParamTable
  label="Header"
  rows={[
    { name: "Authorization", required: true, desc: "`Bearer {api_key}`" },
    { name: "X-Signature", required: true, desc: "HMAC-SHA256 signature" },
    { name: "X-Timestamp", required: true, desc: "ISO 8601 timestamp" },
    { name: "X-Secret-Salt", required: true, desc: "Secret salt for HMAC validation" },
    { name: "Content-Type", required: true, desc: "`application/json`" },
  ]}
/>

### Path Parameters

<ParamTable
  rows={[
    { name: "linkId", type: "string", required: true, desc: "The payment link ID (e.g. `pl_a1b2c3d4e5f6g7h8`)" },
  ]}
/>

## Response

### Success (200 OK)

```json
{
  "success": true,
  "data": [
    {
      "invoiceId": "inv_a1b2c3d4e5f6g7h8",
      "invoiceNumber": "INV-2024-0001",
      "customerId": "cust_a1b2c3d4e5f6g7h8",
      "customerEmail": "john@example.com",
      "customerName": "John Doe",
      "currency": "USD",
      "status": "SENT",
      "totalAmount": 275.00,
      "amountPaid": 0,
      "amountDue": 275.00,
      "issueDate": "2024-01-15T00:00:00.000Z",
      "dueDate": "2024-02-15T00:00:00.000Z",
      "createdAt": "2024-01-15T10:30:00.000Z"
    },
    {
      "invoiceId": "inv_c3d4e5f6g7h8i9j0",
      "invoiceNumber": "INV-2024-0002",
      "customerId": "cust_a1b2c3d4e5f6g7h8",
      "customerEmail": "john@example.com",
      "customerName": "John Doe",
      "currency": "USD",
      "status": "DRAFT",
      "totalAmount": 150.00,
      "amountPaid": 0,
      "amountDue": 150.00,
      "issueDate": "2024-01-20T00:00:00.000Z",
      "dueDate": "2024-02-20T00:00:00.000Z",
      "createdAt": "2024-01-20T10:30:00.000Z"
    }
  ],
  "message": "Linked invoices retrieved successfully",
  "error": null,
  "meta": {
    "request_id": "req_xxxxx",
    "timestamp": "2024-01-15T10:30:00.000Z",
    "processing_time_ms": 30,
    "api_version": "v1",
    "endpoint": "GET /payment-links/:linkId/invoices",
    "user_type": "merchant"
  }
}
```

### Error Responses

<ErrorTable
  rows={[
    { code: "UNAUTHORIZED", status: "401", message: "Invalid API key" },
    { code: "PAYMENT_LINK_NOT_FOUND", status: "404", message: "Payment link does not exist" },
  ]}
/>

<CodeRail>

## Examples

<Tabs groupId="language">
  <TabItem value="curl" label="cURL" default>

```bash
curl -X GET https://api.zenpayz.com/merchant/api/v1/payment-links/pl_a1b2c3d4e5f6g7h8/invoices \
  -H "Authorization: Bearer zp_test_xxxxx" \
  -H "X-Timestamp: 2024-01-15T10:30:00.000Z" \
  -H "X-Signature: a1b2c3d4e5f6..." \
  -H "X-Secret-Salt: your_secret_salt" \
  -H "Content-Type: application/json"
```

  </TabItem>
  <TabItem value="javascript" label="JavaScript">

```javascript
const response = await fetch('https://api.zenpayz.com/merchant/api/v1/payment-links/pl_a1b2c3d4e5f6g7h8/invoices', {
  method: 'GET',
  headers: {
    'Authorization': `Bearer ${apiKey}`,
    'X-Timestamp': timestamp,
    'X-Signature': signature,
    'X-Secret-Salt': secretSalt,
    'Content-Type': 'application/json',
  },
});

const result = await response.json();
console.log(result.data); // Array of linked invoices
console.log(result.data.length); // 2
```

  </TabItem>
  <TabItem value="sdk" label="SDK">

```javascript
const invoices = await zenpays.paymentLinks.listInvoices('pl_a1b2c3d4e5f6g7h8');

console.log(invoices); // Array of linked invoices
console.log(invoices.length); // 2
```

  </TabItem>
</Tabs>

</CodeRail>

## Related Endpoints

- [Get Payment Link](/docs/rest-api/endpoints/billing/payment-links/get-payment-link)
- [Create Payment Link](/docs/rest-api/endpoints/billing/payment-links/create-payment-link)
- [Update Payment Link](/docs/rest-api/endpoints/billing/payment-links/update-payment-link)
- [Get Invoice](/docs/rest-api/endpoints/billing/invoices/get-invoice)
