Create a new webhook subscription
client.WebhookSubscriptions.New(ctx, body) (*WebhookSubscriptionNewResponse, error)
POST/v3/webhook-subscriptions
Create a new webhook subscription to receive events at a target URL. Upon creation, a signing secret is generated for verifying webhook authenticity. Store this secret securely โ it cannot be retrieved later.
Phone Number Filtering:
- Optionally specify
phone_numbersto only receive events for specific lines - If omitted, events from all phone numbers are delivered (default behavior)
- Use multiple subscriptions with different
phone_numbersto route different lines to different endpoints - Each
target_urlcan only be used once per account. To route different lines to different destinations, use a unique URL per subscription (e.g., append a query parameter:https://example.com/webhook?line=1)
Webhook Delivery:
- Events are sent via HTTP POST to the target URL
- Each request includes
X-Webhook-SignatureandX-Webhook-Timestampheaders - Signature is HMAC-SHA256 over
{timestamp}.{payload}โ see Webhook Events for verification details - Failed deliveries (5xx, 429, network errors) are retried up to 10 times over ~25 minutes with exponential backoff
- Client errors (4xx except 429) are not retried
Create a new webhook subscription
package main
import (
"context"
"fmt"
"github.com/linq-team/linq-go"
"github.com/linq-team/linq-go/option"
)
func main() {
client := linqgo.NewClient(
option.WithAPIKey("My API Key"),
)
webhookSubscription, err := client.WebhookSubscriptions.New(context.TODO(), linqgo.WebhookSubscriptionNewParams{
SubscribedEvents: []linqgo.WebhookEventType{linqgo.WebhookEventTypeMessageSent, linqgo.WebhookEventTypeMessageDelivered, linqgo.WebhookEventTypeMessageRead},
TargetURL: "https://webhooks.example.com/linq/events",
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", webhookSubscription.ID)
}
{
"id": "b2c3d4e5-f6a7-8901-bcde-f23456789012",
"created_at": "2024-01-15T10:30:00Z",
"is_active": true,
"signing_secret": "whsec_abc123def456",
"subscribed_events": [
"message.sent",
"message.delivered",
"message.read"
],
"target_url": "https://webhooks.example.com/linq/events",
"updated_at": "2024-01-15T10:30:00Z",
"phone_numbers": [
"string"
]
}{
"error": {
"status": 400,
"code": 1002,
"message": "Phone number must be in E.164 format"
},
"success": false
}{
"error": {
"status": 401,
"code": 2004,
"message": "Unauthorized - missing or invalid authentication token"
},
"success": false
}{
"error": {
"status": 500,
"code": 3006,
"message": "Internal server error"
},
"success": false
}Returns Examples
{
"id": "b2c3d4e5-f6a7-8901-bcde-f23456789012",
"created_at": "2024-01-15T10:30:00Z",
"is_active": true,
"signing_secret": "whsec_abc123def456",
"subscribed_events": [
"message.sent",
"message.delivered",
"message.read"
],
"target_url": "https://webhooks.example.com/linq/events",
"updated_at": "2024-01-15T10:30:00Z",
"phone_numbers": [
"string"
]
}{
"error": {
"status": 400,
"code": 1002,
"message": "Phone number must be in E.164 format"
},
"success": false
}{
"error": {
"status": 401,
"code": 2004,
"message": "Unauthorized - missing or invalid authentication token"
},
"success": false
}{
"error": {
"status": 500,
"code": 3006,
"message": "Internal server error"
},
"success": false
}