Collection
In the Nostradamus platform, a collection is a structured set of data that you store and manage. Think of a collection as a specialized database that holds all the relevant information for a particular entity.
When you create a new collection in the Nostradamus platform, it starts out empty. There won't be any data present initially. You will need to import your data into this new collection to start using it effectively.
How to create a collection
To create a collection, you need to send a POST request to the collection endpoint. Required parameters to be specified in the request body are:
name: the name of your choice;product: ChurnPrediction;timezone: the default timezone for the collection, you can specify any timezone from the IANA Time Zone Database.
Additionally you can specify:
tag: Additional metadata that can be associated to the collection.
Churn Prediction allows to specify the following properties in the collection creation request:
subscription: optional property as a object containing additional subscription properties;invoice: optional property as a object containing additional invoice properties;subscription_item: optional property as a object containing additional subscription item properties;usage: required property as a object containing additional usage properties, it requires to specify at least thetypeproperty that has to be a requiredenumproperty with the specification of its possible values;ticket: required property as a object containing additional ticket properties, it requires to specify at least thetypeproperty that has to be a requiredenumproperty with the specification of its possible values;interaction: required property as a object containing additional interaction properties, it requires to specify at least thetypeproperty that has to be a requiredenumproperty with the specification of its possible values.
The expected input format for the object containing the additional data type properties is:
- key: the property name;
- value: an object with the following keys:
type: a string indicating the data type of the property, it can be one ofenum,boolean,number,integer,date,date-time,string;required: a boolean indicating if the property is required;possibleValues: the list of possible values for the property (only for a property of typeenum).
- Curl
- Python
curl --location 'https://nostradamus.u-hopper.com/api/collection' \
--header 'Content-Type: application/json' \
--header 'Authorization: Token my-secret-token' \
--data '{
"name": "My Collection",
"product": "ChurnPrediction",
"timezone": "Europe/Rome",
"tag": {},
"properties": {
"subscription": {
"social_source": {
"type": "enum",
"required": false,
"possibleValues": ["facebook", "twitter", "linkedin"]
}
},
"usage": {
"type": {
"type": "enum",
"required": true,
"possibleValues": ["login", "view", "purchase"]
}
},
"ticket": {
"type": {
"type": "enum",
"required": true,
"possibleValues": ["incident", "request"]
}
},
"interaction": {
"type": {
"type": "enum",
"required": true,
"possibleValues": ["phone", "email", "chat"]
}
}
}
}'
import requests
import json
url = "https://nostradamus.u-hopper.com/api/collection"
payload = json.dumps({
"name": "My Collection",
"product": "ChurnPrediction",
"timezone": "Europe/Rome",
"tag": {},
"properties": {
"subscription": {
"social_source": {
"type": "enum",
"required": false,
"possibleValues": ["facebook", "twitter", "linkedin"]
}
},
"usage": {
"type": {
"type": "enum",
"required": true,
"possibleValues": ["login", "view", "purchase"]
}
},
"ticket": {
"type": {
"type": "enum",
"required": true,
"possibleValues": ["incident", "request"]
}
},
"interaction": {
"type": {
"type": "enum",
"required": true,
"possibleValues": ["phone", "email", "chat"]
}
}
}
})
headers = {
'Content-Type': 'application/json',
'Authorization': 'Token my-secret-token'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
How to list collections
You can retrieve the list of the collections associated to your organization by sending a GET request to the collection endpoint.
- Curl
- Python
curl --location 'https://nostradamus.u-hopper.com/api/collection' \
--header 'Authorization: Token my-secret-token'
import requests
url = "https://nostradamus.u-hopper.com/api/collection"
payload = {}
headers = {
'Authorization': 'Token my-secret-token'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
You will receive a paginated list of collections.
Pagination allows you to control how many records are returned at a time and which part of the list to start from.
You can specify the limit (i.e., the maximum number of records to return per page) and the offset (i.e., the number of records to skip before starting to return results)
by adding the query parameters limit and offset to the request.
How to retrieve a collection
You can retrieve a specific collection by sending a GET request to the collection endpoint with the collection ID.
- Curl
- Python
curl --location 'https://nostradamus.u-hopper.com/api/collection/{my-collection-id}' \
--header 'Authorization: Token my-secret-token'
import requests
url = "https://nostradamus.u-hopper.com/api/collection/{my-collection-id}"
payload = {}
headers = {
'Authorization': 'Token my-secret-token'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
You will receive the details of the collection.
How to update a collection
You can update a collection by sending a PUT request to the collection endpoint with the collection ID.
- Curl
- Python
curl --request PUT --location 'https://nostradamus.u-hopper.com/api/collection/{my-collection-id}' \
--header 'Content-Type: application/json' \
--header 'Authorization: Token my-secret-token' \
--data '{
"name": "My Updated Collection",
"timezone": "Europe/Rome",
"tag": {}
}'
import requests
url = "https://nostradamus.u-hopper.com/api/collection/{my-collection-id}"
payload = json.dumps({
"name": "My Updated Collection",
"timezone": "Europe/Rome",
"tag": {}
})
headers = {
'Content-Type': 'application/json',
'Authorization': 'Token my-secret-token'
}
response = requests.request("PUT", url, headers=headers, data=payload)
print(response.text)
You will receive the updated details of the collection.
How to delete a collection
You can delete a collection by sending a DELETE request to the collection endpoint with the collection ID.
- Curl
- Python
curl --request DELETE --location 'https://nostradamus.u-hopper.com/api/collection/{my-collection-id}' \
--header 'Authorization: Token my-secret-token'
import requests
url = "https://nostradamus.u-hopper.com/api/collection/{my-collection-id}"
payload = {}
headers = {
'Authorization': 'Token my-secret-token'
}
response = requests.request("DELETE", url, headers=headers, data=payload)
print(response.text)
You will receive a confirmation that the collection has been deleted.