Add and modify document using Python

API version: 0.17.0

In this example let’s check how to modify a document in a dataset. At first we create a document, then using the given document id, update it.

import slamby_sdk
from slamby_sdk.rest import ApiException
import uuid

client = slamby_sdk.ApiClient("https://europe.slamby.com/demo/")
client.set_default_header("Authorization", "Slamby s3cr3t")
client.set_default_header("X-DataSet", "demo")

document = {
              "id":str(uuid.uuid4()),
              "title":"demo",
              "desc":"description",
              "tags":[]
            }

# Create document
try:
    slamby_sdk.DocumentApi(client).create_document(document=document)
except ApiException as e:
    print(e)

# Modify it
document["title"] = "modified title"

# Update it
try:
    slamby_sdk.DocumentApi(client).update_document(id=document["id"],document=document)
except ApiException as e:
    print(e)

Leave a Reply

Your email address will not be published. Required fields are marked *