English

תיעוד 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/businessThe business the key belongs tobusiness
GET/v1/customersList customerscustomers
POST/v1/customersCreate a customercustomers
GET/v1/customers/{id}Get a customercustomers
PATCH/v1/customers/{id}Update a customercustomers
DELETE/v1/customers/{id}Delete a customer with no documentscustomers
GET/v1/productsList itemsproducts
POST/v1/productsCreate an itemproducts
GET/v1/products/{id}Get an itemproducts
PATCH/v1/products/{id}Update an itemproducts
DELETE/v1/products/{id}Delete an itemproducts
GET/v1/documentsList documentsdocuments
POST/v1/documentsCreate a draft, or issue a documentdocuments
GET/v1/documents/{id}Get a documentdocuments
PATCH/v1/documents/{id}Update a draftdocuments
DELETE/v1/documents/{id}Delete a draftdocuments
POST/v1/documents/{id}/issueIssue a draftdocuments
GET/v1/documents/{id}/pdfDownload the PDF of an issued documentdocuments
POST/v1/documents/{id}/sendEmail the customer a link to an issued documentdocuments
POST/v1/documents/{id}/allocation/retryAsk the Tax Authority again for an allocation numberdocuments
POST/v1/documents/{id}/public-url/rotateReplace the public download linkdocuments
GET/v1/document-numberingNumbering per document typedocuments
PUT/v1/document-numbering/{type}Confirm the starting number for a document typedocuments
GET/v1/expensesList expensesexpenses
POST/v1/expensesRecord an expenseexpenses
GET/v1/expenses/{id}Get an expenseexpenses
GET/v1/expenses/{id}/receiptDownload the receipt fileexpenses
GET/v1/reports/vatVAT report for a periodreports
GET/v1/webhook-endpointsList webhook endpointswebhooks
POST/v1/webhook-endpointsRegister a webhook endpointwebhooks
DELETE/v1/webhook-endpoints/{id}Remove a webhook endpointwebhooks
GET/v1/eventsEvents from the last 30 dayswebhooks
GET/v1/partner/businessesBusinesses you openedpartner
POST/v1/partner/businessesOpen a business for one of your userspartner
GET/v1/partner/businesses/{id}One business you openedpartner
GET/v1/partner/businesses/{id}/keysKeys you created for the businesspartner
POST/v1/partner/businesses/{id}/keysCreate another key for the businesspartner
DELETE/v1/partner/businesses/{id}/keys/{keyId}Revoke a key you createdpartner

קבצים

OpenAPI · Postman