Theneo SDK
The Theneo SDK is a comprehensive package designed to simplify API requests to the Theneo API, enabling easy integration of Theneo's features into various applications. This SDK abstracts the complexities of API requests and error handling, providing a more streamlined experience for developers.
This documentation provides an overview of the Theneo SDK package. The SDK package includes classes and interfaces for working with the Theneo API. Theneo is a platform for managing API documentation projects.
You can find the Github repository here
Install
Install the Theneo SDK Package: Use npm to install the Theneo SDK package:
npm install @theneo/sdkUsage
To use the Theneo SDK package, import the necessary classes and interfaces, and create an instance of the Theneo class with the required options. Then, you can use the methods provided by the SDK to interact with the Theneo API.
import { Theneo, TheneoOptions, Result, Workspace, ProjectSchema, CreateProjectOptions } from "@theneo/sdk";// Define Theneo optionsconst options: TheneoOptions = { apiKey: "YOUR_API_KEY"};// Create a Theneo instanceconst theneo = new Theneo(options);// Example usageasync function listWorkspaces() { const result: Result<Workspace[]> = await theneo.listWorkspaces(); if (result.ok) { const workspaces: Workspace[] = result.unwrap(); console.log("Workspaces:", workspaces); } else { console.error("Error:", result.unwrap()); }}// Create a new projectasync function createProject() { const projectOptions: CreateProjectOptions = { name: "My Project", workspace: { key: "workspace-key" }, publish: true, isPublic: true, data: { // Specify the data source using one of the following attributes: // 1. Import from a file // file: '/path/to/api-documentation.json', // 2. Import from a URL // link: 'https://example.com/api-documentation.json', // 3. Import from a text string // text: 'API documentation content as a string', // 4. Import from a Postman collection // postman: { // apiKey: 'YOUR_POSTMAN_API_KEY', // collectionIds: ['collection-id-1', 'collection-id-2'], // }, } as ApiDataInputOption }; const result: Result<CreateProjectResponse> = await theneo.createProject(projectOptions); if (result.ok) { const createdProject: CreateProjectResponse = result.unwrap(); console.log("Created Project:", createdProject); } else { console.error("Error:", result.unwrap()); }}// Use the SDK methods as neededlistWorkspaces();createProject();Import API documentation
An example demonstrating how to use the importProjectDocument method to import API documentation to an existing project using the Theneo SDK in TypeScript:
import { Theneo, TheneoOptions, Result, ImportProjectOptions, ImportResponse, ApiDataInputOption } from "@theneo/sdk";// Define Theneo optionsconst options: TheneoOptions = { apiKey: "YOUR_API_KEY"};// Create a Theneo instanceconst theneo = new Theneo(options);// Define the import optionsconst importOptions: ImportProjectOptions = { projectId: "project-id", // Replace with the actual project ID publish: true, // Set to true if you want to publish the imported data data: { // Specify the data source using one of the following attributes: // 1. Import from a file // file: '/path/to/api-documentation.json', // 2. Import from a URL // link: 'https://example.com/api-documentation.json', // 3. Import from a text string // text: 'API documentation content as a string', // 4. Import from a Postman collection // postman: { // apiKey: 'YOUR_POSTMAN_API_KEY', // collectionIds: ['collection-id-1', 'collection-id-2'], // }, } as ApiDataInputOption};// Import API documentation to the projectasync function importApiDocumentation() { const result: Result<ImportResponse> = await theneo.importProjectDocument(importOptions); if (result.ok) { const importResponse: ImportResponse = result.unwrap(); console.log("Imported API Documentation:", importResponse); } else { console.error("Error:", result.unwrap()); }}// Run the import functionimportApiDocumentation();In this example:
- We first create an instance of the
Theneoclass and provide the necessary API key in theoptionsobject. - We define the import options in the
importOptionsobject. You should replace'project-id'with the actual ID of the project where you want to import the API documentation. - Inside the
dataattribute ofimportOptions, you can specify the source of the API documentation to be imported. You can choose one of the four options:- Import from a file (specify the file path).
- Import from a URL (specify the URL).
- Import from a text string (specify the content as a string).
- Import from a Postman collection (specify the Postman API key and collection IDs).
- The
publishoption is set totrueto indicate that the imported data should be published. - The
importApiDocumentationfunction uses theimportProjectDocumentmethod to perform the import operation.
Make sure to replace the placeholder values ('YOUR_API_KEY', 'project-id', and any others) with your actual API key and project details before running the code.
What made this section unhelpful for you?
On this page
- Theneo SDK