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
- C#
- Request
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);
Update Subscription Request
{
"CallbackUri": "https://webhook.site/c7978137-8d45-472a-b0f4-d99d901d1e5f",
"Events": [
"CheckoutOrder.Created"
]
}
Response Code
Code | HttpStatusCode | Description |
---|---|---|
200 | Ok | Update Subscription successful. |
400 | BadRequest | Invalid request parameters. |
403 | Forbidden | Merchant is not authorized to retrieve information. |
401 | Unauthorized | Merchant is not authorized to retrieve information. |