Verify Subscription
Description
Before a registered webhook URL can receive any event, it must be verified, meaning confirmed to be available and handling events. To verify the added subscription, use the verify subscription endpoint specifying the subscription id that was returned in the response when adding the subscription. The verification endpoint will raise a ping event to the registered webhook URL. For details about the event, see the section on event details below.
Endpoint
Method: POST
/api/v2/callbacks/subscriptions/{subscriptionid}/verify
Sample Code
- C#
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("http://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
Parameter | Description | Type |
---|---|---|
subscriptionId required | Subscription Id of the Merchant for Callback. | GUID |
Response Code
Code | HttpStatusCode | Description |
---|---|---|
200 | Ok | Webhook URL valid and verified. |
400 | BadRequest | Webhook URL is invalid. |
403 | Forbidden | Merchant is not authorized to retrieve information. |
401 | Unauthorized | Merchant is not authorized to retrieve information. |