Skip to main content

Webhooks

Get a POST request on your server when a resource language is translated, reviewed, proofread, or filled up, and verify that it came from Transifex.

Written by Antonis Mylonas

Transifex lets you set up a webhook that notifies your server whenever a target language of a resource is fully translated, reviewed, or proofread, or when a translation fill-up finishes. You can then pull translations as soon as they are ready, without checking Transifex for updates.

📝 Note: For webhooks to work, you need a web server to listen for the webhook calls and an application to react to them. Transifex triggers the webhooks automatically.


Add a webhook to a project

You can add webhooks to any project in an organization.

  1. From the Dashboard, go to the project you want to set up webhooks for.

  2. Click Settings. Only Project Maintainers and Organization Administrators can open this menu (see Understanding user roles).

  3. Click the Webhooks tab.

  4. Click Add webhook.

    Project Settings with the Webhooks tab selected and the Add webhook button, both highlighted

  5. In the Add Webhook dialog, enter your webhook URL and, optionally, a secret key. Then choose whether to be notified about all events or only one, and set Status to Active. An inactive webhook isn't triggered.

    The Add Webhook dialog with the URL, Secret Key, Event and Status fields

  6. Click Save Changes.

When a selected event happens, Transifex sends a POST request to your URL. The body of the request is a JSON payload with the variables described in the next section.

You can also list, create, update, and delete webhooks with the Transifex API. In the API, event_type is all_events or one of the event names in the next section, with one difference: for translation_completed_updated, use translation_updated_completed.


Webhook payload

Your callback URL must accept a POST request. The variables in the JSON body depend on the event. The resource_language_stats payload is different and is described at the end of this section.

Variable

Description

project

The slug of the project the notification is for

resource

The slug of the resource the notification is for

language

The language code of the translation that was modified

translated

An integer: the completion percentage of translations for the resource in that language. For a fully reviewed or proofread resource, the payload uses a variable named reviewed or proofread instead of translated.

is_final

In review_completed and proofread_completed: true when no further review step is pending

machine translation, translation memory

In fillup_completed only: how much of the fill-up came from Machine Translation (MT) and from Translation Memory (TM)

tag, url

In task_tag_created and task_tag_completed only: the task's tag and, in task_tag_created, a link to the task's strings in the Editor

event

A string that describes the webhook type. You can use it to filter webhooks.

branch

The branch name, for branched resources. It is included only when the event comes from a branched resource, and only for translation_completed, review_completed, proofread_completed, and translation_completed_updated.

The possible values of event are:

  • translation_completed

  • review_completed

  • proofread_completed

  • fillup_completed

  • translation_completed_updated

  • task_tag_created

  • task_tag_completed

  • resource_language_stats

translation_completed

Transifex triggers this webhook when the target language of a resource is 100% translated. The payload looks like this:

{
"branch": "version/1.5",
"project": "project_slug",
"translated": 100,
"resource": "resource_slug",
"event": "translation_completed",
"language": "lang_code"
}

review_completed

Transifex triggers this webhook when a target language of a resource is 100% reviewed. The payload looks like this:

{
"branch": "version/1.5",
"resource": "resource_slug",
"language": "lang_code",
"reviewed": 100,
"project": "project_slug",
"is_final": true,
"event": "review_completed"
}

is_final is false if the second review step (proofread) is enabled and only the first review step is complete.

proofread_completed

Transifex triggers this webhook when a target language of a resource is 100% proofread. The payload looks like this:

{
"branch": "version/1.5",
"resource": "resource_slug",
"language": "lang_code",
"proofread": 100,
"project": "project_slug",
"is_final": true,
"event": "proofread_completed"
}

translation_completed_updated

Transifex triggers this webhook when a translation is edited in a resource that is already 100% translated.

{
"branch": "version/1.5",
"project": "project_slug",
"translated": 100,
"resource": "resource_slug",
"event": "translation_completed_updated",
"language": "lang_code"
}

📝 Note: In these four events (translation_completed, review_completed, proofread_completed, translation_completed_updated), the payload doesn't include the branch attribute when the update comes from a non-branched resource.

fillup_completed

Transifex triggers this webhook when a translation fill-up finishes for a resource, once for each target language. It fires for fill-ups from Translation Memory, Machine Translation, and Transifex AI. For Transifex AI, it fires both for the automatic fill-up after an upload and for a fill-up started through the Transifex API. To set up fill-ups, see Setting Up Translation Memory Fill-up and Set up Machine Translation.

A fill-up from Translation Memory and Machine Translation:

{
"machine translation": 0,
"resource": "resource_slug",
"language": "lang_code",
"project": "project_slug",
"translated": 50,
"translation memory": 50,
"event": "fillup_completed"
}

A fill-up from Transifex AI:

{
"event": "fillup_completed",
"language": "lang_code",
"machine translation": 0,
"project": "project_slug",
"resource": "resource_slug",
"translated": 100,
"translation memory": 0
}

The payload has no variable for Transifex AI. Strings that Transifex AI filled count in translated, but not in machine translation or translation memory, so both can be 0 after an AI fill-up.

💡 Tip: translated is the completion of the whole resource in that language after the fill-up. A value below 100 means some strings are still untranslated. The payload doesn't say which strings.

task_tag_created

Transifex triggers this webhook when you select a set of strings in the Editor and click Create Task. The payload looks like this:

{
"project": "project_slug",
"language": "lang_code",
"tag": "tag_name",
"url": "https://example.com/org_slug/project_slug/translate/lang_code/resource_slug?q=tags%3AtxtaskENqwertyuiop12",
"event": "task_tag_created"
}

task_tag_completed

Transifex triggers this webhook when a set of strings that already has a task is fully translated. The payload looks like this:

{
"project": "project_slug",
"language": "lang_code",
"tag": "tag_name",
"url": "",
"event": "task_tag_completed"
}

resource_language_stats

You can create this webhook type only through the Transifex API. It isn't available in the UI. Transifex triggers it for these updates:

  • source_edit: update due to source string edits

  • translated: update after string translation

  • untranslated: update when a previously translated string was marked as untranslated

  • reviewed: update after string review

  • unreviewed: update when a previously reviewed string is reverted

  • proofread: update after string proofreading

  • unproofread: update when a previously proofread string is reverted

For each update at the string level, the webhook returns a payload like this one:

{
"action": "updated",
"after": {
"total_strings": 462,
"total_words": 2367,
"translated_strings": 1,
"translated_words": 1,
"translated_strings_percentage": 0.22,
"reviewed_strings": 1,
"reviewed_words": 1,
"reviewed_strings_percentage": 0.22,
"proofread_strings": 1,
"proofread_words": 1,
"proofread_strings_percentage": 0.22,
"completed_strings": 1,
"completed_words": 1,
"completed_strings_percentage": 0.22
},
"before": {
"total_strings": 462,
"total_words": 2367,
"translated_strings": 2,
"translated_words": 11,
"translated_strings_percentage": 0.43,
"reviewed_strings": 2,
"reviewed_words": 11,
"reviewed_strings_percentage": 0.43,
"proofread_strings": 1,
"proofread_words": 1,
"proofread_strings_percentage": 0.22,
"completed_strings": 1,
"completed_words": 1,
"completed_strings_percentage": 0.22
},
"event": "resource_language_stats",
"happened_at": "1698255953.624257",
"language": {
"code": "lang_code"
},
"organization": {
"slug": "organization_slug",
"unique_identifier": "organizations:prY5am32QZdJbW7Z"
},
"project": {
"slug": "project_slug",
"unique_identifier": "projects:M97wXPx9rLLyzjKl"
},
"proofread": false,
"resource": {
"slug": "resource_slug",
"unique_identifier": "resources:MLgZbd5BJram6rWq"
},
"reviewed": false,
"source_edit": false,
"translated": false,
"unproofread": false,
"unreviewed": true,
"untranslated": true
}

One change can trigger several resource_language_stats requests, and they don't always arrive in the order the changes happened. To process them in order, sort them by happened_at, the Unix time of the change in seconds.


Headers

Every webhook request includes Date, Content-Type: application/json, and User-Agent: Transifex. If you set a secret key on the webhook, Transifex also adds the signature headers. Without a secret key, they aren't sent.

Header

Description

X-TX-Signature-V2

The signature calculated by Transifex. Verify this one. Sent only with a secret key.

X-TX-Signature

The earlier signature header, kept for backward compatibility. Sent only with a secret key.

Content-MD5

The MD5 hash of the request body. Sent only with a secret key.

X-TX-Url

The full webhook URL, as it goes into the signature. Sent only with a secret key.

Date

The submission date, which also goes into the signature.

User-Agent

Identifies Transifex as the sender.


Verify a webhook

To check that a webhook comes from Transifex, set a shared secret when you add the webhook. Transifex uses it to calculate the signature in X-TX-Signature-V2. When your server receives the webhook, it calculates the signature the same way and compares the two.

