Skip to content

API

This module allows you to create application endpoints that can be used to interact with the application from the outside, such as other applications and more.

Sample

index.js
const crowdinModule = require('@crowdin/app-project-module');
const app = crowdinModule.express();
const configuration = {
baseUrl: 'https://123.ngrok.io',
clientId: 'clientId',
clientSecret: 'clientSecret',
name: 'Sample App',
identifier: 'sample-app',
description: 'Sample App description',
dbFolder: __dirname,
imagePath: __dirname + '/' + 'logo.png',
api: {
default: true,
docFile: __filename,
endpoints: [
{
name: 'Generate report',
description: 'Get your report',
url: '/report',
method: 'GET'
}
]
}
};
const crowdinApp = crowdinModule.addCrowdinEndpoints(app, configuration);
/**
* @openapi
* /report:
* get:
* tags:
* - 'Report'
* summary: 'Test'
* operationId: test.report
* parameters:
* -
* name: userId
* in: query
* required: true
* schema:
* type: integer
* example: 102
* responses:
* 200:
* content:
* application/json:
* schema:
* properties:
* data:
* type: object
* properties:
* reportUrl:
* type: string
* example: 'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf'
*/
app.get('/report', async (req, res) => {
try {
const { client, context, subscriptionInfo } = await crowdinApp.establishCrowdinConnection(req);
// check subscribe
// get crowdin data
// endpoint logic
res.status(200).send({ reportUrl: 'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf' });
} catch (e) {
return res.status(403).send({ error: 'Access denied' });
}
});
app.listen(3000, () => console.log('Crowdin app started'));

In this example, we create a new endpoint /report that returns a link to a report. The endpoint is protected by the Crowdin authentication mechanism. It’s described in the OpenAPI format, which allows you to generate documentation for your API.

Configuration

ParameterDescriptionDefault value
defaultEnable default endpoints for other modulestrue
docFilePath to the jsdoc file__filename
endpointsList of custom endpoints-

The endpoints parameter is an array of objects with the following properties:

{
name: string;
url: string;
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
description?: string;
}

Default Endpoints for Project Integration

The Project Integration module automatically includes the API module with the default: true parameter. This means the default endpoints are enabled without additional configuration:

EndpointMethodDescription
/crowdin-filesGETGet a list of synced files
/file-progressGETGet file translation progress
/integration-filesGETGet integration files list
/crowdin-updatePOSTUpdate crowdin data
/integration-updatePOSTUpdate integration data
/settingsGETGet application settings
/settingsPOSTUpdate application settings
/sync-settingsGETGet application sync settings
/sync-settingsPOSTUpdate application sync settings