Skip to main content

Verify Subscription

Description

Before a webhook subscription can receive events, its registered URL must be verified. To verify a subscription, call the verify subscription endpoint with the subscription ID returned when the subscription was created. This sends a ping event to the webhook URL, confirming that it is reachable and can process events. See Event Details below for more information.

Endpoint

Method: POST
/api/v2/callbacks/subscriptions/{subscriptionid}/verify

Sample Code

Verify Subscription Example
using Microsoft.Extensions.DependencyInjection;
using System.Text.Json;
using System.Text;

internal static class AddSubscription
{
internal static async Task AddSubscriptionAsync()
{
var services = new ServiceCollection();
services.AddHttpClient("MyApiClient", client =>
{
client.BaseAddress = new Uri("https://paymentadminapistage.svea.com/api/");
});

var serviceProvider = services.BuildServiceProvider();
var httpClientFactory = serviceProvider.GetRequiredService<IHttpClientFactory>();
var httpClient = httpClientFactory.CreateClient("MyApiClient");

var apiUrl = "v2/callbacks/subscriptions";

var subscriptionRequest = new SubscriptionRequest("webhookurl", new string[] { "CheckoutOrder.Created" });
var jsonString = JsonSerializer.Serialize(subscriptionRequest);
var subscriptionRequestJson = new StringContent(
jsonString,
Encoding.UTF8,
"application/json");

// Add authorization header
Authentication.CreateAuthenticationToken(out string token, out string timestamp, jsonString);
httpClient.DefaultRequestHeaders.Add("Authorization", token);
httpClient.DefaultRequestHeaders.Add("Timestamp", timestamp);

try
{
HttpResponseMessage response = await httpClient.PostAsync(apiUrl, subscriptionRequestJson);

// Check if the request was successful
if (response.IsSuccessStatusCode)
{
string responseData = await response.Content.ReadAsStringAsync();
Console.WriteLine("Response: " + responseData);
}
else
{
Console.WriteLine("Failed to retrieve data. Status code: " + response.StatusCode);
}
}
catch (HttpRequestException ex)
{
Console.WriteLine("Error: " + ex.Message);
}
}
}

internal record SubscriptionRequest(string CallbackUri, string[] Events);

Payload parameters

ParameterDescriptionType

subscriptionID required

A unique identifier for the subscription.GUID

Response Code

CodeHttpStatusCodeDescription
200OkWebhook URL valid and verified.
400BadRequestWebhook URL is invalid.
403ForbiddenMerchant does not have permission to access this resource.
401UnauthorizedMerchant is not authorized to retrieve information.