API & webhooks

Importing data via the REST API

Overview

When migrating to Kyvento from another system, you transfer your customers and active subscriptions via the Kyvento REST API. This article describes the order of transfer, the endpoints provided for it, and the settings that allow an interrupted import run to be repeated safely.

Only customers also by file: a plain customer base can be transferred from a CSV file without any programming – see Importing customers from a CSV file. There is no file import for subscriptions; you transfer active subscriptions via the same endpoints as your ongoing integration, one record at a time.

Do not recreate invoices you have already issued via the API: every invoice you create (POST /api/v1/invoices) and finalize via the API is a new Kyvento document with its own invoice number. It goes into the DATEV export and into revenue and would bill the service a second time – this also applies to invoices that are still open in your previous system. A payment you record via the API (POST /api/v1/invoices/{invoice}/record-payment) can only be attached to such a Kyvento document, not to an invoice from your previous system. To transfer historical invoices and payments, please contact support – more on this in the "Extensive data transfers" section below.

Requirements

  • A personal access token (see Setting up API access and creating an API key). Pass it with every call in the Authorization: Bearer <token> header.
  • The required abilities on the token: customers:full and subscriptions:full. A token with read-only access is not sufficient for the transfer.
  • All products and coupons referenced by your subscriptions must already exist in Kyvento. Create them beforehand – either in the interface or via POST /api/v1/products and POST /api/v1/coupons; for these two calls the token additionally needs products:full or coupon_codes:full respectively.
  • An export from your previous system in which every record has a unique and permanent identifier. This identifier is required to make the import repeatable.

Order of transfer

Transfer the data in the following order, as each step builds on the IDs from the preceding one. All paths in this article are relative to https://app.kyvento.com – a complete call is therefore, for example, https://app.kyvento.com/api/v1/customers.

Step Record type Endpoint
1 Customers POST /api/v1/customers
2 Subscriptions for those customers POST /api/v1/subscriptions

Step 1: Create customers

Begin with the master data. Three particularities apply here:

  • customer_type is a required field and must contain either business or individual. Among other things, the tax treatment depends on this value.
  • Switch off the portal invitation: without the send_portal_invitation field, Kyvento invites every newly created customer to the customer portal by email, provided the portal and the invitation template are active – in a transfer, that means your entire customer base at once. Set "send_portal_invitation": false if you want to inform your customers yourself and later. Whether an invitation was sent is shown in the response under meta.portal_invitation. While your Kyvento account is in its trial, such emails go to you as the owner instead of the customer.
  • Address fields are passed flat. A nested address object is not supported; street, house number, postal code, city and country are located directly at the top level.
POST /api/v1/customers
Authorization: Bearer 42|aBcDe…
Content-Type: application/json

{
  "customer_type": "business",
  "company_name": "Moorlinden Software GmbH",
  "email": "buchhaltung@moorlinden.example",
  "vat_id": "DE347829165",
  "street": "Musterstraße",
  "house_number": "12",
  "postal_code": "20095",
  "city": "Hamburg",
  "country": "DE",
  "send_portal_invitation": false
}

Please note regarding field names: fields that the endpoint does not recognise are discarded without an error message. A nested address object will therefore result in a customer without an address. We recommend reviewing the first transferred record in the interface before transferring the entire dataset.

Step 2: Create subscriptions

Next, create the active contracts via POST /api/v1/subscriptions – using the customer's identifier from step 1 in the customer field (the public_id value from the response, such as cust_…) and the identifier of the product set up beforehand in the product field. What matters is when billing starts in Kyvento, because that decides whether a period is billed twice:

  • Without start_date or with a past start_date, billing starts on the day of creation. Kyvento then immediately issues a first invoice for the period from the creation day and sends it to the customer like any subscription invoice – for products with a trial, the first invoice is only created when the trial ends. A past start_date only records the original contract start; elapsed periods are not billed retroactively. If your previous system has already billed the current period, it is billed a second time this way.
  • With a past start_date and bill_from_start: true, billing starts on the start_date – meant for a contract that began shortly before creation and has not yet been billed in your previous system. The first invoice then covers the period from that day (prorated up to the next anchor date if the product uses one). This only works while that first period is still running on the day of creation; otherwise Kyvento rejects the request with 409 (SUBSCRIPTION_BILL_FROM_START_TOO_FAR_BACK), and for products with a trial also with 409 (SUBSCRIPTION_BILL_FROM_START_WITH_TRIAL).
  • With a future start_date, the subscription is scheduled: no invoice is created at creation, access and billing only start on that day, and the first invoice is created then. If you set the date to the next billing date of your previous system, the first Kyvento invoice follows on from its last one – until then, however, the subscription is only scheduled, not active.
  • billing_anchor_day (1–31) sets the billing day of the month; the first period then ends on the next such day and is prorated, unless prorated first billing is switched off for your account. Without the field, a calendar anchor of the product (such as the start of the month) applies; otherwise a future start and bill_from_start use the calendar day of the start_date, and every other subscription the day of creation – not the past contract start. For products with a trial the day applies from the first paid period; the trial itself starts with billing, i.e. on the creation day for a past start.

The start_date is a calendar date in YYYY-MM-DD format between 2000-01-01 and 2100-12-31 and applies from 00:00 in your account's time zone. If your plan has a fixed limit on the number of subscriptions, POST /api/v1/subscriptions rejects every creation beyond the quota with 402 (QUOTA_EXCEEDED); the X-Quota-Remaining header of every successful response shows how many were left before that request – one fewer after it. Check the quota before a large import.

