Skip to main content

Editing orders

Add order row

Description

Call this endpoint to add an order row to an order. If the new order amount is higher than the current order amount, a credit check will be made.

Endpoint

Method: POST
/api/v1/orders/{CheckoutOrderId}/rows/

Sample Code

Add Order Row Example
using Microsoft.Extensions.DependencyInjection;
using System.Text.Json;
using System.Text;

internal static class EditOrderAddRow
{
internal static async Task AddRowAsync(long checkoutOrderId)
{
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 = string.Format("v1/orders/{0}/rows/", checkoutOrderId);

//New Order Row
var addRowRequest = new AddRowRequest("A-1", "Article Name 1", 1000, 1000, 0, 0, 2500, "st");

var jsonString = JsonSerializer.Serialize(addRowRequest);
var addRowRequestJson = 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, addRowRequestJson);

// 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);
}
}
}

Prerequisite

The order must have the action CanAddOrderRow.

Request parameters

ParameterDescriptionType

CheckoutOrderID required

Checkout order ID of the specified order.Long

OrderRow required

Order RowOrderRow object

Response

ParameterDescriptionType
OrderRowIDThe row ID of the newly created order row.Long

Response Code

CodeHttpStatusCodeDescription
202AcceptedAdd row request accepted for processing.
400BadRequest
Reason:
  • Invalid request details.
  • Missing CanAddOrderRow action.
  • Order not found.
  • Any other internal error.
403ForbiddenMerchant does not have permission to access this resource.
401UnauthorizedMerchant is not authorized to retrieve information.

Add order rows

Description

Call this endpoint to add several order rows to an order. If the new order amount is higher than the current order amount, a credit check will be made.

Endpoint

Method: POST
/api/v1/orders/{CheckoutOrderId}/rows/addOrderRows/

Sample Code

Add Order Rows Example
using Microsoft.Extensions.DependencyInjection;
using System.Text.Json;
using System.Text;

