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.
API Module Read more on the Crowdin Developer Portal.
Sample
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
Parameter | Description | Default value |
---|---|---|
default | Enable default endpoints for other modules | true |
docFile | Path to the jsdoc file | __filename |
endpoints | List 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:
Endpoint | Method | Description |
---|---|---|
/crowdin-files | GET | Get a list of synced files |
/file-progress | GET | Get file translation progress |
/integration-files | GET | Get integration files list |
/crowdin-update | POST | Update crowdin data |
/integration-update | POST | Update integration data |
/settings | GET | Get application settings |
/settings | POST | Update application settings |
/sync-settings | GET | Get application sync settings |
/sync-settings | POST | Update application sync settings |