Update Invoice
Update an existing invoice. Only provided fields will be updated.
PUT
https://api.zenpayz.com/merchant/api/v1/invoices/:invoiceIdBearer · API key
Request
Headers
| Header | Description |
|---|---|
Authorization REQUIRED | Bearer {api_key} |
X-Signature REQUIRED | HMAC-SHA256 signature |
X-Timestamp REQUIRED | ISO 8601 timestamp |
X-Secret-Salt REQUIRED | Secret salt for HMAC validation |
Content-Type REQUIRED | application/json |
Path Parameters
| Parameter | Type | Description |
|---|---|---|
invoiceId REQUIRED | string | The invoice ID (e.g. inv_a1b2c3d4e5f6g7h8) |
Body Parameters
| Parameter | Type | Description |
|---|---|---|
dueDate OPTIONAL | string | Payment due date (ISO 8601) |
taxRate OPTIONAL | number | Tax rate percentage (minimum 0) |
discountAmount OPTIONAL | number | Discount amount (minimum 0) |
notes OPTIONAL | string | Notes displayed on the invoice |
terms OPTIONAL | string | Payment terms and conditions |
lineItems OPTIONAL | array | Array of line items |
Response
Success (200 OK)
{
"success": true,
"data": {
"invoiceId": "inv_a1b2c3d4e5f6g7h8",
"invoiceNumber": "INV-2024-0001",
"customerId": "cust_a1b2c3d4e5f6g7h8",
"customerEmail": "john@example.com",
"customerName": "John Doe",
"currency": "USD",
"status": "DRAFT",
"issueDate": "2024-01-15T00:00:00.000Z",
"dueDate": "2024-03-15T00:00:00.000Z",
"subtotal": 300.00,
"taxRate": 10,
"taxAmount": 30.00,
"discountAmount": 20,
"totalAmount": 310.00,
"amountPaid": 0,
"amountDue": 310.00,
"notes": "Updated payment terms",
"terms": "Net 60",
"lineItems": [
{
"id": "li_001",
"productId": "prod_a1b2c3d4e5f6g7h8",
"description": "Pro Plan - Monthly",
"quantity": 6,
"unitPrice": 50.00,
"taxRate": 0,
"amount": 300.00,
"sortOrder": 0
}
],
"metadata": {},
"createdAt": "2024-01-15T10:30:00.000Z",
"updatedAt": "2024-01-16T14:20:00.000Z"
},
"message": "Invoice updated successfully",
"error": null,
"meta": {
"request_id": "req_xxxxx",
"timestamp": "2024-01-16T14:20:00.000Z",
"processing_time_ms": 50,
"api_version": "v1",
"endpoint": "PUT /invoices/:invoiceId",
"user_type": "merchant"
}
}
Error Responses
| Code | HTTP | Message |
|---|---|---|
| VALIDATION_ERROR | 400 | Invalid request parameters |
| UNAUTHORIZED | 401 | Invalid API key |
| INVOICE_NOT_FOUND | 404 | Invoice does not exist |
| INVOICE_NOT_EDITABLE | 409 | Invoice cannot be edited in its current status |
Examples
- cURL
- JavaScript
- SDK
curl -X PUT https://api.zenpayz.com/merchant/api/v1/invoices/inv_a1b2c3d4e5f6g7h8 \
-H "Authorization: Bearer zp_test_xxxxx" \
-H "X-Timestamp: 2024-01-16T14:20:00.000Z" \
-H "X-Signature: a1b2c3d4e5f6..." \
-H "X-Secret-Salt: your_secret_salt" \
-H "Content-Type: application/json" \
-d '{
"dueDate": "2024-03-15T00:00:00.000Z",
"discountAmount": 20,
"notes": "Updated payment terms",
"terms": "Net 60",
"lineItems": [
{
"productId": "prod_a1b2c3d4e5f6g7h8",
"description": "Pro Plan - Monthly",
"quantity": 6,
"unitPrice": 50.00
}
]
}'
const response = await fetch('https://api.zenpayz.com/merchant/api/v1/invoices/inv_a1b2c3d4e5f6g7h8', {
method: 'PUT',
headers: {
'Authorization': `Bearer ${apiKey}`,
'X-Timestamp': timestamp,
'X-Signature': signature,
'X-Secret-Salt': secretSalt,
'Content-Type': 'application/json',
},
body: JSON.stringify({
dueDate: '2024-03-15T00:00:00.000Z',
discountAmount: 20,
notes: 'Updated payment terms',
terms: 'Net 60',
lineItems: [
{
productId: 'prod_a1b2c3d4e5f6g7h8',
description: 'Pro Plan - Monthly',
quantity: 6,
unitPrice: 50.00,
},
],
}),
});
const result = await response.json();
console.log(result.data.totalAmount); // 310.00
const invoice = await zenpays.invoices.update('inv_a1b2c3d4e5f6g7h8', {
dueDate: '2024-03-15T00:00:00.000Z',
discountAmount: 20,
notes: 'Updated payment terms',
terms: 'Net 60',
lineItems: [
{
productId: 'prod_a1b2c3d4e5f6g7h8',
description: 'Pro Plan - Monthly',
quantity: 6,
unitPrice: 50.00,
},
],
});
console.log(invoice.totalAmount); // 310.00