internal static class EditOrderAddRows
{
internal static async Task AddRowsAsync(long checkoutOrderId)
{
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 = string.Format("v1/orders/{0}/rows/addOrderRows", checkoutOrderId);

//New Order Rows
var addRowRequest = new List<AddRowRequest>
{
new AddRowRequest("A-1", "Article Name 1", 1000, 1000, 0, 0, 2500, "st"),
new AddRowRequest("A-2", "Article Name 2", 2000, 2000, 0, 0, 2500, "st"),
};

var addRowsRequest = new AddRowsRequest(addRowRequest);

var jsonString = JsonSerializer.Serialize(addRowsRequest);
var addRowRequestJson = 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, addRowRequestJson);

// 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 AddRowRequest(string ArticleNumber, string Name, long Quantity, long UnitPrice, long DiscountPercent, long DiscountAmount, long VatPercent, string Unit);

internal record AddRowsRequest(IList<AddRowRequest> OrderRows);

Prerequisite

The order must have the action CanAddOrderRow.

Request parameters

ParameterDescriptionType

CheckoutOrderID required

Checkout order ID of the specified order.Long

OrderRows required

List of OrderRow objectList of OrderRow

Order Row

ParameterDescriptionType
ArticleNumberArticle number as a string, can contain letters and numbers.String

Name required

Article name.String

Quantity required

Quantity of the product.Long

UnitPrice required

Price of the product including VAT.Long
DiscountPercentDiscount percentage of the product. Cannot be used together with DiscountAmount.Long
DiscountAmountDiscount amount of the product. Cannot be used together with DiscountPercent.Long
VatPercentThe VAT percentage of the current product.Long
UnitThe unit type, e.g., “st”, “pc”, “kg” etc.String

Response

ParameterDescriptionType
OrderRowIDThe row IDs of the newly created OrderRows.List of Long

Response Code

CodeHttpStatusCodeDescription
202AcceptedAdd row request accepted for processing.
400BadRequest
Reason:
  • Invalid request details.
  • Missing CanAddOrderRow action.
  • Order not found.
  • Any other internal error.
403ForbiddenMerchant does not have permission to access this resource.
401UnauthorizedMerchant is not authorized to retrieve information.

Update order row

Description

Call this endpoint to update an order row.
If the new order amount is higher than the current order amount, a credit check will be made.

Endpoint

Method: PATCH
/api/v1/orders/{CheckoutOrderId}/rows/{OrderRowId}/

Sample Code

Update Order Row Example
using Microsoft.Extensions.DependencyInjection;
using System.Text.Json;
using System.Text;

internal static class EditOrderUpdateRow
{
internal static async Task EditOrderUpdateRowAsync(long checkoutOrderId, int rowId)
{
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 = string.Format("v1/orders/{0}/rows/{1}", checkoutOrderId, rowId);

var updateRowRequest = new UpdateRowRequest("A-1", 5000);

var jsonString = JsonSerializer.Serialize(updateRowRequest);
var updateRowRequestJson = 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.PatchAsync(apiUrl, updateRowRequestJson);

// 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 UpdateRowRequest(string ArticleNumber, long Quantity, string? Name = "", long? UnitPrice = 0, long? DiscountPercent = 0, long? DiscountAmount = 0,
long? VatPercent = 0, string? Unit = "",
bool? IsCancelled = false);

Prerequisite

The order must have the action CanUpdateOrderRow.
The order row must have the action CanUpdateRow.

Request parameters

ParameterDescriptionType

CheckoutOrderID required

Checkout order ID of the specified order.Long

OrderRowID required

ID of the specified row to be updated.Long

OrderRow required

OrderRow objectOrder Row

Response Code

CodeHttpStatusCodeDescription
204No ContentUpdate Row request Accepted for processing.
400BadRequest
Reason:
  • Invalid request details.
  • Missing CanUpdateOrderRow or CanUpdateRow action.
  • Order not found.
  • Order Row cannot be found.
  • Any other internal error.
403ForbiddenMerchant does not have permission to access this resource.
401UnauthorizedMerchant is not authorized to retrieve information.

Update Order Row Request

ParameterDescriptionType
ArticleNumberArticle number as a string, can contain letters and numbers.String
NameArticle name.String

Quantity required

Quantity of the product.Long
UnitPricePrice of the product including VAT.Long
DiscountPercentDiscount percentage of the product. Cannot be used together with DiscountAmount.Long
DiscountAmountDiscount amount of the product. Cannot be used together with DiscountPercent.Long
VatPercentThe VAT percentage of the current product.Long
UnitThe unit type, e.g., “st”, “pc”, “kg” etc.String
IsCancelledSet to true if the row should be cancelled.Boolean

Update order rows

Description

Call this endpoint to update several order rows.
If the new order amount is higher than the current order amount, a credit check will be made.

Endpoint

Method: POST
/api/v1/orders/{CheckoutOrderId}/rows/updateOrderRows/

Note: Despite being an update operation, this endpoint uses the POST method.

Sample Code

Update Order Rows Example
using Microsoft.Extensions.DependencyInjection;
using System.Text.Json;
using System.Text;

internal static class EditOrderUpdateRows
{
internal static async Task EditOrderUpdateRowsAsync(long checkoutOrderId)
{
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 = string.Format("v1/orders/{0}/rows/updateOrderRows", checkoutOrderId);

var updateRowsRequest = new UpdateRowsRequest
{
OrderRows = new List<UpdateRowsObject>
{
new UpdateRowsObject(1, new UpdateRowRequest("A-1", 1000)),
new UpdateRowsObject(2, new UpdateRowRequest("A-2", 3000))
}
};


var jsonString = JsonSerializer.Serialize(updateRowsRequest);
var updateRowsRequestJson = 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, updateRowsRequestJson);

// 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 UpdateRowsObject(long RowId, UpdateRowRequest Row);
internal record UpdateRowRequest(string ArticleNumber, long Quantity, string? Name = "", long? UnitPrice = 0, long? DiscountPercent = 0, long? DiscountAmount = 0,
long? VatPercent = 0, string? Unit = "",
bool? IsCancelled = false);
internal class UpdateRowsRequest
{
public IList<UpdateRowsObject> OrderRows { get; set; }
}

Prerequisite

The order must have the action CanUpdateOrderRow.
The order row must have the action CanUpdateRow.

Request parameters

ParameterDescriptionType

CheckoutOrderID required

Checkout order ID of the specified order.Long

OrderRows required

To update several order rows with row ID specified.List of Order Row

Update Order Rows Request

ParameterDescriptionType

RowID required

Row ID of the order row.Long
ArticleNumberArticle number as a string, can contain letters and numbers.String
NameArticle name.String

Quantity required

Quantity of the product.Long
UnitPricePrice of the product including VAT.Long
DiscountPercentDiscount percentage of the product. Cannot be used together with DiscountAmount.Long
DiscountAmountDiscount amount of the product. Cannot be used together with DiscountPercent.Long
VatPercentThe VAT percentage of the current product.Long
UnitThe unit type, e.g., “st”, “pc”, “kg” etc.String

Response Code

CodeHttpStatusCodeDescription
204No ContentRow update processed successfully.
400BadRequest
Reason:
  • Invalid request details.
  • Missing CanUpdateOrderRow or CanUpdateRow action.
  • Order not found.
  • Any other internal error.
403ForbiddenMerchant does not have permission to access this resource.
401UnauthorizedMerchant is not authorized to retrieve information.

Replace order rows

Description

Call this endpoint to replace all existing order rows with new order rows.
The existing rows will be cancelled.
If the new order amount is higher than the current order amount, a credit check will be made.

Endpoint

Method: PUT
/api/v1/orders/{CheckoutOrderId}/rows/replaceOrderRows

Sample Code

Replace Order Rows Example
using Microsoft.Extensions.DependencyInjection;
using System.Text.Json;
using System.Text;

internal static class EditOrderReplaceRows
{
internal static async Task EditOrderReplaceRowsAsync(long checkoutOrderId)
{
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 = string.Format("v1/orders/{0}/rows/replaceOrderRows", checkoutOrderId);

//New Order Rows
var replaceRowRequest = new List<AddRowRequest>
{
new AddRowRequest("A-1", "Article Name 1", 1000, 1000, 0, 0, 2500, "st")
};

var addRowsRequest = new AddRowsRequest(replaceRowRequest);

var jsonString = JsonSerializer.Serialize(addRowsRequest);
var replaceRowRequestJson = 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, replaceRowRequestJson);

// 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 AddRowRequest(string ArticleNumber, string Name, long Quantity, long UnitPrice, long DiscountPercent, long DiscountAmount, long VatPercent, string Unit);

Prerequisite

The order must have the action CanUpdateOrderRow.
⚠️ This endpoint is only applicable for orders with payment type:

Invoice Account Credit Payment plan

Request parameters

ParameterDescriptionType

CheckoutOrderID required

Checkout order ID of the specified order.Long

OrderRows required

The new order rows that will replace all existing rows.List of Order Row

Response Code

CodeHttpStatusCodeDescription
204No ContentUpdate Row request Accepted for processing.
400BadRequest
Reason:
  • Invalid request details.
  • Missing CanUpdateOrderRow or CanUpdateRow action.
  • Order not found.
  • Any other internal error.
403ForbiddenMerchant does not have permission to access this resource.
401UnauthorizedMerchant is not authorized to retrieve information.

Extend order expiry date

Description

Call this endpoint to update expiry date of an order. The requested new expiry date of an order should not be in the past and greater than current date.

Endpoint

Method: PATCH
/api/v1/orders/{CheckoutOrderId}/extendOrder/{expiryDate}/

Sample Code

Extend Order Expiry Date Example
using Microsoft.Extensions.DependencyInjection;

internal static class EditOrderExtendExpiryDate
{
internal static async Task EditOrderExtendExpiryDateAsync(long checkoutOrderId, string expiryDate)
{
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 = string.Format("v1/orders/{0}/extendOrder/{1}/", checkoutOrderId, expiryDate);

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

try
{
HttpResponseMessage response = await httpClient.PatchAsync(apiUrl, new StringContent(""));

// 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);
}
}
}

Request parameters

ParameterDescriptionType

CheckoutOrderID required

Checkout order ID of the specified order.Long

ExpiryDate required

New expiry date of an order in ISO 8601 format. e.g. 2024-01-01

Date

Response Code

CodeHttpStatusCodeDescription
200SuccessExtend date has been updated successfully.
400BadRequest
Reason:
  • Invalid request details.
  • Order not found.
  • Any other internal error.
403ForbiddenMerchant does not have permission to access this resource.
401UnauthorizedMerchant is not authorized to retrieve information.

Update Metadata

Description

Call this endpoint to update metadata of an order which is an optional set of custom key–value pairs that can be attached to the request to help with internal tracking, filtering, or correlation (for example: sales channel, external reference IDs, or source system identifiers).

Endpoint

Method: PUT
/api/v1/orders/{CheckoutOrderId}/metadata

Sample Code

Update Order Metadata Example
using Microsoft.Extensions.DependencyInjection;

internal static class UpdateOrderMetadata
{
internal static async Task UpdateOrderMetadataAsync(long checkoutOrderId)
{
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 = string.Format("v1/orders/{0}/metadata", checkoutOrderId);

//Metadata
var metadataItems = new MetadataItem[]
{
new MetadataItem { Key = "key1", Value = "value1" },
new MetadataItem { Key = "key2", Value = "value2" }
};

var metadataRequest=new MetadataRequest(metadataItems);


var jsonString = JsonSerializer.Serialize(metadataRequest);
var metadataRequestJson = new StringContent(
jsonString,
Encoding.UTF8,
"application/json");

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

try
{
HttpResponseMessage response = await httpClient.PutAsync(apiUrl, metadataRequestJson());

// 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 MetadataRequest(MetadataItem[] Metadata);
internal record MetadataItem(string Key,string Value);

Prerequisite

Maximum 50 key–value pairs per request.
Maximum 50 characters per key.
Maximum 500 characters per value.
Each key can only be used once per order.

Request parameters

ParameterDescriptionType

CheckoutOrderID required

Checkout order ID of the specified order.Long

Metadata required

List of metadata

List of key value pair

Response Code

CodeHttpStatusCodeDescription
200SuccessOrder metadata has been added successfully.
400BadRequest
Reason:
  • Invalid request details.
  • Order not found.
  • Any other internal error.
403ForbiddenMerchant does not have permission to access this resource.
401UnauthorizedMerchant is not authorized to retrieve information.
caution

Do not store or transmit sensitive information in metadata (e.g., passwords, access tokens, personal data, payment details, or other confidential identifiers).