תיעוד Slate API
חיבור מערכת אחרת לSlate: לקוחות, פריטים, מסמכים, הוצאות והתראות.
https://api.slate.co.il/v1
התחלה
בעל העסק יוצר מפתח במסך "חיבורים" באפליקציה. המפתח מוצג פעם אחת בלבד, ונשלח בכל בקשה בכותרת Authorization. מפתח שמתחיל ב-slk_test_ עובד רק בסביבת הבדיקות, ומפתח שמתחיל ב-slk_live_ רק בסביבה האמיתית.
curl
curl https://api.slate.co.il/v1/documents \
-H "Authorization: Bearer $SLATE_KEY" \
-H "Idempotency-Key: order-1001" \
-H "Content-Type: application/json" \
-d '{"type":"tax-invoice-receipt","status":"issued","customerId":"cus_123","lineItems":[{"productName":"Consulting","quantity":1,"price":1000}],"receipts":[{"receiptType":"transfer","amount":1170}]}'Node
const res = await fetch('https://api.slate.co.il/v1/documents', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.SLATE_KEY}`,
'Idempotency-Key': 'order-1001',
'Content-Type': 'application/json',
},
body: JSON.stringify({"type":"tax-invoice-receipt","status":"issued","customerId":"cus_123","lineItems":[{"productName":"Consulting","quantity":1,"price":1000}],"receipts":[{"receiptType":"transfer","amount":1170}]}),
});
const doc = await res.json();Python
import os, requests
res = requests.post(
"https://api.slate.co.il/v1/documents",
headers={"Authorization": f"Bearer {os.environ['SLATE_KEY']}", "Idempotency-Key": "order-1001"},
json={"type":"tax-invoice-receipt","status":"issued","customerId":"cus_123","lineItems":[{"productName":"Consulting","quantity":1,"price":1000}],"receipts":[{"receiptType":"transfer","amount":1170}]},
)
doc = res.json()PHP
$ch = curl_init('https://api.slate.co.il/v1/documents');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('SLATE_KEY'),
'Idempotency-Key: order-1001',
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => '{"type":"tax-invoice-receipt","status":"issued","customerId":"cus_123","lineItems":[{"productName":"Consulting","quantity":1,"price":1000}],"receipts":[{"receiptType":"transfer","amount":1170}]}',
]);
$doc = json_decode(curl_exec($ch), true);Verify webhook (Node)
import crypto from 'node:crypto';
function verify(header, rawBody, secret) {
const { t, v1 } = Object.fromEntries(header.split(',').map((p) => p.split('=')));
const expected = crypto.createHmac('sha256', secret).update(`${t}.${rawBody}`).digest('hex');
const fresh = Math.abs(Date.now() / 1000 - Number(t)) < 300;
return fresh && crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(v1));
}הפקת מסמך
מסמך נוצר כטיוטה (status: "draft") או מופק מיד (status: "issued"). חובה לציין אחד מהשניים. מסמך שהופק הוא רשומה קבועה: אי אפשר לערוך אותו או למחוק אותו, ותיקון נעשה במסמך זיכוי. הפקה דורשת מפתח עם הרשאת הפקה וכותרת Idempotency-Key, כך שבקשה שנשלחה פעמיים מפיקה מסמך אחד.
פתיחת עסק מהאפליקציה שלכם
אפליקציה שרושמת משתמשים יכולה לפתוח לכל אחד מהם עסק בSlate בלי שייכנס לאתר. בשביל זה צריך מפתח שותף (slk_partner_live_), שמתקבל מ-Slate. POST /v1/partner/businesses עם פרטי העסק והמייל של הבעלים פותח את העסק ומחזיר מפתח לעסק, שמוצג פעם אחת. כל הפעולות על העסק נעשות עם המפתח הזה. הבעלים מקבל מייל שהחשבון נפתח, ויכול להיכנס אליו עם קוד שנשלח למייל ולבטל את הגישה. כתובת מייל או מספר עוסק שכבר רשומים בSlate נדחים.
שגיאות
כל שגיאה חוזרת באותו מבנה, עם קוד קבוע שאפשר לבדוק בקוד ומזהה בקשה לפנייה לתמיכה.
{
"error": {
"type": "invalid_request",
"code": "status_required",
"message": "status is required: \"draft\" or \"issued\".",
"param": "status",
"requestId": "req_8f2c..."
}
}דפדוף
רשימות מחזירות עד 50 שורות (limit עד 100). לדף הבא שולחים startingAfter עם המזהה האחרון. modifiedSince מחזיר רק מה שהשתנה מאז, לסנכרון.
התראות (Webhooks)
כל התראה חתומה בכותרת Slate-Signature. מחשבים HMAC-SHA256 של "t.body" עם הסוד שהתקבל ברישום, ומשווים ל-v1. התראה שלא נענתה ב-2xx נשלחת שוב: אחרי דקה, 5 דקות, 30 דקות, שעתיים, 6 שעות ואז פעם ביום. אחרי כמה ימים של כישלונות הכתובת מושבתת ובעל העסק מקבל מייל.
מגבלות קצב
מעבר למגבלה מחזיר 429 עם כותרת Retry-After.
כל הנתיבים
GET | /v1/business | The business the key belongs to | business |
GET | /v1/customers | List customers | customers |
POST | /v1/customers | Create a customer | customers |
GET | /v1/customers/{id} | Get a customer | customers |
PATCH | /v1/customers/{id} | Update a customer | customers |
DELETE | /v1/customers/{id} | Delete a customer with no documents | customers |
GET | /v1/products | List items | products |
POST | /v1/products | Create an item | products |
GET | /v1/products/{id} | Get an item | products |
PATCH | /v1/products/{id} | Update an item | products |
DELETE | /v1/products/{id} | Delete an item | products |
GET | /v1/documents | List documents | documents |
POST | /v1/documents | Create a draft, or issue a document | documents |
GET | /v1/documents/{id} | Get a document | documents |
PATCH | /v1/documents/{id} | Update a draft | documents |
DELETE | /v1/documents/{id} | Delete a draft | documents |
POST | /v1/documents/{id}/issue | Issue a draft | documents |
GET | /v1/documents/{id}/pdf | Download the PDF of an issued document | documents |
POST | /v1/documents/{id}/send | Email the customer a link to an issued document | documents |
POST | /v1/documents/{id}/allocation/retry | Ask the Tax Authority again for an allocation number | documents |
POST | /v1/documents/{id}/public-url/rotate | Replace the public download link | documents |
GET | /v1/document-numbering | Numbering per document type | documents |
PUT | /v1/document-numbering/{type} | Confirm the starting number for a document type | documents |
GET | /v1/expenses | List expenses | expenses |
POST | /v1/expenses | Record an expense | expenses |
GET | /v1/expenses/{id} | Get an expense | expenses |
GET | /v1/expenses/{id}/receipt | Download the receipt file | expenses |
GET | /v1/reports/vat | VAT report for a period | reports |
GET | /v1/webhook-endpoints | List webhook endpoints | webhooks |
POST | /v1/webhook-endpoints | Register a webhook endpoint | webhooks |
DELETE | /v1/webhook-endpoints/{id} | Remove a webhook endpoint | webhooks |
GET | /v1/events | Events from the last 30 days | webhooks |
GET | /v1/partner/businesses | Businesses you opened | partner |
POST | /v1/partner/businesses | Open a business for one of your users | partner |
GET | /v1/partner/businesses/{id} | One business you opened | partner |
GET | /v1/partner/businesses/{id}/keys | Keys you created for the business | partner |
POST | /v1/partner/businesses/{id}/keys | Create another key for the business | partner |
DELETE | /v1/partner/businesses/{id}/keys/{keyId} | Revoke a key you created | partner |