Skip to content

API


Soko uses Supabase for its backend, which provides a variety of client libraries. In this article, we use the Supabase Python client. You can find the full Python client reference here:

Installing the Client


# Installing
pip install supabase


Client Initialization

After installing the client, you need to initialize it and authenticate.
Each Soko instance has a unique API URL and public API key that specify which instance to use. You can find your instance credentials at Settings > Pipeline > Soko

image.png

You can now use those credentials to initialize the client.
# Init API client
from supabase import create_client, Client
from supabase.lib.client_options import ClientOptions

url: str = "my-soko-api-url"
key: str = "my-soko-api-key"

supabase: Client = create_client(
url, key
)

Authenticate


You can log in to the API using either your password or your personal API key.
# Login into API via email and password
user = supabase.auth.sign_in_with_password({
"email": "user@sokovfx.com",
"password": "mypassword"
})

If you prefer not to use your password in a script, you can authenticate using user API key. Every Soko user has a unique API key, so you can use the personal API key of a service user. A service user is a user with elevated permissions that cannot log into the Soko App but can be used in pipelines, integrations, and scripts. A list of all service users can be found at Settings > Pipeline > Soko

error
Do not share API key or password with anyone!

image.png

To use a personal API key, initialize the client with the API key in the headers. Then you don’t need to call the sign_in_with_password method:
supabase: Client = create_client(
url, key,
options=ClientOptions(
headers={
'userApiKey': "mayapikey",
}
)
)

Using the API

Now that you’re logged in, you can create, read, update, and delete entities.

Query

To fetch data from the API, Supabase exposes a fluent, chainable querying API:
# Query data from API
query_response = (
supabase.table("folders") # <-- database table
.select("*") # <-- query
.eq("id", "ef69ce9a-32de-41d1-98ae-b501024b50d1") # <-- filter
.execute() # <-- run request
)

print(f"query_response: {query_response}")

Create

# Create
payload = {
"id": "ef69ce9a-32de-41d1-98ae-b501024b50d1",
"name": "New task",
"parentId": "ba57780c-402a-4120-8d30-d23171f6b841",
"typeId": "dde97b1a-db0a-45d0-8f6f-ab5be9635884",
"statusId": "3e788227-5759-440c-abe3-8a1abbe3f500",
"folderTypeId": "11c137c0-ee7e-4f9c-91c5-8c77cec22b2c",
"priorityId": "ca74faf6-6d86-11e8-922e-1f8dbe8e60f2",
"projectId": "870dbfeb-7847-4294-8249-e508c1fe85ba",
"plannedHours": 4,
"description": ""
}

create_response = (
supabase.table("folders")
.insert(payload)
.execute()
)

print(f"create_response: {create_response}")

Update

# Update
update_response = (
supabase.table("folders")
.update({
"statusId": "3e788227-5759-440c-abe3-8a1abbe3f500"
})
.eq("id", "ef69ce9a-32de-41d1-98ae-b501024b50d1")
.execute()
)

print(f"update_response: {update_response}")

Upsert

# Upsert
upsert_response = (
supabase.table("folders")
.upsert(payload)
.execute()
)


print(f"upsert_response: {upsert_response}")

Delete

# Delete
delete_response = supabase.table("folders").delete().eq("id", "ef69ce9a-32de-41d1-98ae-b501024b50d1").execute()
print(f"delete_response: {delete_response}")

RPC

We also have some custom functions in Soko that can be called via the RPC method:
rpc_response = supabase.rpc("get_project_by_component_id", {
'component_id': 'ef69ce9a-32de-41d1-98ae-b501024b50d1'
}).execute()

print(f"rpc_response: {rpc_response}")


API Reference

List of all entities and functions can be found at:

Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.