接入教程
1. 访问Invovate官网注册获取API密钥
2. 准备包含发票数据的JSON请求体
3. 向API端点发送POST请求
4. 接收生成的PDF、JSON或UBL格式发票
5. 根据需要配置输出语言(支持11种)
使用Python生成多语言发票
import requests
import json
url = "https://api.example.com/v1/invoices"
api_key = "YOUR_API_KEY"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
}
# 示例发票数据
invoice_data = {
"invoice": {
"language": "en",
"currency": "USD",
"items": [
{"description": "Web Design Service", "quantity": 1, "unit_price": 500}
]
},
"output_formats": ["pdf", "json", "ubl"]
}
response = requests.post(url, headers=headers, json=invoice_data)
if response.status_code == 200:
result = response.json()
print("Invoice generated successfully:", result)
else:
print(f"Error: {response.status_code}", response.text)
使用PHP调用发票生成API
<?php
$url = "https://api.example.com/v1/invoices";
$api_key = "YOUR_API_KEY";
$data = [
"invoice" => [
"language" => "zh",
"currency" => "CNY",
"items" => [
["description" => "软件开发服务", "quantity" =>161, "unit_price" => 1500]
]
],
"output_formats" => ["pdf", "json"]
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer " . $api_key,
"Content-Type: application/json"
]);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($http_code == 200) {
$result = json_decode($response, true);
echo "发票生成成功:";
print_r($result);
} else {
echo "错误代码:{$http_code}\n";
echo $response;
}
?>
使用JavaScript生成发票
const apiUrl = "https://api.example.com/v1/invoices";
const apiKey = "YOUR_API_KEY";
const invoiceData = {
invoice: {
language: "de",
currency: "EUR",
items: [
{description: "IT Consulting", quantity: 2, unit_price: 750}
]
},
output_formats: ["pdf", "ubl"]
};
async function generateInvoice() {
try {
const response = await fetch(apiUrl, {
method: "POST",
headers: {
"Authorization": `Bearer ${apiKey}`,
"Content-Type": "application/json"
},
body: JSON.stringify(invoiceData)
});
if (response.ok) {
const result = await response.json();
console.log("Invoice generated:", result);
} else {
console.error(`Error: ${response.status}`, await response.text());
}
} catch (error) {
console.error("Request failed:", error);
}
}
generateInvoice();
常见问题
API支持哪些输出格式?
支持PDF、JSON和UBL三种格式。您可以通过output_formats参数指定一种或多种格式,API将返回相应格式的发票数据。
发票数据中的语言字段支持哪些选项?
目前支持11种语言:英语(en)、中文(zh)、德语(de)、法语(fr)、西班牙语(es)、日语(ja)、韩语(ko)、意大利语(it)、葡萄牙语(pt)、俄语(ru)和荷兰语(nl)。
如何获取API密钥?
请访问Invovate官网(https://invovate.com/api)注册账户,在开发者控制台创建项目即可获取API密钥。测试环境提供免费调用额度。
Aitishiku.com