Some LUSID entities require you to specify a unique ID when performing an upsert operation. For example, consider the following call to the UpsertTransactions API (unique ID for the transaction in red):
You can use the APIs in the Sequences collection to help automate the process of creating unique values for use in an upsert (or any other) operation.
Creating a sequence
The first step is to create a sequence defining a number of values, and certain characteristics of those values.
Note: A sequence is single use unless you set its
cycle field to true. By default, once you have exhausted the values in a sequence, you cannot obtain them again; this helps ensure values are unique. Only change
cycle to true if you want to generate non-unique values.
- Obtain an API token.
- Call the CreateSequence API for a particular scope in your LUSID domain, specifying a code for the sequence and other characteristics in the body of the request. For example, the following call creates a
test/oddNumbersequence consisting of 10 values, each with a prefix and a number between 1 and 19, in increments of 2 (so
txn-equity-5and so on):
Note the response confirms the operation has succeeded but does not itself return the values:
Obtaining the values in a sequence
You can obtain the values in a sequence either one at a time or in batches.
To do this, call the Next API for the scope and code of the sequence as many times as you need. For example, the first call to Next for the
test/oddNumber sequence :
...retrieves the first two values (to retrieve singly, omit the
The second call to
Next retrieves the next two values, and so on: