{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":[]},"type":"markdown"},"seo":{"title":"Typescript SDK","llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"typescript-sdk","__idx":0},"children":["Typescript SDK"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The eGain API client SDK for TypeScript supports both Node.js and browser environments, offering a modern, type-safe interface for integrating with eGain's Knowledge Portal Manager, AI Services, and Ingestion APIs."]},{"$$mdtype":"Tag","name":"div","attributes":{"style":{"padding":"16px 0","marginBottom":"24px"}},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"https://github.com/eGain/egain-api-typescript","target":"_blank","rel":"noopener noreferrer","className":"github-card","style":{"display":"inline-flex","alignItems":"center","gap":"12px","padding":"12px 24px","border":"1px solid #d1d5db","borderRadius":"8px","backgroundColor":"#fff","color":"#374151","textDecoration":"none","fontSize":"14px","fontWeight":"500"}},"children":[{"$$mdtype":"Tag","name":"svg","attributes":{"width":"20","height":"20","fill":"currentColor","viewbox":"0 0 20 20","xmlns":"http://www.w3.org/2000/svg"},"children":[{"$$mdtype":"Tag","name":"path","attributes":{"fillRule":"evenodd","d":"M10 0C4.477 0 0 4.484 0 10.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0110 4.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.203 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.942.359.31.678.921.678 1.856 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0020 10.017C20 4.484 15.522 0 10 0z","clipRule":"evenodd"},"children":[]}]},"\n    View on GitHub\n  "]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"license","__idx":1},"children":["License"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The following licenses are required to use the SDK:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["If the user is an agent, then the ",{"$$mdtype":"Tag","name":"em","attributes":{},"children":["Knowledge + AI"]}," license is required."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["If the user is a customer, the ",{"$$mdtype":"Tag","name":"em","attributes":{},"children":["Self-Service"]}," and ",{"$$mdtype":"Tag","name":"em","attributes":{},"children":["Advanced Self-Service"]}," licenses must be available."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"sdk-installation","__idx":2},"children":["SDK Installation"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The SDK can be installed with either ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://www.npmjs.com/"},"children":["npm"]},", ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://pnpm.io/"},"children":["pnpm"]},", ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://bun.sh/"},"children":["bun"]}," or ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://classic.yarnpkg.com/en/"},"children":["yarn"]}," package managers."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"npm","__idx":3},"children":["NPM"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"npm add @egain/egain-api-typescript\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"pnpm","__idx":4},"children":["PNPM"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"pnpm add @egain/egain-api-typescript\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"bun","__idx":5},"children":["Bun"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"bun add @egain/egain-api-typescript\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"yarn","__idx":6},"children":["Yarn"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"yarn add @egain/egain-api-typescript\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"blockquote","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["[!NOTE]"," ","This package is published with CommonJS and ES Modules (ESM) support."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"sdk-example-usage","__idx":7},"children":["SDK Example Usage"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"get-article-by-id","__idx":8},"children":["Get Article by ID"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"typescript","header":{"controls":{"copy":{}}},"source":"import { Egain } from \"@egain/egain-api-typescript\";\n\nconst egain = new Egain({\n  accessToken: process.env[\"EGAIN_ACCESS_TOKEN\"] ?? \"\",\n});\n\nasync function run() {\n  const result = await egain.portal.article.getArticleById({\n    acceptLanguage: \"en-US\",\n    portalID: \"PROD-1000\",\n    articleID: \"PROD-2996\",\n    language: \"en-US\",\n    articleAdditionalAttributes: [\n      \"averageRating\",\n    ],\n    customAdditionalAttributes: \"country_name\",\n    publishViewId: \"PROD-3203\",\n    workflowMilestone: \"publish\",\n  });\n\n  console.log(result);\n}\n\nrun();\n\n","lang":"typescript"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"retrieve-chunks","__idx":9},"children":["Retrieve Chunks"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"typescript","header":{"controls":{"copy":{}}},"source":"import { Egain } from \"@egain/egain-api-typescript\";\n\nconst egain = new Egain({\n  accessToken: process.env[\"EGAIN_ACCESS_TOKEN\"] ?? \"\",\n});\n\nasync function run() {\n  const result = await egain.aiservices.retrieve.retrieveChunks({\n    q: \"fair lending\",\n    portalID: \"PROD-1000\",\n    filterUserProfileID: \"PROD-3210\",\n    language: \"en-US\",\n    filterTags: {\n      \"PROD-1234\": [\n        \"PROD-2000\",\n        \"PROD-2003\",\n      ],\n      \"PROD-2005\": [\n        \"PROD-2007\",\n      ],\n    },\n    retrieveRequest: {\n      channel: {\n        name: \"Eight Bank Website\",\n      },\n    },\n  });\n\n  console.log(result);\n}\n\nrun();\n","lang":"typescript"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"authentication","__idx":10},"children":["Authentication"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"per-client-security-schemes","__idx":11},"children":["Per-Client Security Schemes"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This SDK supports the following security scheme globally:"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Name"},"children":["Name"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Type"},"children":["Type"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Scheme"},"children":["Scheme"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Environment Variable"},"children":["Environment Variable"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["accessToken"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["http"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["HTTP Bearer"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["EGAIN_ACCESS_TOKEN"]}]}]}]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["To authenticate with the API the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["accessToken"]}," parameter must be set when initializing the SDK client instance. For example:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"typescript","header":{"controls":{"copy":{}}},"source":"import { Egain } from \"@egain/egain-api-typescript\";\n\nconst egain = new Egain({\n  accessToken: process.env[\"EGAIN_ACCESS_TOKEN\"] ?? \"\",\n});\n\nasync function run() {\n  const result = await egain.portal.article.getArticleById({\n    acceptLanguage: \"en-US\",\n    portalID: \"PROD-1000\",\n    articleID: \"PROD-2996\",\n    language: \"en-US\",\n    articleAdditionalAttributes: [\n      \"averageRating\",\n    ],\n    customAdditionalAttributes: \"country_name\",\n    publishViewId: \"PROD-3203\",\n    workflowMilestone: \"publish\",\n  });\n\n  console.log(result);\n}\n\nrun();\n\n","lang":"typescript"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"error-handling","__idx":12},"children":["Error Handling"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["[",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["EgainError"]},"] is the base class for all HTTP error responses. It has the following properties:"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Property"},"children":["Property"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Type"},"children":["Type"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"Description"},"children":["Description"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["error.message"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["string"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Error message"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["error.statusCode"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["number"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["HTTP response status code eg ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["404"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["error.headers"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Headers"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["HTTP response headers"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["error.body"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["string"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["HTTP body. Can be empty string if no body is returned."]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["error.rawResponse"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["Response"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Raw HTTP response"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["error.data$"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["Optional. Some errors may contain structured data. ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"#error-classes"},"children":["See Error Classes"]},"."]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"example","__idx":13},"children":["Example"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"typescript","header":{"controls":{"copy":{}}},"source":"import { Egain } from \"@egain/egain-api-typescript\";\nimport * as errors from \"egain-api-client/models/errors\";\n\nconst egain = new Egain({\n  accessToken: process.env[\"EGAIN_ACCESS_TOKEN\"] ?? \"\",\n});\n\nasync function run() {\n  try {\n    const result = await egain.portal.article.getArticleById({\n      acceptLanguage: \"en-US\",\n      portalID: \"PROD-1000\",\n      articleID: \"PROD-2996\",\n      language: \"en-US\",\n      articleAdditionalAttributes: [\n        \"averageRating\",\n      ],\n      customAdditionalAttributes: \"country_name\",\n      publishViewId: \"PROD-3203\",\n      workflowMilestone: \"publish\",\n    });\n\n    console.log(result);\n  } catch (error) {\n    // The base class for HTTP error responses\n    if (error instanceof errors.EgainError) {\n      console.log(error.message);\n      console.log(error.statusCode);\n      console.log(error.body);\n      console.log(error.headers);\n\n      // Depending on the method different errors may be thrown\n      if (error instanceof errors.WSErrorCommon) {\n        console.log(error.data$.code); // string\n        console.log(error.data$.developerMessage); // string\n        console.log(error.data$.details); // Detail[]\n        console.log(error.data$.userMessage); // string\n      }\n    }\n  }\n}\n\nrun();\n\n","lang":"typescript"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"server-selection","__idx":14},"children":["Server Selection"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"override-server-url-per-client","__idx":15},"children":["Override Server URL Per-Client"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The default server can be overridden globally by passing a URL to the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["serverURL: string"]}," optional parameter when initializing the SDK client instance. For example:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"typescript","header":{"controls":{"copy":{}}},"source":"import { Egain } from \"@egain/egain-api-typescript\";\n\nconst egain = new Egain({\n  serverURL: \"https://${API_DOMAIN}/knowledge/portalmgr/v4\",\n  accessToken: process.env[\"EGAIN_ACCESS_TOKEN\"] ?? \"\",\n});\n\nasync function run() {\n  const result = await egain.portal.article.getArticleById({\n    acceptLanguage: \"en-US\",\n    portalID: \"PROD-1000\",\n    articleID: \"PROD-2996\",\n    language: \"en-US\",\n    articleAdditionalAttributes: [\n      \"averageRating\",\n    ],\n    customAdditionalAttributes: \"country_name\",\n    publishViewId: \"PROD-3203\",\n    workflowMilestone: \"publish\",\n  });\n\n  console.log(result);\n}\n\nrun();\n\n","lang":"typescript"},"children":[]}]},"headings":[{"value":"Typescript SDK","id":"typescript-sdk","depth":1},{"value":"License","id":"license","depth":3},{"value":"SDK Installation","id":"sdk-installation","depth":2},{"value":"NPM","id":"npm","depth":3},{"value":"PNPM","id":"pnpm","depth":3},{"value":"Bun","id":"bun","depth":3},{"value":"Yarn","id":"yarn","depth":3},{"value":"SDK Example Usage","id":"sdk-example-usage","depth":2},{"value":"Get Article by ID","id":"get-article-by-id","depth":3},{"value":"Retrieve Chunks","id":"retrieve-chunks","depth":3},{"value":"Authentication","id":"authentication","depth":2},{"value":"Per-Client Security Schemes","id":"per-client-security-schemes","depth":3},{"value":"Error Handling","id":"error-handling","depth":2},{"value":"Example","id":"example","depth":3},{"value":"Server Selection","id":"server-selection","depth":2},{"value":"Override Server URL Per-Client","id":"override-server-url-per-client","depth":3}],"frontmatter":{"seo":{"title":"Typescript SDK"}},"lastModified":"2026-02-23T22:00:32.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/developer-portal/sdks/typescript/sdk","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}