Create new tax transaction - Fabric
Create new tax transaction
cURL
curl --request POST \
--url https://prod01-apigw.yourcompany.fabric.zone/api-tax/tax/create \
--header 'Content-Type: application/json' \
--header 'x-site-context: <x-site-context>' \
--data '
{
"type": "SalesInvoice",
"lineItems": [
{
"price": 12.99,
"quantity": 3,
"taxCode": "PF050099",
"title": "Fabric Inc T-Shirt",
"sku": "123456789Red-Shirt",
"lineItem": 3
}
],
"addresses": {
"shipTo": {
"street1": "2000 Main Street",
"city": "Irvine",
"state": "CA",
"country": "US",
"zipCode": "92614"
},
"shipFrom": {
"street1": "2000 Main Street",
"city": "Irvine",
"state": "CA",
"country": "US",
"zipCode": "92614"
}
}
}
'
Python
import requests
url = "https://prod01-apigw.yourcompany.fabric.zone/api-tax/tax/create"
payload = {
"type": "SalesInvoice",
"lineItems": [
{
"price": 12.99,
"quantity": 3,
"taxCode": "PF050099",
"title": "Fabric Inc T-Shirt",
"sku": "123456789Red-Shirt",
"lineItem": 3
}
],
"addresses": {
"shipTo": {
"street1": "2000 Main Street",
"city": "Irvine",
"state": "CA",
"country": "US",
"zipCode": "92614"
},
"shipFrom": {
"street1": "2000 Main Street",
"city": "Irvine",
"state": "CA",
"country": "US",
"zipCode": "92614"
}
}
}
headers = {
"x-site-context": "<x-site-context>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)
JavaScript (Fetch)
const options = {
method: 'POST',
headers: {'x-site-context': '<x-site-context>', 'Content-Type': 'application/json'},
body: JSON.stringify({
type: 'SalesInvoice',
lineItems: [
{
price: 12.99,
quantity: 3,
taxCode: 'PF050099',
title: 'Fabric Inc T-Shirt',
sku: '123456789Red-Shirt',
lineItem: 3
}
],
addresses: {
shipTo: {
street1: '2000 Main Street',
city: 'Irvine',
state: 'CA',
country: 'US',
zipCode: '92614'
},
shipFrom: {
street1: '2000 Main Street',
city: 'Irvine',
state: 'CA',
country: 'US',
zipCode: '92614'
}
}
})
};
fetch('https://prod01-apigw.yourcompany.fabric.zone/api-tax/tax/create', 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://prod01-apigw.yourcompany.fabric.zone/api-tax/tax/create",
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([
'type' => 'SalesInvoice',
'lineItems' => [
[
'price' => 12.99,
'quantity' => 3,
'taxCode' => 'PF050099',
'title' => 'Fabric Inc T-Shirt',
'sku' => '123456789Red-Shirt',
'lineItem' => 3
]
],
'addresses' => [
'shipTo' => [
'street1' => '2000 Main Street',
'city' => 'Irvine',
'state' => 'CA',
'country' => 'US',
'zipCode' => '92614'
],
'shipFrom' => [
'street1' => '2000 Main Street',
'city' => 'Irvine',
'state' => 'CA',
'country' => 'US',
'zipCode' => '92614'
]
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-site-context: <x-site-context>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
Response Example
{
"code": "e2ab8924-4316-47b6-880d-3744b16aaa4f",
"date": "2021-09-19",
"status": "Saved",
"type": "SalesInvoice",
"customerCode": "FABRIC_INC",
"totalAmount": 2063.39,
"totalExempt": 182.97,
"totalDiscount": 0,
"totalTax": 145.73,
"totalTaxable": 1880.42,
"totalTaxCalculated": 145.73,
"lines": [
{
"id": 6000306551642,
"lineNumber": "1",
"description": "Chocolate",
"isItemTaxable": true,
"lineAmount": null,
"quantity": 2,
"tax": 139.5,
"taxableAmount": 1800,
"taxCalculated": 139.5,
"taxCode": "P0000000"
}
]
}
Error Response Example
{
"code": "<string>",
"message": "<string>"
}