Skip to main content

Update Subscription

Description

Updates the subscription by replacing the current subscription with the data provided in the request. A client can use this endpoint to replace the webhook URL or the events subscribed to, note that if the URL is updated it needs to be verified again before any events can be received.

Endpoint

Method: PUT
/api/v2/callbacks/subscriptions/{subscriptionId}

Sample Code

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

internal static class UpdateSubscription
{
internal static async Task UpdateSubscriptionAsync(string subscriptionId)
{
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 = string.Format("v2/callbacks/subscriptions/{0}", subscriptionId);

var subscriptionRequest = new UpdateSubscriptionRequest("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.PutAsync(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 UpdateSubscriptionRequest(string CallbackUri, string[] Events);

Response Code

CodeHttpStatusCodeDescription
200OkUpdate Subscription successful.
400BadRequestInvalid request parameters.
403ForbiddenMerchant is not authorized to retrieve information.
401UnauthorizedMerchant is not authorized to retrieve information.