Skip to main content

Imports

You can import subscription features, subscribers, offerings and subscriptions using Subscriptions Import. This is useful if you want to import subscriptions from an external system into Elastic Path Subscriptions.

The API uses a JSONL file. Here is an example of a JSONL file.

When you send an import request, an import job is created. Jobs are processed one at a time. You can continue to send import requests, but those jobs are queued. In other words, Subscriptions looks for any jobs that have a status of PENDING and starts the job with the earliest created date. This process is repeated until all jobs are processed. Use List import jobs to see a list of all import jobs.

A file can include up to 50,000 objects. If you have more than 50,000 objects, then you must create a separate file, and import each file, one at a time.

Characteristics of Subscriptions Import​

The Subscriptions Import API has the following characteristics:

  • The Subscriptions Import API reads the entire file and then creates the subscription objects. This means the subscription objects can be in any order in the file.

  • Subscriptions imports are asynchronous and are processed one at a time. You can continue to send import requests, but these are queued.

  • The API works on a "best endeavours" approach. In other words, the API does its best to create the subscription objects based on the file that you provide.

Import modes​

The mode field of an import request sets how the import treats records that already exist. The default is create. In create mode, the import skips a feature or offering when its external_ref already exists in your store.

In both modes, the import skips a subscription line when its external_ref already exists, or when an earlier line in the same file has the same external_ref. The import reports an error for each skipped line, and the rest of the file is still processed.

In upsert mode, a feature or offering line with an external_ref that matches an existing record in your store updates that record. Any other line creates a new record. Upsert applies to features and offerings only. The import never updates subscribers or subscriptions. If a record changes through the API after the import reads it, the line fails and the change through the API is kept.

When a line updates a record, these rules apply:

  • An attribute that the line omits keeps its current value.
  • An attribute that the line sets to null is cleared.
  • For an offering, the import matches each plan and pricing option to a stored one by external_ref. A matched item is updated and keeps its ID. An unmatched item is added. A stored item that the line omits is kept.
  • For each plan that the line names in pricing_option_associations or configured_features, the import sets the pricing options or feature configurations of that plan to exactly the values in the line. A pricing option that the plan had before and the line does not list is no longer linked to that plan. Other plans keep their pricing options and feature configurations.
  • The feature_configurations of a matched plan in the line follow the plan update rules of the API. Each listed feature configuration is set, and a null value removes it.
  • An error about a plan or pricing option names its position in the line, for example plans[0].price_units.amount.
  • The lead_time of a matched pricing option must fit inside the billing interval that the option has after the line is applied.
  • A referenced feature is copied as the import reads it. A change to that feature through the API while the line is applied is not part of the copy. The next import of the line copies it.
  • Every plan and pricing option in an offering line that updates an existing offering must have an external_ref, and each external_ref must be unique within the offering. If not, the line fails.
  • The import validates the merged offering before it saves any change. A matched plan or pricing option follows the same rules as an update through the API, including the length and value limits of its attributes. If the merged offering is not valid, the line fails and the offering does not change.
  • If the line sets to null an attribute that an update through the API cannot clear, such as name, the line fails.
  • An inline feature in the line replaces the inline feature that has the same external_ref. An inline feature without an external_ref is added each time the line is imported.
  • When a referenced or inline feature changes, every plan configuration of that feature must still match its type and promotion tags. If not, the line fails. Set the plan in configured_features to fix the configuration in the same line.

The import job counts updated records under updated in the records meta of the import. Records that the import creates are counted as before.

Import events​

The events field sets which events an import emits for features and offerings. The default is none, because one import can contain many lines. Use updates to emit an updated event for each updated record. Use all to also emit a created event for each created record. Subscriber created events are always emitted, whatever the events value.

Subscriptions Import File​

The following table describes the subscriptions objects, and their attributes, that the import file can include.

ObjectAttributes
A subscriber objectThe attributes you specify for a subscriber object are the attributes you specify when creating a subscriber.
An offering objectThe attributes you specify for an offering object are the attributes you specify when building an offering.
Ask External AI