Webhook
The module allows you to create subscriptions for events that occur in the Crowdin project or organization. It’s not necessary to subscribe to events every time after creating a new project, events will come from all resources allowed for the application.
Sample
Section titled “Sample”import crowdinModule from '@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: import.meta.dirname, imagePath: import.meta.dirname + '/logo.png', webhooks: [ { events: ['file.added', 'file.updated', 'file.deleted', 'file.reverted'], callback({client, events, webhookContext}) { console.log('File events:', events); } } ]}const crowdinApp = crowdinModule.addCrowdinEndpoints(app, configuration);
app.listen(3000, () => console.log('Crowdin app started'));import crowdinModule from '@crowdin/app-project-module';import type { ClientConfig } from '@crowdin/app-project-module';
const app = crowdinModule.express();
const configuration: ClientConfig = { baseUrl: 'https://123.ngrok.io', clientId: 'clientId', clientSecret: 'clientSecret', name: 'Sample App', identifier: 'sample-app', description: 'Sample App description', dbFolder: import.meta.dirname, imagePath: import.meta.dirname + '/logo.png', webhooks: [ { events: ['file.added', 'file.updated', 'file.deleted', 'file.reverted'], async callback({client, events, webhookContext}) { console.log('File events:', events); } } ]}const crowdinApp = crowdinModule.addCrowdinEndpoints(app, configuration);
app.listen(3000, () => console.log('Crowdin app started'));To register or update webhooks programmatically (for example during app setup), use createOrUpdateWebhook and related helpers from App Functions.
Configuration
Section titled “Configuration”| Parameter | Description |
|---|---|
events | List of events to subscribe the application. See available events. |
callback | This function is called when the app receives events. |
deferResponse | Optional. If true, the HTTP response is sent after webhook processing completes. Default: false, or true with the Cloudflare Workers adapter. |
callback Function
Section titled “callback Function”Parameters
Section titled “Parameters”client- Crowdin API client.events- Array of webhook event objects.webhookContext- Object containing webhook context information:domain- Crowdin domainorganizationId- Organization IDuserId- User ID (user who installed the application)agentId- Agent ID (ifauthenticationTypeiscrowdin_agent)
Delivery
Section titled “Delivery”Crowdin sends the events of an app in one POST /webhooks request, as the events array, and follows its delivery rules: each event is sent once, and the request waits 30 seconds for a 2XX answer. After any other answer or a timeout the event does not come again.
The module answers the request itself:
| Answer | When |
|---|---|
200 | The signature is valid. With deferResponse, the callback has also finished. |
401 | The app is not installed in the organization that sent the request. |
403 | The X-Crowdin-Signature header does not match the request body. |
500 | With deferResponse, the callback threw. The error is logged. |
What this means for the callback:
- Filter the events. They come from every project the app can access, so compare the project in the payload with the one the callback is for.
- With
deferResponse, finish within 30 seconds. The answer waits for the callback, so a slower callback is a failed delivery. For longer work, save what the event needs in the callback and do the work in a background job. - Catch up on what was missed. An event sent while the app was unavailable is gone, so an app that must not miss a change also reads the state through the API, for example on a schedule.
Cloudflare Workers
Section titled “Cloudflare Workers”The Cloudflare Workers adapter sets deferResponse: true on every webhook that does not set the option, so the example below is only needed when you wire the Worker yourself. Without it, the Worker can stop before webhook processing completes.
webhooks: [{ events: ['file.added', 'file.updated'], deferResponse: true, // Required for Workers callback: async ({ client, events }) => { // Process webhook events for (const event of events) { await processEvent(event, client); } }}]Why needed: Workers terminate execution immediately after HTTP response is sent. deferResponse: true sends the response after callback completion, ensuring proper execution.