Integrations

Webhooks (Strings)

Webhooks notify external services such as chat clients or other external APIs of events. A webhook can set a URL when a specific event takes place.

File uploads only trigger the uploads:create and uploads:processing webhook events.

Webhook response

A webhook endpoint must return an HTTP status code in the 200–299 range within 5 seconds of receiving a callback. Other status codes and request timeouts are considered to be delivery failures. A webhook will be deactivated if delivery fails for more than 10 consecutive events. Callbacks are not repeated.

If receiving a callback, respond within the 5-second request timeout period. To ensure applications don’t accidentally trigger a timeout, defer processing until after the HTTP response has been sent.

Webhook request integrity

Each webhook request includes an X-PhraseApp-Signature header which is generated using the webhook verification token as a secret along with the data sent in the request. Verify that a request origin by computing the HMAC digest of the request body and comparing it to the value in the X-PhraseApp-Signature header.

Examples:

Ruby

def verify_webhook(signatureheader)
  digest = OpenSSL::Digest::Digest.new('sha256')
  hmac = OpenSSL::HMAC.digest(digest, VERIFICATION_TOKEN, request.body)
  hmac = Base64.encode64(hmac).strip
  hmac == signatureheader
end

PHP

function verify_webhook($signatureheader){
  $hmac = hash_hmac('sha256', $requestBody, $verificationToken, true);
  $hmac = trim(base64_encode($hash));
  return $hmac == $signatureheader;
}

Webhook Events

Event name

Description

locales:create

A new language version was created in a project.

locales:update

A language version was changed, renamed or reconfigured.

locales:delete

A language version was deleted.

uploads:create

A locale file was uploaded.

uploads:processing

A locale file was processed.

keys:create

A key was created.

keys:update

A key was renamed or changed.

keys:delete

A key was deleted.

keys:batch_delete

Multiple keys were deleted.

translations:create

A translation of a key in a certain language version was added.

translations:update

A translation of a key in a certain language version was edited.

translations:deliver

A translation of a key in a certain language version was delivered by a language service provider.

translations:review

A translation of a key in a certain language version was reviewed.

comments:create

A comment on a translation key was added.

jobs:start

A job was started.

jobs:complete

A job was marked as complete.

jobs:reopened

A job was reopened.

jobs:locale:complete

A locale of a job was marked as completed.

jobs:locale:reopened

A locale of a job was reopened.

jobs:locale:review:complete

A locale of a job was reviewed and marked as complete.

jobs:locale:review:reopen

A locale of a job was reviewed and reopened.

screenshots:create

A screenshot was created.

screenshots:update

A screenshot was changed or renamed.

screenshots:delete

A screenshot was deleted.

branches:create

A branch was created.

branches:merge

A branch was merged.

Add a Webhook

To add a webhook, follow these steps:

  1. From the Integrations page, scroll down to Webhooks and click Configure.

    The Webhooks page opens.

  2. Click Add Webhook.

    The Add Webhook window opens.

  3. Provide webhook details.

  4. Optionally Include branches.

  5. Click Save. The specified webhook is added the list on the Webhooks page.

A webhook can be deactivated from the More menu of a specific webhook.

Test a Webhook

To test a webhook:

  • From the Webhooks page, select a webhooks and select Send Test Notification from the More menu.

    A notice is presented indicated the test was successful.

Use a service such as RequestBin to capture the contents of a webhook. RequestBin provides a URL that collects request data for inspection.

Using Webhook Data

A POST request is sent to the specified callback URL each time an event of the specified type occurs. The request’s POST payload is a JSON-encoded document with relevant data for the event. The attributes event and message will always be included, along with additional attributes relevant to the event such as the userproject and branch the webhook was triggered from.

Reponse headers

HTTP requests made to the callback URL will contain several special headers.

  • X-PhraseApp-Event: The type of event that triggered the webhook.

  • X-PhraseApp-Signature: The HMAC hex digest of the payload, using the hook's secret as the key.

Example:

Content-Type: application/json
X-PhraseApp-Event: translation:create
X-PhraseApp-Signature: abc123

{
  "event": "translations:create",
  "message": "Peter translated page.help.title in fr.",
  "user": {
    "id": "abcd1234cdef1234abcd1234cdef1234",
    "username": "joe.doe",
    "name": "Joe Doe",
    "email": "joe@phrase.com",
    "position": "Lead Developer",
    "created_at": "2015-01-28T09:52:53Z",
    "updated_at": "2015-01-28T09:52:53Z"
  },
  "project": {
    "id": "abcd1234cdef1234abcd1234cdef1234",
    "name": "My Android Project",
    "main_format": "xml",
    "project_image_url": "http://assets.phrase.com/project.png",
    "account": "account",
    "created_at": "2015-01-28T09:52:53Z",
    "updated_at": "2015-01-28T09:52:53Z"
  },
  "branch": {
  "name": "branch_name"
  },
  "translation": {
    "id": "abcd1234cdef1234abcd1234cdef1234",
    "content": "My translation",
    "unverified": false,
    "excluded": false,
    "plural_suffix": "",
    "key": {
      "id": "abcd1234cdef1234abcd1234cdef1234",
      "name": "home.index.headline",
      "plural": false
    },
    "locale": {
      "id": "abcd1234cdef1234abcd1234cdef1234",
      "name": "de",
      "code": "de-DE"
    },
    "placeholders": [
      "%{count}"
    ],
    "created_at": "2015-01-28T09:52:53Z",
    "updated_at": "2015-01-28T09:52:53Z"
  }
}

Use Webhooks for Slack Integration

Slack is a platform for centralized team communication. Slack offers integrations that automatically pulls information and activity from outside tools into Slack in a way that’s timely, relevant and searchable.

If not using the Slack plugin, webhooks can be manually setup to provide integration.

To integrate notifications generated by a webhook into a Slack channel, set up an incoming webhook within Slack to obtain a webhook URL. This webhook URL can be set it as the callback URL for a webhook.

A POST request is sent to the provided URL each time an event of the specified type occurs. The request’s POST payload is a JSON-encoded document with relevant data that Slack can use to display a short description of the event in a specified channel.

Example payload:

{
  "text": "Andre has updated a translation in project: 'my project'",
  "username": "PhraseApp"
}
Was this article helpful?

Sorry about that! In what way was it not helpful?

The article didn’t address my problem.
I couldn’t understand the article.
The feature doesn’t do what I need.
Other reason.

Note that feedback is provided anonymously so we aren't able to reply to questions.
If you'd like to ask a question, submit a request to our Support team.
Thank you for your feedback.