Create Vendor Referral
Create a new referral record linking a merchant to a vendor for commission tracking.
POST
https://api.zenpayz.com/merchant/api/v1/vendors/:id/referralsBearer · 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 |
|---|---|---|
id REQUIRED | string | Vendor ID (e.g., vnd_a1b2c3d4e5f6g7h8) |
Body Parameters
| Parameter | Type | Description |
|---|---|---|
merchantId REQUIRED | string | ID of the referred merchant |
referralCode OPTIONAL | string | Custom referral tracking code |
referralSource OPTIONAL | string | Source of the referral (e.g., website, partner_portal, event) |
commissionRate OPTIONAL | number | Override commission rate for this referral (0-100) |
environment OPTIONAL | string | Environment identifier |
notes OPTIONAL | string | Additional notes about the referral |
Response
Success (201 Created)
{
"success": true,
"data": {
"referralId": "ref_j0k1l2m3n4o5p6q7",
"vendorId": "vnd_a1b2c3d4e5f6g7h8",
"merchantId": "mer_m3n4o5p6q7r8s9t0",
"referralCode": "ACME-2024-003",
"referralSource": "partner_portal",
"status": "active",
"commissionRate": 15.0,
"totalTransactions": 0,
"totalRevenue": 0,
"totalCommission": 0,
"environment": "production",
"notes": "Enterprise client referred at FinTech Summit 2024",
"createdAt": "2024-03-21T11:00:00.000Z",
"updatedAt": "2024-03-21T11:00:00.000Z"
},
"message": "Vendor referral created successfully",
"error": null,
"meta": {
"request_id": "req_xxxxx",
"timestamp": "2024-03-21T11:00:00.000Z",
"processing_time_ms": 130,
"api_version": "v1",
"endpoint": "POST /vendors/:id/referrals",
"user_type": "merchant"
}
}
Error Responses
| Code | HTTP | Message |
|---|---|---|
| VALIDATION_ERROR | 400 | Invalid request parameters |
| UNAUTHORIZED | 401 | Invalid API key |
| VENDOR_NOT_FOUND | 404 | Vendor with specified ID does not exist |
| MERCHANT_NOT_FOUND | 404 | Merchant with specified ID does not exist |
| DUPLICATE_REFERRAL | 409 | Referral for this merchant already exists under this vendor |
Examples
- cURL
- JavaScript
- SDK
curl -X POST https://api.zenpayz.com/merchant/api/v1/vendors/vnd_a1b2c3d4e5f6g7h8/referrals \
-H "Authorization: Bearer zp_test_xxxxx" \
-H "X-Timestamp: 2024-03-21T11:00:00.000Z" \
-H "X-Signature: a1b2c3d4e5f6..." \
-H "X-Secret-Salt: your_secret_salt" \
-H "Content-Type: application/json" \
-d '{
"merchantId": "mer_m3n4o5p6q7r8s9t0",
"referralCode": "ACME-2024-003",
"referralSource": "partner_portal",
"commissionRate": 15.0,
"environment": "production",
"notes": "Enterprise client referred at FinTech Summit 2024"
}'
const response = await fetch('https://api.zenpayz.com/merchant/api/v1/vendors/vnd_a1b2c3d4e5f6g7h8/referrals', {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'X-Timestamp': timestamp,
'X-Signature': signature,
'X-Secret-Salt': secretSalt,
'Content-Type': 'application/json',
},
body: JSON.stringify({
merchantId: 'mer_m3n4o5p6q7r8s9t0',
referralCode: 'ACME-2024-003',
referralSource: 'partner_portal',
commissionRate: 15.0,
environment: 'production',
notes: 'Enterprise client referred at FinTech Summit 2024',
}),
});
const result = await response.json();
console.log(result.data.referralId); // ref_j0k1l2m3n4o5p6q7
const referral = await zenpays.vendors.createReferral('vnd_a1b2c3d4e5f6g7h8', {
merchantId: 'mer_m3n4o5p6q7r8s9t0',
referralCode: 'ACME-2024-003',
referralSource: 'partner_portal',
commissionRate: 15.0,
environment: 'production',
notes: 'Enterprise client referred at FinTech Summit 2024',
});
console.log(referral.referralId); // ref_j0k1l2m3n4o5p6q7