Text Library API
The Text Library API lets you find, create, change and delete the texts and folders of the Studio Text Library from your own system. This page is about the Text Library in Studio. It is not the standalone Text Library 2 service. The Studio Text Library is described in the overview.
Every host on this page follows the environment you pick here.
The calls are listed in the API reference of the Smartforms API, in the group TextLibrary. The reference is at https://smartforms.metaforce.net/documentation-api.
Before you start
- You need a client with the
api.externalscope for your company. See Authentication. The calls work on your company only. There is no company parameter: the company comes from the token. - The API works on your company’s shared folders. A person’s private Home and the texts in it are not visible.
- Changes are made in Development. Publish the folders to the other environments in Studio, see Environments.
- Every call answers
401 Unauthorizedwithout a valid token and403 Forbiddenwhen the client has no company or no access.
Find folders and texts
curl --location 'https://api.smartforms.metaforce.net/Integrations/textlibrary/search?q=sick&page=0&pageSize=20&sortBy=name' --header 'Authorization: Bearer <your_token>'
| Parameter | What it does |
|---|---|
q | Matches the code, name or description of texts, and the name of folders. Leave it out to list everything. |
page | The page of texts, counted from 0. The default is 0. |
pageSize | Texts on a page. The default is 10 and the largest is 100. |
sortBy | code (the default), name or description. |
descending | true reverses the order. |
The answer has the texts in pages and all matching folders:
{
"texts": {
"items": [
{
"id": "6697afe9b039be06934828bc",
"folderId": "6697afe9b039be06934828aa",
"code": "sick-leave",
"name": "Sick leave letter",
"description": "Standard letter",
"contentType": 1,
"isPublic": true,
"defaultLanguage": "en",
"translations": {
"en": { "content": "Dear employee", "source": 0 }
}
}
],
"page": 0,
"pageSize": 20,
"totalCount": 1,
"totalPages": 1
},
"folders": [
{ "id": "6697afe9b039be06934828aa", "name": "HR letters", "parentFolderId": null, "isDefault": false, "code": "HRDOCS" }
]
}Other reads:
GET /Integrations/textlibrary/folderslists the folders, each with its code. Start here to find the id of a folder.GET /Integrations/textlibrary/texts/{id}reads one text.
Create and change folders
| Call | What it does |
|---|---|
POST /Integrations/textlibrary/folders | Creates a folder. Body: name (required), parentFolderId for a subfolder, and code. Folders go one level deep. |
PUT /Integrations/textlibrary/folders/{id} | Renames a folder or sets its code. A field you leave out keeps its value. An empty code clears the code. A folder cannot be moved. |
DELETE /Integrations/textlibrary/folders/{id} | Deletes a folder. It must have no texts and no subfolders. |
curl --location 'https://api.smartforms.metaforce.net/Integrations/textlibrary/folders' --header 'Content-Type: application/json' --header 'Authorization: Bearer <your_token>' --data '{ "name": "HR letters", "code": "HRDOCS" }'
A code holds letters, digits, dots, dashes and underscores, and is used in references instead of the folder name, so the references keep working if you rename the folder.
Create and change texts
| Call | What it does |
|---|---|
POST /Integrations/textlibrary/texts | Creates a text. folderId and code are required. |
PUT /Integrations/textlibrary/texts/{id} | Changes a text. Send every field: each one is replaced by what you send, so a field you leave out is cleared. Translations are the exception and are merged: a language you leave out keeps its content. folderId and code are required here too. A different folderId moves the text to that folder. |
DELETE /Integrations/textlibrary/texts/{id} | Deletes a text. |
curl --location 'https://api.smartforms.metaforce.net/Integrations/textlibrary/texts' --header 'Content-Type: application/json' --header 'Authorization: Bearer <your_token>' --data '{
"folderId": "6697afe9b039be06934828aa",
"code": "sick-leave",
"name": "Sick leave letter",
"description": "Standard letter",
"contentType": 1,
"isPublic": true,
"defaultLanguage": "en",
"translations": {
"en": { "content": "Dear employee" },
"no": { "content": "Kjære medarbeider" }
}
}'
| Field | Meaning |
|---|---|
folderId, code | The folder, and the code of the text in it. Both are required. |
name, description | Shown in Studio. |
contentType | 0 for plain text, 1 for rich text, 2 for HTML. |
isPublic | true lets people find the text in the Doc Composer. The default is false. |
defaultLanguage | The language used when no other is asked for. |
translations | The content for each language code, for example en or no. Language codes are saved in lower case. source is 0 for a text written by a person. |
A reference to the text in a Smartform is [[ LIB : HRDOCS : sick-leave ]], with the folder code and the text code. See Using Texts.
Rules and errors
- A text
codeis unique in its folder and in the folders under the same top folder. - A folder name is unique at its level, and a folder
codeis unique in your company.
| Answer | When |
|---|---|
400 Bad Request | folderId or code is missing on a text, name is missing or empty on a folder, or the parent of a new folder is itself a subfolder. |
404 Not Found | The text or folder does not exist, is in a private folder, or belongs to another company. |
409 Conflict | The code or name is already used, or a folder to delete still holds texts or subfolders. |