Klarna
Authorize Klarna Checkout
Confirms the Klarna authorization token after customer approval in the Klarna widget
POST
/
api
/
v1
/
domains
/
{domain}
/
express
/
klarna
/
authorize
Authorize Klarna Checkout
curl --request POST \
--url https://api.firmly.work/api/v1/domains/{domain}/express/klarna/authorize \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'x-firmly-authorization: <x-firmly-authorization>' \
--data '
{
"attributes": {
"authorization_token": "<string>"
}
}
'import requests
url = "https://api.firmly.work/api/v1/domains/{domain}/express/klarna/authorize"
payload = { "attributes": { "authorization_token": "<string>" } }
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: {authorization_token: '<string>'}})
};
fetch('https://api.firmly.work/api/v1/domains/{domain}/express/klarna/authorize', 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/authorize",
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' => [
'authorization_token' => '<string>'
]
]),
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/authorize"
payload := strings.NewReader("{\n \"attributes\": {\n \"authorization_token\": \"<string>\"\n }\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/authorize")
.header("x-firmly-authorization", "<x-firmly-authorization>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"attributes\": {\n \"authorization_token\": \"<string>\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.firmly.work/api/v1/domains/{domain}/express/klarna/authorize")
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 \"authorization_token\": \"<string>\"\n }\n}"
response = http.request(request)
puts response.read_body{
"cart_id": "<string>",
"line_items": [
{}
],
"payment_method": {
"payment_type": "<string>",
"attributes": {
"session_id": "<string>",
"authorization_token": "<string>"
}
},
"shipping_info": {},
"total": {},
"sub_total": {},
"tax": {},
"fees": [
{}
],
"fee_total": {}
}Overview
After the customer authorizes payment in the Klarna widget (client-side), this endpoint confirms the authorization with Firmly. It stores theauthorization_token in the session and returns the cart with the confirmed Klarna payment method.
Authentication
Path Parameters
Request Body
Response
Returns the cart with the confirmed Klarna payment method.Code Example
// After Klarna.Payments.authorize() callback returns authorization_token
const response = await fetch(
'https://api.firmly.work/api/v1/domains/merchant.example.com/express/klarna/authorize',
{
method: 'POST',
headers: {
'x-firmly-authorization': authToken,
'Content-Type': 'application/json'
},
body: JSON.stringify({
attributes: {
authorization_token: 'klarna_auth_token_from_widget'
}
})
}
);
const cart = await response.json();
// Payment is now authorized, proceed to complete order
import requests
response = requests.post(
'https://api.firmly.work/api/v1/domains/merchant.example.com/express/klarna/authorize',
headers={
'x-firmly-authorization': auth_token,
'Content-Type': 'application/json'
},
json={
'attributes': {
'authorization_token': 'klarna_auth_token_from_widget'
}
}
)
cart = response.json()
curl -X POST https://api.firmly.work/api/v1/domains/merchant.example.com/express/klarna/authorize \
-H "x-firmly-authorization: YOUR_AUTH_TOKEN" \
-H "Content-Type: application/json" \
-d '{"attributes": {"authorization_token": "klarna_auth_token_from_widget"}}'
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",
"authorization_token": "klarna_auth_token_from_widget"
}
},
"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"
},
"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 |
ErrorBadRequest | Missing authorization_token in request body |
ErrorGatewayNotFound | Klarna is not enabled for this merchant |
ErrorPaymentMethodNotAvailable | Klarna is not available for this cart |
ErrorPrecondition | Precondition failed (e.g., cart state invalid) |
ErrorSubmitExpressCheckout | Authorization failed at the merchant |
ErrorRateLimited | Too many requests |
Related Endpoints
- Start Klarna Checkout - Create Klarna session first
- Complete Klarna Order - Finalize the order
⌘I
Authorize Klarna Checkout
curl --request POST \
--url https://api.firmly.work/api/v1/domains/{domain}/express/klarna/authorize \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'x-firmly-authorization: <x-firmly-authorization>' \
--data '
{
"attributes": {
"authorization_token": "<string>"
}
}
'import requests
url = "https://api.firmly.work/api/v1/domains/{domain}/express/klarna/authorize"
payload = { "attributes": { "authorization_token": "<string>" } }
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: {authorization_token: '<string>'}})
};
fetch('https://api.firmly.work/api/v1/domains/{domain}/express/klarna/authorize', 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/authorize",
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' => [
'authorization_token' => '<string>'
]
]),
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/authorize"
payload := strings.NewReader("{\n \"attributes\": {\n \"authorization_token\": \"<string>\"\n }\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/authorize")
.header("x-firmly-authorization", "<x-firmly-authorization>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"attributes\": {\n \"authorization_token\": \"<string>\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.firmly.work/api/v1/domains/{domain}/express/klarna/authorize")
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 \"authorization_token\": \"<string>\"\n }\n}"
response = http.request(request)
puts response.read_body{
"cart_id": "<string>",
"line_items": [
{}
],
"payment_method": {
"payment_type": "<string>",
"attributes": {
"session_id": "<string>",
"authorization_token": "<string>"
}
},
"shipping_info": {},
"total": {},
"sub_total": {},
"tax": {},
"fees": [
{}
],
"fee_total": {}
}