Import Tags from csv using Python

Quick example how to import tags from CSV file using Slamby Python SDK.

import slamby_sdk
from slamby_sdk.rest import ApiException
import csv

server = "https://europe.slamby.com/demo/"
secret = "s3cr3t"
targetDataset = "demo"

client = slamby_sdk.ApiClient(server)
client.set_default_header("Authorization", "Slamby {0}".format(secret))
client.set_default_header("X-DataSet", targetDataset);

with open('tags.csv') as csvfile: 
    for item in csv.DictReader(csvfile):
        try:
            tag = slamby_sdk.Tag()
            tag.id = item["Id"]
            tag.name = item["Name"]
            slamby_sdk.TagApi(client).create_tag(tag = tag)
        except ApiException as e:
            print(e)

Download this example from here

Leave a Reply

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