SDKs

Node.js SDK

The Smartling SDK for Node.js simplifies the use of Smartling’s APIs from Node.js application code by providing a Node library for accessing the underlying REST APIs

The following APIs are included in the Node.js SDK:

The SDK is distributed as an npm package.

Sample code that uses the SDK can be found in the Smartling Samples GitHub repository.

Setup

To use the SDK, you need the following:

  • Node.js installed
  • API token (user identifier and secret) for a Smartling project

Once Node.js is installed, you can install the SDK by entering the command:

npm install smartling-api-sdk-nodejs

Using the SDK

To use the SDK, first import it into your code identifying the parts you want to use. For example:

const {
    Logger,
    SmartlingApiClientBuilder,
    SmartlingJobsApi,
    SmartlingJobBatchesApi,
    SmartlingFilesApi,
    CreateJobParameters,
    CreateBatchParameters,
    UploadBatchFileParameters,
    FileType,
    JobProgressParameters,
    DownloadFileParameters,
    RetrievalType
} = require("smartling-api-sdk-nodejs");

Then create a factory for building specific API clients:

const apiBuilder = new SmartlingApiClientBuilder()
    .setLogger(console)
    .setBaseSmartlingApiUrl("https://api.smartling.com")
    .authWithUserIdAndUserSecret(userId, userSecret);

Finally, create the API clients you need. For example:

const jobsApi = apiBuilder.build(SmartlingJobsApi);
const batchesApi = apiBuilder.build(SmartlingJobBatchesApi);
const filesApi = apiBuilder.build(SmartlingFilesApi);

Making API requests

Each REST API endpoint has a corresponding method on the API client object in the SDK. Calling a method on the API client object results in an HTTP request being sent to the corresponding REST endpoint. Parameters are defined explicitly in the method signature and/or are grouped into a parameters object depending on the method.

For example, in the method representing the Download translated file REST endpoint, projectId, URI and localeId are passed as explicit parameters, whereas the remaining parameters are packaged into a DownloadFileParameters parameter:

const downloadFileParams = new DownloadFileParameters()
                .setRetrievalType(RetrievalType.PUBLISHED);
 
const downloadedFileContent = await filesApi.downloadFile(projectId, fileInfo.fileUri, locale, downloadFileParams);

 

Was this article helpful?