Creating Publications
This section explains how to create publications using the Thinkeo API, including uploading documents and handling responses.
Example Application
For this example, we'll use an App that analyzes technical documents on multiple aspects and optionally provides a concise summary of the analysis.
The App structure consists of several blocks:
- API - Document Block: Processes the input document
- API - AI Analysis Block: Executes automatically after document processing
- API - Summary Block: Conditional block that appears when the "Summary" attribute is assigned
The App uses the following attributes:
- Document: File type attribute for the input document
- Analysis: Text type attribute with values "Short" or "Detailed"
- Specific: Text type attribute for specifying analysis focus
- Summary: Text type attribute (could also be flag type) for enabling summary generation
Creating a Publication via API
To create a publication, you'll need to follow these steps:
1. Upload Document
Before creating a publication, you need to provide a URL for any file attributes. There are two ways to handle this:
Option 1: Store your file somewhere with a public URL that you can reference
Option 2 : Upload your file directly to Thinkeo using a POST Attachment request, then use the returned URL in your publication request
Here's how to upload a file using the second option:
Make a POST request to /attachments with these requirements:
- Authorization header with your bearer token
- Content-Type header matching your file type (see MIME types reference)
- filename header with your desired filename
curl -X POST "https://api.thinkeo.io/v0/attachments" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/pdf" \
-H "filename: document.pdf" \
--data-binary "@/path/to/your/file.pdf"
The server will respond with a JSON object containing the file details:
{
"filename": "document.pdf",
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"sha1": [0],
"url": "https://api.thinkeo.dev/v0/attachments/uuid"
}
You can now use the returned URL as the value for your file attribute when creating a publication.
2. Create Publication
To create a publication, send a POST request to /publications. Here's what you need:
- Bearer token in the Authorization header
- Content-Type: application/json header
- App UUID in the request URL
- Version parameter (use "latest" for production or "preview" for development)
- Attributes and their values in the request body
Example request with our document analysis App:
curl -X POST "https://api.thinkeo.io/v0/publications?appId=0191ea9f-4791-7d40-9e57-c4510181aee1f&version=latest" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
--data '{
"attributes": {
"0191eaa0-5df8-72d0-968a-5ddbbb498a48": ["https://api.thinkeo.dev/v0/attachments/497f6eca-6276-4993-bfeb-53cbbbba6f08"],
"0191eaa3-871f-76a3-8bd2-165649b1e872": ["Detailed"],
"0191eab1-e733-7db0-bff3-86a725c1fb0a": ["Focus on technical implementation"],
"0191eab4-77c0-7f51-97e2-46989dcf6788": [""]
},
"stream": false
}'
3. Understanding the Response
The API returns a JSON object containing a tree structure of blocks. Here's an example response showing the analysis and summary blocks:
{
"publicationId": "93327d8c-28a6-486e-9efe-56c688756cb2",
"rootBlockId": "0191ea9f-4791-7d40-9e57-c4510181aee1",
"blocks": {
"0191eabd-48cb-7de1-9e2c-ae53281cf173": {
"kind": "html",
"content": "Analysis content here..."
},
"0191eac1-4674-7721-81ac-6931c345ddf8": {
"kind": "html",
"content": "Summary content here..."
},
"0191ea9f-4791-7d40-9e57-c4510181aee1": {
"kind": "concatenation",
"content": [
"0191eabd-48cb-7de1-9e2c-ae53281cf173",
"0191eac1-4674-7721-81ac-6931c345ddf8"
]
}
}
}
The response contains two types of blocks:
- HTML blocks (
"kind": "html"
): Contain the actual content - Concatenation blocks (
"kind": "concatenation"
): Define the structure and order of content blocks
To process the response:
- Start with the
rootBlockId
- For HTML blocks: Use the content directly
- For concatenation blocks: Combine all child blocks in order
The final result will be properly formatted HTML content that you can use in your application.
JS snippet
The following JS snippet can be used to perform the request and return the content as an HTML string:
async function thinkeoPublication(token, appId, appVersion, context = {}) {
const res = await fetch(`https:/api.thinkeo.io/v0/publications?app=${appId}&version=${appVersion}`, {
method: "POST",
headers: {
"Authorization": `Bearer ${token}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
attributes: context,
})
})
const { blocks, rootBlockId } = await res.json()
const concatenated = {}
function concatenateContent(id) {
if (concatenated[id]) return concatenated[id]
const block = blocks[id]
switch (block.kind) {
case "concatenation":
concatenated[id] = block.content.map(concatenateContent).join("")
break
case "html":
concatenated[id] = block.content
break
}
return concatenated[id]
}
return concatenateContent(rootBlockId)
}