Klarna
Start Klarna Checkout
Creates a Klarna payment session and returns client credentials for the Klarna widget
POST
/
api
/
v1
/
domains
/
{domain}
/
express
/
klarna
/
start
Start Klarna Checkout
curl --request POST \
--url https://api.firmly.work/api/v1/domains/{domain}/express/klarna/start \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'x-firmly-authorization: <x-firmly-authorization>' \
--data '
{
"attributes": {}
}
'import requests
url = "https://api.firmly.work/api/v1/domains/{domain}/express/klarna/start"
payload = { "attributes": {} }
headers = {
"x-firmly-authorization": "<x-firmly-authorization>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'x-firmly-authorization': '<x-firmly-authorization>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({attributes: {}})
};
fetch('https://api.firmly.work/api/v1/domains/{domain}/express/klarna/start', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.firmly.work/api/v1/domains/{domain}/express/klarna/start",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'attributes' => [
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"x-firmly-authorization: <x-firmly-authorization>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.firmly.work/api/v1/domains/{domain}/express/klarna/start"
payload := strings.NewReader("{\n \"attributes\": {}\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-firmly-authorization", "<x-firmly-authorization>")
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.firmly.work/api/v1/domains/{domain}/express/klarna/start")
.header("x-firmly-authorization", "<x-firmly-authorization>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"attributes\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.firmly.work/api/v1/domains/{domain}/express/klarna/start")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-firmly-authorization"] = '<x-firmly-authorization>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"attributes\": {}\n}"
response = http.request(request)
puts response.read_body{
"cart_id": "<string>",
"line_items": [
{}
],
"payment_method": {
"payment_type": "<string>",
"attributes": {
"session_id": "<string>",
"client_token": "<string>",
"payment_method_categories": [
{}
],
"url": "<string>"
}
},
"shipping_info": {},
"shipping_method": {},
"total": {},
"sub_total": {},
"tax": {},
"fees": [
{}
],
"fee_total": {}
}Overview
Initiates a Klarna checkout by creating a payment session with Klarna. Returns the cart enriched with apayment_method object containing the client_token, session_id, and available payment_method_categories needed to render the Klarna Payments widget on the client. Merchants that use a redirect flow return a url to send the buyer to instead (see the url field below).
Klarna is enabled per merchant. Check the cart’s
payment_method_options array for { "type": "Klarna", "wallet": "klarna", "config": { "express_enabled": true, "clientId": "..." } } before offering Klarna.Authentication
Path Parameters
Request Body
Optional gateway-specific attributes. Can be an empty object or omitted entirely for standard Klarna checkout.
Response
Returns the cart enriched with the Klarna payment method details.Klarna payment method details
Show Payment Method
Show Payment Method
Klarna session credentials
Show Attributes
Show Attributes
Available Klarna payment options (e.g.,
pay_later, pay_over_time, pay_now). Each entry contains identifier, name, and asset_urls.Redirect flow only. The hosted Klarna page to send the buyer to, returned instead of
client_token for merchants that use a redirect flow. After the buyer completes Klarna, pass the redirectResult from the return URL to Complete Order as transaction_token.Code Example
const response = await fetch(
'https://api.firmly.work/api/v1/domains/merchant.example.com/express/klarna/start',
{
method: 'POST',
headers: {
'x-firmly-authorization': authToken,
'Content-Type': 'application/json'
},
body: JSON.stringify({})
}
);
const cart = await response.json();
// Extract Klarna credentials for the widget
const {
session_id,
client_token,
payment_method_categories
} = cart.payment_method.attributes;
// Initialize Klarna Payments SDK with client_token
Klarna.Payments.init({ client_token });
import requests
response = requests.post(
'https://api.firmly.work/api/v1/domains/merchant.example.com/express/klarna/start',
headers={
'x-firmly-authorization': auth_token,
'Content-Type': 'application/json'
},
json={}
)
cart = response.json()
klarna_attrs = cart['payment_method']['attributes']
session_id = klarna_attrs['session_id']
client_token = klarna_attrs['client_token']
categories = klarna_attrs['payment_method_categories']
curl -X POST https://api.firmly.work/api/v1/domains/merchant.example.com/express/klarna/start \
-H "x-firmly-authorization: YOUR_AUTH_TOKEN" \
-H "Content-Type: application/json" \
-d '{}'
Response Example
{
"cart_id": "9cf76530-1344-420f-9ca6-c7a96fb6db45",
"line_items": [
{
"line_item_id": "3e66bef5-43f5-4a80-8957-91c5c8233163",
"sku": "MT12",
"quantity": 1,
"description": "Cassius Sparring Tank",
"price": {
"currency": "USD",
"value": 18,
"number": 1800,
"symbol": "$"
},
"line_price": {
"currency": "USD",
"value": 18,
"number": 1800,
"symbol": "$"
}
}
],
"payment_method": {
"payment_type": "Klarna",
"attributes": {
"session_id": "kp_abc123def456",
"client_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
"payment_method_categories": [
{
"identifier": "pay_later",
"name": "Pay later",
"asset_urls": {
"descriptive": "https://x.klarnacdn.net/payment-method/assets/badges/generic/klarna.svg",
"standard": "https://x.klarnacdn.net/payment-method/assets/badges/generic/klarna.svg"
}
},
{
"identifier": "pay_over_time",
"name": "Financing",
"asset_urls": {
"descriptive": "https://x.klarnacdn.net/payment-method/assets/badges/generic/klarna.svg",
"standard": "https://x.klarnacdn.net/payment-method/assets/badges/generic/klarna.svg"
}
}
]
}
},
"shipping_info": {
"first_name": "John",
"last_name": "Smith",
"email": "john@example.com",
"phone": "2065551212",
"address1": "123 Main St",
"city": "Seattle",
"state_or_province": "WA",
"country": "US",
"postal_code": "98101"
},
"shipping_method": {
"id": "standard_shipping",
"description": "Standard Shipping",
"price": {
"currency": "USD",
"value": 10,
"number": 1000,
"symbol": "$"
}
},
"total": {
"currency": "USD",
"value": 32,
"number": 3200,
"symbol": "$"
},
"sub_total": {
"currency": "USD",
"value": 18,
"number": 1800,
"symbol": "$"
},
"tax": {
"currency": "USD",
"value": 2,
"number": 200,
"symbol": "$"
},
"fees": [
{
"description": "Recycle fee",
"currency": "USD",
"value": 2,
"number": 200,
"symbol": "$"
}
],
"fee_total": {
"currency": "USD",
"value": 2,
"number": 200,
"symbol": "$"
}
}
Error Responses
| Code | Description |
|---|---|
ErrorCartNotFound | No active cart for this domain |
ErrorGatewayNotFound | Klarna is not enabled for this merchant |
ErrorOperationNotSupported | Merchant adapter does not support Klarna |
ErrorStartExpressCheckout | Failed to create Klarna payment session |
ErrorStoreUnavailable | Merchant temporarily unavailable |
ErrorRateLimited | Too many requests |
Related Endpoints
- Authorize Klarna Checkout - Confirm Klarna authorization
- Complete Klarna Order - Finalize the order
⌘I
Start Klarna Checkout
curl --request POST \
--url https://api.firmly.work/api/v1/domains/{domain}/express/klarna/start \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'x-firmly-authorization: <x-firmly-authorization>' \
--data '
{
"attributes": {}
}
'import requests
url = "https://api.firmly.work/api/v1/domains/{domain}/express/klarna/start"
payload = { "attributes": {} }
headers = {
"x-firmly-authorization": "<x-firmly-authorization>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'x-firmly-authorization': '<x-firmly-authorization>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({attributes: {}})
};
fetch('https://api.firmly.work/api/v1/domains/{domain}/express/klarna/start', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.firmly.work/api/v1/domains/{domain}/express/klarna/start",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'attributes' => [
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"x-firmly-authorization: <x-firmly-authorization>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.firmly.work/api/v1/domains/{domain}/express/klarna/start"
payload := strings.NewReader("{\n \"attributes\": {}\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-firmly-authorization", "<x-firmly-authorization>")
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.firmly.work/api/v1/domains/{domain}/express/klarna/start")
.header("x-firmly-authorization", "<x-firmly-authorization>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"attributes\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.firmly.work/api/v1/domains/{domain}/express/klarna/start")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-firmly-authorization"] = '<x-firmly-authorization>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"attributes\": {}\n}"
response = http.request(request)
puts response.read_body{
"cart_id": "<string>",
"line_items": [
{}
],
"payment_method": {
"payment_type": "<string>",
"attributes": {
"session_id": "<string>",
"client_token": "<string>",
"payment_method_categories": [
{}
],
"url": "<string>"
}
},
"shipping_info": {},
"shipping_method": {},
"total": {},
"sub_total": {},
"tax": {},
"fees": [
{}
],
"fee_total": {}
}