Order
Order Endpoint
The Order endpoint allows you to create a new order by providing the necessary details such as shipping address, cart items and optional custom reference or additional information.
Important: To place an order, you must set the place
parameter to 1
. If not set, the order will only be created without being placed. Example: /api/v1/order/?place=1
.
POST/api/v1/order/
URL parameters
Name | Type | Required | Description |
---|---|---|---|
place | boolean | ❌ | Set to 1 to place the order (default: 0) |
JSON body parameters
Name | Type | Required | Description |
---|---|---|---|
shipping_address_id | string | ✅ | UUID of shipping address |
cart | array | ✅ | Array of cart items with product_number and quantity |
custom_reference | string | ❌ | Your reference for this order |
additional_information | string | ❌ | Additional order information or notes |
Example Request
- cURL
- JavaScript
- PHP
- Python
- Go
- C#
curl -X POST "https://api.axro.com/api/v1/order/" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"shipping_address_id": "a1b2c3d4-e5f6-7890-abcd-1234567890ab",
"cart": [
{
"product_number": "CANL055BK",
"quantity": 5
},
{
"product_number": "HP301BK",
"quantity": 10
}
],
"custom_reference": "PO-12345",
"additional_information": "Please deliver to loading dock B"
}'
// Using Fetch API with async/await
async function placeOrder() {
const url = 'https://api.axro.com/api/v1/order/';
const token = 'YOUR_ACCESS_TOKEN';
const orderData = {
shipping_address_id: 'a1b2c3d4-e5f6-7890-abcd-1234567890ab',
cart: [
{
product_number: 'CANL055BK',
quantity: 5
},
{
product_number: 'HP301BK',
quantity: 10
}
],
custom_reference: 'PO-12345',
additional_information: 'Please deliver to loading dock B'
};
try {
const response = await fetch(url, {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(orderData)
});
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const result = await response.json();
console.log('Order placed successfully:', result);
return result;
} catch (error) {
console.error('Error placing order:', error);
throw error;
}
}
// Call the function
placeOrder().catch(error => console.error(error));
// Using cURL
function placeOrder() {
$url = 'https://api.axro.com/api/v1/order/';
$token = 'YOUR_ACCESS_TOKEN';
$orderData = [
'shipping_address_id' => 'a1b2c3d4-e5f6-7890-abcd-1234567890ab',
'cart' => [
[
'product_number' => 'CANL055BK',
'quantity' => 5
],
[
'product_number' => 'HP301BK',
'quantity' => 10
]
],
'custom_reference' => 'PO-12345',
'additional_information' => 'Please deliver to loading dock B'
];
// Initialize cURL session
$ch = curl_init($url);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($orderData));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $token,
'Content-Type: application/json'
]);
// Execute request
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// Check for errors
if (curl_errno($ch)) {
$error = curl_error($ch);
curl_close($ch);
return ['error' => 'cURL Error: ' . $error];
}
curl_close($ch);
// Parse response
$responseData = json_decode($response, true);
// Return success or error based on HTTP code
if ($httpCode >= 200 && $httpCode < 300) {
return [
'success' => true,
'data' => $responseData
];
} else {
return [
'success' => false,
'error' => 'HTTP Error: ' . $httpCode,
'response' => $responseData
];
}
}
// Call the function
$result = placeOrder();
if ($result['success']) {
echo "Order placed successfully!\n";
print_r($result['data']);
} else {
echo "Error placing order: " . $result['error'] . "\n";
}
# Using requests library
import requests
import json
def place_order():
url = 'https://api.axro.com/api/v1/order/'
token = 'YOUR_ACCESS_TOKEN'
headers = {
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json'
}
order_data = {
'shipping_address_id': 'a1b2c3d4-e5f6-7890-abcd-1234567890ab',
'cart': [
{
'product_number': 'CANL055BK',
'quantity': 5
},
{
'product_number': 'HP301BK',
'quantity': 10
}
],
'custom_reference': 'PO-12345',
'additional_information': 'Please deliver to loading dock B'
}
try:
response = requests.post(url, headers=headers, json=order_data)
response.raise_for_status() # Raise exception for HTTP errors
result = response.json()
print('Order placed successfully!')
return result
except requests.exceptions.HTTPError as http_err:
print(f'HTTP Error: {http_err}')
try:
# Try to extract error details from response
error_details = response.json()
print(f'Error details: {error_details}')
except:
pass
return None
except requests.exceptions.RequestException as req_err:
print(f'Request Error: {req_err}')
return None
# Call the function
result = place_order()
if result:
print(json.dumps(result, indent=2))
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
// CartItem represents a product in the cart
type CartItem struct {
ProductNumber string `json:"product_number"`
Quantity int `json:"quantity"`
}
// OrderRequest represents the order data to send to the API
type OrderRequest struct {
ShippingAddressID string `json:"shipping_address_id"`
Cart []CartItem `json:"cart"`
CustomReference string `json:"custom_reference"`
AdditionalInformation string `json:"additional_information"`
}
func placeOrder() (map[string]interface{}, error) {
url := "https://api.axro.com/api/v1/order/"
token := "YOUR_ACCESS_TOKEN"
// Create order data
orderData := OrderRequest{
ShippingAddressID: "a1b2c3d4-e5f6-7890-abcd-1234567890ab",
Cart: []CartItem{
{
ProductNumber: "CANL055BK",
Quantity: 5,
},
{
ProductNumber: "HP301BK",
Quantity: 10,
},
},
CustomReference: "PO-12345",
AdditionalInformation: "Please deliver to loading dock B",
}
// Convert to JSON
jsonData, err := json.Marshal(orderData)
if err != nil {
return nil, fmt.Errorf("error marshalling JSON: %v", err)
}
// Create request
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
if err != nil {
return nil, fmt.Errorf("error creating request: %v", err)
}
// Add headers
req.Header.Set("Authorization", "Bearer "+token)
req.Header.Set("Content-Type", "application/json")
// Send request
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return nil, fmt.Errorf("error sending request: %v", err)
}
defer resp.Body.Close()
// Read response body
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("error reading response: %v", err)
}
// Check status code
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return nil, fmt.Errorf("HTTP error %d: %s", resp.StatusCode, string(body))
}
// Parse response JSON
var result map[string]interface{}
if err := json.Unmarshal(body, &result); err != nil {
return nil, fmt.Errorf("error parsing response: %v", err)
}
return result, nil
}
func main() {
result, err := placeOrder()
if err != nil {
fmt.Printf("Error placing order: %v\n", err)
return
}
fmt.Println("Order placed successfully!")
// Print order details
orderJSON, _ := json.MarshalIndent(result, "", " ")
fmt.Println(string(orderJSON))
}
// Using HttpClient (modern approach)
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
class Program
{
// Define models for the request
class CartItem
{
[JsonPropertyName("product_number")]
public string ProductNumber { get; set; }
[JsonPropertyName("quantity")]
public int Quantity { get; set; }
}
class OrderRequest
{
[JsonPropertyName("shipping_address_id")]
public string ShippingAddressId { get; set; }
[JsonPropertyName("cart")]
public List Cart { get; set; }
[JsonPropertyName("custom_reference")]
public string CustomReference { get; set; }
[JsonPropertyName("additional_information")]
public string AdditionalInformation { get; set; }
}
static async Task Main()
{
try
{
var result = await PlaceOrder();
Console.WriteLine("Order placed successfully!");
Console.WriteLine(JsonSerializer.Serialize(result, new JsonSerializerOptions { WriteIndented = true }));
}
catch (Exception ex)
{
Console.WriteLine($"Error placing order: {ex.Message}");
}
}
static async Task PlaceOrder()
{
string url = "https://api.axro.com/api/v1/order/";
string token = "YOUR_ACCESS_TOKEN";
// Create order data
var orderData = new OrderRequest
{
ShippingAddressId = "a1b2c3d4-e5f6-7890-abcd-1234567890ab",
Cart = new List
{
new CartItem { ProductNumber = "CANL055BK", Quantity = 5 },
new CartItem { ProductNumber = "HP301BK", Quantity = 10 }
},
CustomReference = "PO-12345",
AdditionalInformation = "Please deliver to loading dock B"
};
// Create HttpClient
using (var client = new HttpClient())
{
// Add headers
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
// Serialize order data to JSON
string jsonData = JsonSerializer.Serialize(orderData);
var content = new StringContent(jsonData, Encoding.UTF8, "application/json");
// Send request
HttpResponseMessage response = await client.PostAsync(url, content);
// Read response content
string responseContent = await response.Content.ReadAsStringAsync();
// Check if request was successful
if (response.IsSuccessStatusCode)
{
// Parse response JSON
return JsonSerializer.Deserialize(responseContent);
}
else
{
throw new Exception($"HTTP error {(int)response.StatusCode}: {responseContent}");
}
}
}
}
Example Response
Important The keys uhg_unit
and uhg_total
will be set if a shipping address in Germany is provided, otherwise they will be set to 0.
More information about the UHG can be found here § 54 UrhG - Vergütungspflicht and § 54a UrhG - Vergütungshöhe.
{
"shipping_address": {
"id": "a1b2c3d4-e5f6-7890-abcd-1234567890ab",
"company": "Example Corp",
"department": "Warehouse",
"street": "123 Shipping St",
"zip": "10001",
"city": "New York",
"country": "US"
},
"billing_address": {
"company": "Example Corp",
"department": "Accounting",
"street": "456 Billing Ave",
"zip": "10002",
"city": "New York",
"country": "US"
},
"cart": [
{
"product_number": "CANL055BK",
"quantity": 5,
"difference": 0,
"unit_price": 8599,
"uhg_unit": 0,
"uhg_total": 0,
"sub_total": 42995
},
{
"product_number": "HP301BK",
"quantity": 10,
"difference": 0,
"unit_price": 2499,
"uhg_unit": 0,
"uhg_total": 0,
"sub_total": 24990
}
],
"toll": 0,
"freight_costs": 995,
"grand_total": 68980,
"custom_reference": "PO-12345",
"additional_information": "Please deliver to loading dock B",
"order_placed": true,
"place_order_url": "/api/v1/order/?place=1"
}