KWNDevelopersالعربيةOpen KWN

API reference

Products

The product catalogue, with the app’s rules: VAT 5 or 0, a barcode used once.

List products

GET/products

Needs
products.read
Scopes
sales:readpurchase:readaccounting:read

Newest first: search by name or internal reference, sku, barcode, active=false for the archived.

Parameters

FieldTypeDescription
searchQuerystring
skuQuerystring
barcodeQuerystring
activeQueryboolean
limitQueryinteger1 to 200; 50 by default.
cursorQuerystringThe previous page's next.
updatedSinceQuerydateOnly rows changed at or after this instant.
createdFromQuerydate
createdToQuerydate
externalIdQuerystringOnly the row your system gave this id.

Code samples

curl -sS -X GET "https://app.kwn.tax/api/v1/products" \
  -H "X-Api-Key: $KWN_API_KEY"

Responses

  • 200OK
    FieldTypeDescription
    dataobject[]The rows of this page.
    nextstringThe cursor of the next page, to send as ?cursor=; null on the last page.
  • 400Refused: the request or a business rule. The code says which (REQUEST_INVALID, RULE_REFUSED, …).
    Example
    {
      "error": "Lines: at least one line is required.",
      "code": "REQUEST_INVALID"
    }
  • 401No key, a key that is not ours, or one revoked (API_KEY_INVALID); a merchant not active (MERCHANT_INACTIVE).
    Example
    {
      "error": "That API key is not valid, or it was revoked.",
      "code": "API_KEY_INVALID"
    }
  • 403The key's scopes do not carry the capability (APP_NOT_GRANTED, ROLE_TOO_LOW), or the plan lacks the app (APP_LOCKED).
    Example
    {
      "error": "This key's scopes do not include sales.approve.",
      "code": "ROLE_TOO_LOW"
    }
  • 404Not found: another type under this route, or another company's (NOT_FOUND).
    Example
    {
      "error": "Not found.",
      "code": "NOT_FOUND"
    }
  • 409A conflict: an externalId taken, or a change that could not be saved (EXTERNAL_ID_TAKEN, CONFLICT).
    Example
    {
      "error": "That externalId is already used by another record of this company.",
      "code": "EXTERNAL_ID_TAKEN"
    }
  • 429Too many requests: wait retryAfter seconds (RATE_LIMITED).
    Example
    {
      "error": "Too many requests. Wait a little and try again.",
      "code": "RATE_LIMITED"
    }

Create a product

POST/products

Needs
products.write
Scopes
sales:writepurchase:write

Send an Idempotency-Key header.

VAT is 5 (standard) or 0 (zero-rated). A barcode is unique in the company. Requires Idempotency-Key.

Parameters

FieldTypeDescription
Idempotency-KeyHeaderRequiredstring1 to 100 visible ASCII characters, such as a UUID, unique to this request. Sent again with the same request, the first answer is replayed (Idempotent-Replayed: true); with another request, 422 IDEMPOTENCY_KEY_REUSED.

Request body

15 fields
FieldTypeDescription
namestring
unitPricenumberVAT-exclusive sales price.
taxRatenumberSales VAT percent: 5 or 0; 5 on a new product, what is on file on an update.
skustringInternal reference.
barcodestring
descriptionstring
purchaseDescriptionstring
typeGOODS | SERVICE
uomstring
costPricenumber
purchaseTaxRatenumber
categoryIdstring
saleOkboolean
purchaseOkboolean
externalIdstringYour system's id for it, kept for good. Create only.

Code samples

curl -sS -X POST "https://app.kwn.tax/api/v1/products" \
  -H "X-Api-Key: $KWN_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "Office chair, mesh back",
  "unitPrice": 450,
  "taxRate": 5,
  "sku": "CHR-MESH-01",
  "barcode": "6291041500213",
  "costPrice": 280,
  "externalId": "ITEM-3310"
}'

Responses

  • 201Created
    FieldTypeDescription
    idstring
    namestring
    skustring
    barcodestring
    descriptionstring
    purchaseDescriptionstring
    typeGOODS | SERVICE
    uomstring
    unitPricenumber
    costPricenumber
    taxRatenumber
    purchaseTaxRatenumber
    categoryIdstring
    saleOkboolean
    purchaseOkboolean
    activeboolean
    externalIdstring
    createdAtdate
    updatedAtdate
  • 400Refused: the request or a business rule. The code says which (REQUEST_INVALID, RULE_REFUSED, …).
    Example
    {
      "error": "Lines: at least one line is required.",
      "code": "REQUEST_INVALID"
    }
  • 401No key, a key that is not ours, or one revoked (API_KEY_INVALID); a merchant not active (MERCHANT_INACTIVE).
    Example
    {
      "error": "That API key is not valid, or it was revoked.",
      "code": "API_KEY_INVALID"
    }
  • 403The key's scopes do not carry the capability (APP_NOT_GRANTED, ROLE_TOO_LOW), or the plan lacks the app (APP_LOCKED).
    Example
    {
      "error": "This key's scopes do not include sales.approve.",
      "code": "ROLE_TOO_LOW"
    }
  • 404Not found: another type under this route, or another company's (NOT_FOUND).
    Example
    {
      "error": "Not found.",
      "code": "NOT_FOUND"
    }
  • 409A conflict: an externalId taken, or a change that could not be saved (EXTERNAL_ID_TAKEN, CONFLICT).
    Example
    {
      "error": "That externalId is already used by another record of this company.",
      "code": "EXTERNAL_ID_TAKEN"
    }
  • 422That Idempotency-Key was used for a different request (IDEMPOTENCY_KEY_REUSED).
    Example
    {
      "error": "That Idempotency-Key was used for a different request.",
      "code": "IDEMPOTENCY_KEY_REUSED"
    }
  • 429Too many requests: wait retryAfter seconds (RATE_LIMITED).
    Example
    {
      "error": "Too many requests. Wait a little and try again.",
      "code": "RATE_LIMITED"
    }

