Description
Bug
Attempting to create or update supplier prices via the Dolibarr 20.0.1 API results in a 500 Internal Server Error. Manual entry via the Dolibarr interface works correctly, but API calls with valid payload data fail consistently.
The API responds with an HTTP 500 Internal Server Error when a POST request with the payload is sent to the endpoint /products/{PRODUCT_ID}/purchase_prices.
Dolibarr Version
20.0.1
Environment PHP
8.2
Environment Database
MariaDB 11.3.2-MariaDB-1:11.3.2+maria
Steps to reproduce the behavior and expected behavior
import requests
import json
API Configuration
api_url = "https://xxxx/api/index.php/"
api_key = "xxxxxxxxxxxxxxxx"
PRODUCT_ID = 68198 # Example product ID
url = f"{api_url}products/{PRODUCT_ID}/purchase_prices"
Payload
payload = {
"qty": 1,
"buyprice": 15.99,
"price_base_type": "HT",
"fourn_id": 3,
"availability": 7,
"ref_fourn": "449452",
"tva_tx": 19.00,
"charges": "SU2411-00030",
"delivery_time_days": 2,
"supplier_reputation": "Favorit",
"desc_fourn": "string",
"barcode": "string",
"fk_barcode_type": 0
}
Headers
headers = {
"DOLAPIKEY": api_key,
"Content-Type": "application/json",
"Accept": "application/json",
}
Send POST request
response = requests.post(url, json=payload, headers=headers)
Check result
if response.status_code == 200:
print("Supplier price successfully updated.")
print(response.json())
else:
print(f"Error {response.status_code}: {response.text}")
print("Payload:")
print(json.dumps(payload, indent=4))