PHP Example
Use this when you want to send the vendor-number callback from PHP. Construct with API key and base URL (e.g. from env), then call assignVendorNumber($eventId, $vendorNumber). Returns true on 204.
<?php
class B1LinkWebhookClient {
private $apiKey;
private $baseUrl;
public function __construct($apiKey, $baseUrl) {
$this->apiKey = $apiKey;
$this->baseUrl = $baseUrl;
}
public function assignVendorNumber($eventId, $vendorNumber) {
// Create request payload
$payload = [
'Id' => $eventId,
'ErpVendorNumber' => $vendorNumber
];
// Serialize to JSON (compact format, no whitespace)
$jsonPayload = json_encode($payload, JSON_UNESCAPED_SLASHES);
// Generate signature
$signature = $this->generateSignature($jsonPayload);
// Create request URL
$url = $this->baseUrl . '/api/onboarding-request-erp-events/assign-erp-vendor-number-event';
// Set headers
$headers = [
'Content-Type: application/json',
'X-B1LINK-Signature: ' . $signature
];
// Initialize cURL
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonPayload);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute request
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $httpCode === 204;
}
private function generateSignature($payload) {
// Compute HMAC-SHA256
$hash = hash_hmac('sha256', $payload, $this->apiKey, true);
// Base64 encode
return base64_encode($hash);
}
}
// Usage
$client = new B1LinkWebhookClient(
'your-api-key-here',
'{baseUrl}'
);
$success = $client->assignVendorNumber(
'550e8400-e29b-41d4-a716-446655440000',
'VENDOR-12345'
);
Key Points
- Uses
json_encode()withJSON_UNESCAPED_SLASHESfor compact JSON hash_hmac()with'sha256'algorithm for signature generationbase64_encode()for Base64 encoding- cURL for HTTP requests
Error Handling
You may want to add error handling:
public function assignVendorNumber($eventId, $vendorNumber) {
// ... existing code ...
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonPayload);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); // Important for production
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
curl_close($ch);
if ($error) {
error_log("cURL error: " . $error);
return false;
}
return $httpCode === 204;
}
Requirements
- PHP 7.0 or higher
- cURL extension enabled
Next step
- Troubleshooting — If you get 401 or 404.