To calculate the signature:

  1. Join these four elements with a newline (\n), one element per line, with no newline after the last one:

    • The method type, for example POST

    • The URL: the value of the X-TX-Url header

    • The submission date, taken from the Date header

    • The MD5 hash of the request body, as a lowercase hexadecimal string

  2. Calculate the HMAC-SHA256 of the joined text, using the shared secret as the key.

  3. Encode the result in Base64, without line breaks.

  4. Compare it with the X-TX-Signature-V2 value, using a constant-time comparison.

⚠️ Warning: Calculate the MD5 hash over the raw request body, exactly as you received it. If you parse the JSON and serialize it again, spacing or key order can change, the hash changes, and the verification fails.

Test values

Use these values to check your implementation. The secret is for testing only.

Method:    POST
URL: https://example.com/transifex/webhook
Date: Fri, 31 May 2024 11:42:12 GMT
Secret: my_shared_secret
Body: {"event": "translation_completed", "language": "el", "project": "project_slug", "resource": "resource_slug", "translated": 100}
MD5: ec84963222ed0bc9cd14d03efd1c6d99
Signature: YDIlugwWef0yEwGpFQ/WOcv67KbIctmir7EiptARkYM=

The samples below return true for these values.

PHP

<?php
function verify_webhook($raw_body, $method, $url, $date_header, $received_signature, $secret) {
$content_md5 = md5($raw_body);
$message = implode("\n", [$method, $url, $date_header, $content_md5]);
$expected_signature = base64_encode(hash_hmac('sha256', $message, $secret, true));
return hash_equals($expected_signature, $received_signature);
}

// In your webhook listener:
$raw_body = file_get_contents('php://input');
$received_signature = $_SERVER['HTTP_X_TX_SIGNATURE_V2'] ?? '';
$url = $_SERVER['HTTP_X_TX_URL'] ?? '';
$date_header = $_SERVER['HTTP_DATE'] ?? '';

if (!verify_webhook($raw_body, 'POST', $url, $date_header, $received_signature, getenv('TRANSIFEX_WEBHOOK_SECRET'))) {
http_response_code(401);
exit;
}

PHP exposes request headers in $_SERVER with an HTTP_ prefix, in uppercase and with underscores.

Node.js

const crypto = require('crypto');

// rawBody is the request body exactly as received (Buffer or string).
// url is the value of the X-TX-Url header.
// dateHeader is the value of the Date header.
function verifyWebhook(rawBody, method, url, dateHeader, receivedSignature, secret) {
const contentMd5 = crypto.createHash('md5').update(rawBody).digest('hex');
const message = [method, url, dateHeader, contentMd5].join('\n');
const expected = crypto
.createHmac('sha256', secret)
.update(message)
.digest('base64');

const expectedBuffer = Buffer.from(expected);
const receivedBuffer = Buffer.from(receivedSignature);
// timingSafeEqual throws if the lengths differ, so check them first.
return (
expectedBuffer.length === receivedBuffer.length &&
crypto.timingSafeEqual(expectedBuffer, receivedBuffer)
);
}

module.exports = { verifyWebhook };

Python

import base64
import hashlib
import hmac

def verify_webhook(raw_body, method, url, date_header, received_signature, secret):
"""Return True if the received X-TX-Signature-V2 value is valid.

raw_body is the request body exactly as received (bytes).
url is the value of the X-TX-Url header.
date_header is the value of the Date header.
"""
content_md5 = hashlib.md5(raw_body).hexdigest()
message = "\n".join([method, url, date_header, content_md5]).encode("utf-8")
digest = hmac.new(secret.encode("utf-8"), message, hashlib.sha256).digest()
expected_signature = base64.b64encode(digest).decode("ascii")
return hmac.compare_digest(expected_signature, received_signature)

Ruby

require 'openssl'
require 'base64'
require 'digest'

# raw_body is the request body exactly as received (String).
# url is the value of the X-TX-Url header.
# date_header is the value of the Date header.
def verify_webhook(raw_body, method, url, date_header, received_signature, secret)
content_md5 = Digest::MD5.hexdigest(raw_body)
message = [method, url, date_header, content_md5].join("\n")
digest = OpenSSL::HMAC.digest('sha256', secret, message)
expected_signature = Base64.strict_encode64(digest)
secure_equal?(expected_signature, received_signature)
end

# Constant-time string comparison.
def secure_equal?(a, b)
return false unless a.bytesize == b.bytesize
a.bytes.zip(b.bytes).reduce(0) { |acc, (x, y)| acc | (x ^ y) }.zero?
end

Use Base64.strict_encode64. Base64.encode64 adds a line break, so the signature never matches.


💡 Tip

Looking for more help? Get support from our Transifex Community Forum!

Find answers or post to get help from Transifex Support and our Community.

Did this answer your question?