KWNDevelopersالعربيةOpen KWN

API reference

Contacts

One contact book for customers and vendors. Bank details and internal notes never leave KWN.

List contacts

GET/contacts

Needs
contacts.read
Scopes
sales:readpurchase:readcontacts:read

Customers and vendors, newest first: type=customer or vendor, search by name, TRN or email, active=false for the archived. Bank accounts and internal notes are never returned.

Parameters

FieldTypeDescription
typeQuerystringcustomer or vendor.
searchQuerystring
activeQuerybooleantrue (default) for active contacts, false for archived.
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/contacts" \
  -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 contact

POST/contacts

Needs
contacts.write
Scopes
sales:writepurchase:writecontacts:write

Send an Idempotency-Key header.

A customer by default (isCustomer), a vendor with isVendor. A UAE company's TRN is 15 digits. 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

25 fields
FieldTypeDescription
namestring
isCompanyboolean
isCustomerboolean
isVendorboolean
trnstring15 digits for a contact in the UAE.
emailstring
phonestring
mobilestring
websitestring
addressstring
street2string
citystring
zipstring
statestring
emirateABU_DHABI | DUBAI | SHARJAH | AJMAN | UMM_AL_QUWAIN | RAS_AL_KHAIMAH | FUJAIRAH
countrystring
parentIdstring
companyNamestring
paymentTermIdstring
vendorPaymentTermIdstring
fiscalPositionIdstring
salespersonIdstring
creditLimitnumber
tagsstring[]
externalIdstringYour system's id for it, kept for good. Create only.

Code samples

curl -sS -X POST "https://app.kwn.tax/api/v1/contacts" \
  -H "X-Api-Key: $KWN_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "Al Noor Trading L.L.C.",
  "isCompany": true,
  "isCustomer": true,
  "trn": "100398765400003",
  "email": "accounts@alnoor.example",
  "phone": "+971 4 555 0142",
  "address": "Office 1204, Bay Square, Business Bay",
  "city": "Dubai",
  "emirate": "DUBAI",
  "country": "AE",
  "externalId": "CUST-0091"
}'

Responses

  • 201Created
    FieldTypeDescription
    idstring
    customerNostring
    namestring
    isCompanyboolean
    isCustomerboolean
    isVendorboolean
    activeboolean
    trnstring
    emailstring
    phonestring
    mobilestring
    websitestring
    addressstring
    street2string
    citystring
    zipstring
    statestring
    emirateABU_DHABI | DUBAI | SHARJAH | AJMAN | UMM_AL_QUWAIN | RAS_AL_KHAIMAH | FUJAIRAH
    countrystring
    parentIdstring
    companyNamestring
    paymentTermIdstring
    vendorPaymentTermIdstring
    fiscalPositionIdstring
    salespersonIdstring
    creditLimitnumber
    tagsstring[]
    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 contact

GET/contacts/{id}

Needs
contacts.read
Scopes
sales:readpurchase:readcontacts:read

One contact of this company.

Parameters

FieldTypeDescription
idPathRequiredstring

Code samples

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

Responses

  • 200OK
    FieldTypeDescription
    idstring
    customerNostring
    namestring
    isCompanyboolean
    isCustomerboolean
    isVendorboolean
    activeboolean
    trnstring
    emailstring
    phonestring
    mobilestring
    websitestring
    addressstring
    street2string
    citystring
    zipstring
    statestring
    emirateABU_DHABI | DUBAI | SHARJAH | AJMAN | UMM_AL_QUWAIN | RAS_AL_KHAIMAH | FUJAIRAH
    countrystring
    parentIdstring
    companyNamestring
    paymentTermIdstring
    vendorPaymentTermIdstring
    fiscalPositionIdstring
    salespersonIdstring
    creditLimitnumber
    tagsstring[]
    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 contact

PUT/contacts/{id}

Needs
contacts.write
Scopes
sales:writepurchase:writecontacts:write

An optional field left out keeps what is on file.

Parameters

FieldTypeDescription
idPathRequiredstring

Request body

25 fields
FieldTypeDescription
namestring
isCompanyboolean
isCustomerboolean
isVendorboolean
trnstring15 digits for a contact in the UAE.
emailstring
phonestring
mobilestring
websitestring
addressstring
street2string
citystring
zipstring
statestring
emirateABU_DHABI | DUBAI | SHARJAH | AJMAN | UMM_AL_QUWAIN | RAS_AL_KHAIMAH | FUJAIRAH
countrystring
parentIdstring
companyNamestring
paymentTermIdstring
vendorPaymentTermIdstring
fiscalPositionIdstring
salespersonIdstring
creditLimitnumber
tagsstring[]
externalIdstringYour system's id for it, kept for good. Create only.

Code samples

curl -sS -X PUT "https://app.kwn.tax/api/v1/contacts/<id>" \
  -H "X-Api-Key: $KWN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "Al Noor Trading L.L.C.",
  "isCompany": true,
  "isCustomer": true,
  "trn": "100398765400003",
  "email": "accounts@alnoor.example",
  "phone": "+971 4 555 0142",
  "address": "Office 1204, Bay Square, Business Bay",
  "city": "Dubai",
  "emirate": "DUBAI",
  "country": "AE",
  "externalId": "CUST-0091"
}'

Responses

  • 200OK
    FieldTypeDescription
    idstring
    customerNostring
    namestring
    isCompanyboolean
    isCustomerboolean
    isVendorboolean
    activeboolean
    trnstring
    emailstring
    phonestring
    mobilestring
    websitestring
    addressstring
    street2string
    citystring
    zipstring
    statestring
    emirateABU_DHABI | DUBAI | SHARJAH | AJMAN | UMM_AL_QUWAIN | RAS_AL_KHAIMAH | FUJAIRAH
    countrystring
    parentIdstring
    companyNamestring
    paymentTermIdstring
    vendorPaymentTermIdstring
    fiscalPositionIdstring
    salespersonIdstring
    creditLimitnumber
    tagsstring[]
    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"
    }

Archive a contact

POST/contacts/{id}/archive

Needs
contacts.write
Scopes
sales:writepurchase:writecontacts:write

The contact leaves the lists; its documents keep it. Archived already: alreadyDone.

Parameters

FieldTypeDescription
idPathRequiredstring

Code samples

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

Responses

  • 200OK
    FieldTypeDescription
    alreadyDonebooleanTrue when the document was already where the action takes it; nothing changed.
    documentobject
  • 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"
    }

Restore a contact

POST/contacts/{id}/restore

Needs
contacts.write
Scopes
sales:writepurchase:writecontacts:write

Active already: alreadyDone.

Parameters

FieldTypeDescription
idPathRequiredstring

Code samples

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

Responses

  • 200OK
    FieldTypeDescription
    alreadyDonebooleanTrue when the document was already where the action takes it; nothing changed.
    documentobject
  • 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"
    }