To move the next billing date of a subscription that already exists, use POST /api/v1/subscriptions/{subscription}/reschedule-next-renewal. The next_billing_date field accepts a calendar date in YYYY-MM-DD format only; with a calendar anchor it applies at 00:00 in your account's time zone. A first invoice already issued at creation is not affected by this.

If you scheduled a subscription with a future start_date and chose the wrong date, correct it while the subscription has not started yet with POST /api/v1/subscriptions/{subscription}/reschedule-start – without cancelling and re-creating it. Here too, the start_date field accepts YYYY-MM-DD only, is read in your account's time zone and must be after today. Kyvento then plans the subscription as if it had been created with this date. A subscription that has already started can no longer be moved this way.

Repeatability via the idempotency key

An import run may be interrupted for technical reasons, for example by a dropped connection. Both endpoints therefore support the Idempotency-Key header – a unique value of your choosing; no particular format such as UUID is required. Kyvento remembers the key and the response for 24 hours: if the same key arrives again within that time with an identical request body, you receive the original response (header X-Idempotency-Replayed: true) without a second record being created. The same key with a changed body is rejected with 422 (error_code: IDEMPOTENCY_KEY_MISMATCH). After the 24 hours the safeguard no longer applies – so before repeating an import run that was interrupted for longer, check for records that were already created.

Lasting protection via external_uid: customers and subscriptions accept the identifier from your previous system in the external_uid field. It is unique per account – a second record with the same identifier is rejected, even after the 24 hours have passed. Use the ?external_uid=… filter on the respective list to find a record that was already transferred.

For the idempotency key to take effect on a repeated run, the key must be derived from the source record and be identical on every pass – for example as a UUID v5 over a string of the form previous-system:customer:4711. A random key generated per attempt cancels out the effect: the second run then does not receive the original response but runs into the uniqueness rules – a customer with the same email address is rejected with 422, and a second active, scheduled or trialing subscription of the same customer for the same product is refused with 409 (SUBSCRIPTION_DUPLICATE_ACTIVE) as long as your account does not allow multiple bookings of the same product. The flip side: two previous customers with the same email address, or two active contracts for the same product for one customer, cannot be transferred this way.

POST /api/v1/customers
Authorization: Bearer 42|aBcDe…
Idempotency-Key: 8c4f1e2a-5d7b-5f3c-9a1e-6b2d4c8e0f37
Content-Type: application/json

VAT identification numbers

A vat_id that is passed in is validated against the EU VIES portal after creation, not during it. The customer is created in any case and receives a validation status that you can query later (GET /api/v1/customers/{customer}/vat-id-status). We recommend not pausing the import until the validation result is available, as the availability of VIES is outside our sphere of influence. Transfer the complete dataset first and evaluate the validation statuses afterwards.

Rate limits

The same per-minute limits apply to a data transfer as to any other API use on your plan. Evaluate the X-RateLimit-Remaining header and, when a response returns status 429, observe the waiting period specified in the Retry-After header; a fixed waiting period leads either to further failed attempts or to unnecessary delay. Further guidance can be found in API rate limits and best practices.

Verifying success

  1. Trial run with a single record: begin by transferring one customer with one subscription.
  2. Review in the interface: are the customer's address and VAT identification number complete? Are the subscription's status and next billing date correct, and – if a first invoice was created at creation – has its period not already been billed in your previous system?
  3. Verify repeatability: run the same record through your script a second time within 24 hours. With stably derived keys you receive the original response with the header X-Idempotency-Replayed: true; if you get a rejection instead (for example 422 because of the email address), the keys are not stable and should be adjusted before the full transfer.
  4. Complete transfer and reconciliation: finally, compare the number of customers and subscriptions against your previous system.

If it does not work

  • Customer without an address: the address fields were passed nested and were therefore discarded. Use the flat field names from step 1.
  • Status 401 or 403: the token is missing, has expired, or does not hold the required ability (customers:full, subscriptions:full).
  • Status 429: the rate limit has been reached. Continue the transfer after the waiting period specified in Retry-After.
  • A repeated run is rejected: the record already exists – for customers (email address, external_uid) with status 422, for a second subscription to the same product for the same customer with status 409 and the error code SUBSCRIPTION_DUPLICATE_ACTIVE –, and the idempotency key did not match or was older than 24 hours. Find the record via ?external_uid=… and derive the keys from the identifier of the source record.
  • A customer is rejected with 422 although they are new: another customer in Kyvento already has the same email address; customer email addresses are unique per account (case-insensitive).

Extensive data transfers

You do not have to carry out extensive or complex data transfers yourself. We offer data imports and migrations – including the transfer of historical invoices and payments – as a paid additional service; orders are placed in advance through an individual agreement covering scope and content.

Please contact support@kyvento.com and let us know which system you are migrating from and what volume of data is to be transferred. You will then receive a quote covering the applicable costs.

Next steps

← Back to Support

Related articles

API & webhooks

Verifying a webhook endpoint

Overview Kyvento delivers webhook events exclusively to verified endpoints. Verification establishes that the configured...

API & webhooks

Setting up the Stripe webhook

Overview A webhook is Stripe's way of reporting back to Kyvento: whenever something happens in Stripe that Kyvento needs...

API & webhooks

Setting up the PayPal webhook

Overview A webhook is PayPal's way of reporting back to Kyvento: whenever something happens in PayPal that Kyvento needs...