Skip to main content

Verify Webhook

A webhook may need to be verified before it receives events. If it does, the Create Webhook response has "verified": false, and Moyasar sends a webhook_verification event to the webhook's URL with a 6-digit code in data.verification_code:

Verification event
{
"id": "7a1f0e3c-5d2b-4c8e-9f61-2b8d4f0a9c13",
"type": "webhook_verification",
"created_at": "2024-01-15T10:05:12Z",
"secret_token": "123",
"account_name": "My Store",
"data": {
"webhook_id": "c4bc247d-5288-4673-9b40-39c082ac7fbb",
"verification_code": "482913"
}
}

This event is sent once and isn't retried. If your server didn't receive it, request a new code with Resend Verification Code.

Send the code back to verify the webhook. Until it's verified, the webhook receives no events, and they aren't delivered later either.

Curl Request
curl -X POST https://api.moyasar.com/v1/webhooks/:id/verify \
-u sk_yourkey: \
-H 'Content-Type: application/json' \
-d '{ "code": "482913" }'

The code is valid for 30 minutes. After 5 wrong codes, request a new one with Resend Verification Code.

Responses​

Success Response
{
"id": "c4bc247d-5288-4673-9b40-39c082ac7fbb",
"http_method": "post",
"url": "https://example.com/updatepayments",
"created_at": "2024-01-15T10:05:11.097Z",
"events": ["payment_paid", "payment_failed"],
"verified": true,
"verified_at": "2024-01-15T10:06:40.512Z"
}
Error Response
{
"type": "webhook_verification_invalid",
"message": "Verification code is incorrect",
"errors": null
}
Error typeMeaning
webhook_verification_invalidThe code is wrong.
webhook_verification_expiredThe code is older than 30 minutes. Request a new one.
webhook_verification_locked5 wrong codes were sent. Request a new one.

Resend Verification Code​

Sends a new code to the webhook's URL. The previous code stops working. You can request a new code once a minute.

Curl Request
curl -X POST https://api.moyasar.com/v1/webhooks/:id/resend_verification -u sk_yourkey:
Success Response
{
"message": "Verification code was sent"
}
Error typeMeaning
webhook_verification_throttledA code was sent less than a minute ago.
webhook_already_verifiedThe webhook is already verified.