Skip to main content

Snippets

Snippets is a way to save time on frequently used pieces of text. You can read more about snippet usage in Sapling's support knowledge base. This is the API mechanism for managing snippets for a team. See Team Management for getting the IDs for a particular team.

Team Snippet GET

API key holder must have permissions to read team snippets.

Request Parameters

import requests

key = '<api-key>'
team_id = '<TEAM_ID>'

url = f'https://api.sapling.ai/api/v1/team/{team_id}/snippets'
data = {
'key': key,
}

try:
resp = requests.post(url, json=data)
if 200 <= resp.status_code < 300:
print('Snippets: ', resp['snippets'])
else:
resp_json = resp.json()
print('Error: ', resp_json)
except Exception as e:
print('Error: ', e)

https://api.sapling.ai/api/v1/team/<team_id>/snippets

HTTP method: POST

<team_id>: String (UUID)
ID of a Sapling team.

key: String
32-character API key

usage_stats: Optional Boolean
If usage_stats is present, the response will include all-time usage stats of the returned snippets.

Response Parameters

List of snippets under key snippets.

{
"snippets": []
}

Snippet structure:

{
"id": <str>, // Opaque id, used for management
"plain_text": <str, plain text>, // The snippet stripped of rich text formatting
"rich_text": <str, markdown/html>, // The snippet
"shortcut": <str>, // Expansion shortcut
"team_id": <str, UUID>, // Team ID for snippet
"title": <str>, // Snippet title
"created_at": <str, date>, // e.g. "Wed, 07 Oct 2020 21:15:47 GMT"
"updated_at": <str, date>, // e.g. "Wed, 07 Oct 2020 21:15:47 GMT"
"stale_at": <str, date>, // e.g. "Wed, 07 Oct 2020 21:15:47 GMT"
"expires_at": <str, date>, // e.g. "Wed, 07 Oct 2020 21:15:47 GMT"
"user_id": <str, UUID>, // User that created snippet
"action_count": <int, optional> // Total usage of snippet, returned if usage_stats was present
}