Read a product

GET/products/{id}

Needs
products.read
Scopes
sales:readpurchase:readaccounting:read

One product of this company.

Parameters

FieldTypeDescription
idPathRequiredstring

Code samples

curl -sS -X GET "https://app.kwn.tax/api/v1/products/<id>" \
  -H "X-Api-Key: $KWN_API_KEY"

Responses

  • 200OK
    FieldTypeDescription
    idstring
    namestring
    skustring
    barcodestring
    descriptionstring
    purchaseDescriptionstring
    typeGOODS | SERVICE
    uomstring
    unitPricenumber
    costPricenumber
    taxRatenumber
    purchaseTaxRatenumber
    categoryIdstring
    saleOkboolean
    purchaseOkboolean
    activeboolean
    externalIdstring
    createdAtdate
    updatedAtdate
  • 400Refused: the request or a business rule. The code says which (REQUEST_INVALID, RULE_REFUSED, …).
    Example
    {
      "error": "Lines: at least one line is required.",
      "code": "REQUEST_INVALID"
    }
  • 401No key, a key that is not ours, or one revoked (API_KEY_INVALID); a merchant not active (MERCHANT_INACTIVE).
    Example
    {
      "error": "That API key is not valid, or it was revoked.",
      "code": "API_KEY_INVALID"
    }
  • 403The key's scopes do not carry the capability (APP_NOT_GRANTED, ROLE_TOO_LOW), or the plan lacks the app (APP_LOCKED).
    Example
    {
      "error": "This key's scopes do not include sales.approve.",
      "code": "ROLE_TOO_LOW"
    }
  • 404Not found: another type under this route, or another company's (NOT_FOUND).
    Example
    {
      "error": "Not found.",
      "code": "NOT_FOUND"
    }
  • 409A conflict: an externalId taken, or a change that could not be saved (EXTERNAL_ID_TAKEN, CONFLICT).
    Example
    {
      "error": "That externalId is already used by another record of this company.",
      "code": "EXTERNAL_ID_TAKEN"
    }
  • 429Too many requests: wait retryAfter seconds (RATE_LIMITED).
    Example
    {
      "error": "Too many requests. Wait a little and try again.",
      "code": "RATE_LIMITED"
    }

Update a product

PUT/products/{id}

Needs
products.write
Scopes
sales:writepurchase:write

An optional field left out keeps what is on file.

Parameters

FieldTypeDescription
idPathRequiredstring

Request body

15 fields
FieldTypeDescription
namestring
unitPricenumberVAT-exclusive sales price.
taxRatenumberSales VAT percent: 5 or 0; 5 on a new product, what is on file on an update.
skustringInternal reference.
barcodestring
descriptionstring
purchaseDescriptionstring
typeGOODS | SERVICE
uomstring
costPricenumber
purchaseTaxRatenumber
categoryIdstring
saleOkboolean
purchaseOkboolean
externalIdstringYour system's id for it, kept for good. Create only.

Code samples

curl -sS -X PUT "https://app.kwn.tax/api/v1/products/<id>" \
  -H "X-Api-Key: $KWN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "Office chair, mesh back",
  "unitPrice": 450,
  "taxRate": 5,
  "sku": "CHR-MESH-01",
  "barcode": "6291041500213",
  "costPrice": 280,
  "externalId": "ITEM-3310"
}'

Responses

  • 200OK
    FieldTypeDescription
    idstring
    namestring
    skustring
    barcodestring
    descriptionstring
    purchaseDescriptionstring
    typeGOODS | SERVICE
    uomstring
    unitPricenumber
    costPricenumber
    taxRatenumber
    purchaseTaxRatenumber
    categoryIdstring
    saleOkboolean
    purchaseOkboolean
    activeboolean
    externalIdstring
    createdAtdate
    updatedAtdate
  • 400Refused: the request or a business rule. The code says which (REQUEST_INVALID, RULE_REFUSED, …).
    Example
    {
      "error": "Lines: at least one line is required.",
      "code": "REQUEST_INVALID"
    }
  • 401No key, a key that is not ours, or one revoked (API_KEY_INVALID); a merchant not active (MERCHANT_INACTIVE).
    Example
    {
      "error": "That API key is not valid, or it was revoked.",
      "code": "API_KEY_INVALID"
    }
  • 403The key's scopes do not carry the capability (APP_NOT_GRANTED, ROLE_TOO_LOW), or the plan lacks the app (APP_LOCKED).
    Example
    {
      "error": "This key's scopes do not include sales.approve.",
      "code": "ROLE_TOO_LOW"
    }
  • 404Not found: another type under this route, or another company's (NOT_FOUND).
    Example
    {
      "error": "Not found.",
      "code": "NOT_FOUND"
    }
  • 409A conflict: an externalId taken, or a change that could not be saved (EXTERNAL_ID_TAKEN, CONFLICT).
    Example
    {
      "error": "That externalId is already used by another record of this company.",
      "code": "EXTERNAL_ID_TAKEN"
    }
  • 429Too many requests: wait retryAfter seconds (RATE_LIMITED).
    Example
    {
      "error": "Too many requests. Wait a little and try again.",
      "code": "RATE_LIMITED"
    }