Documentation
API
Project API
Show and create translation projects with the WebTranslateIt Project API, with curl, JavaScript, Python, Ruby and PHP examples.
4 min read
The Project API is composed of 2 endpoints:
Show Project
This endpoint is accessible by both read-write and read-only Project API keys and returns information about your project:
- Project name,
- Locales setup on that project,
- The source language,
- For each file:
- The file
ids and file names. - The time of the file’s last modification.
- The SHA-1 checksum of the file.
fresh: displays if the file hosted on WebTranslateIt is up to date or needs to be regenerated.
- The file
The call should be made using a GET request.
/api/projects/:project_token.format [GET]
Where format is one of xml, json or yaml.
GET
/api/projects/:project_token.jsoncurl "https://webtranslateit.com/api/projects/PROJECT_TOKEN.json"
const response = await fetch(
'https://webtranslateit.com/api/projects/PROJECT_TOKEN.json'
)
const { project } = await response.json()
import requests
response = requests.get(
"https://webtranslateit.com/api/projects/PROJECT_TOKEN.json"
)
project = response.json()["project"]
require 'net/http'
require 'json'
uri = URI('https://webtranslateit.com/api/projects/PROJECT_TOKEN.json')
project = JSON.parse(Net::HTTP.get(uri))['project']
<?php
$ch = curl_init('https://webtranslateit.com/api/projects/PROJECT_TOKEN.json');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$project = json_decode(curl_exec($ch), true)['project'];
curl_close($ch);
Examples:
- yaml: https://webtranslateit.com/api/projects/98e71ee45042066f1053ed900b4e8f4ec1f98451.yaml
- xml: https://webtranslateit.com/api/projects/98e71ee45042066f1053ed900b4e8f4ec1f98451.xml
- json: https://webtranslateit.com/api/projects/98e71ee45042066f1053ed900b4e8f4ec1f98451.json
Data structure in YAML:
yaml
project:
name: WebTranslateIt
source_locale:
name: English
code: en
target_locales:
- name: French
code: fr
type: Locale
id: 406
project_files:
- name: config/locales/app/en.yml
updated_at: 2011-04-12 12:49:49 Z
hash_file: 6ec3e8f72c5acfbbf2dbfe4e5d3014bd4144c541
master_project_file_id:
id: 56386
locale_code: en
fresh: true
- name: config/locales/app/fr.yml
updated_at: 2011-04-12 12:49:49 Z
hash_file: 4e4ceeb4557a383dae1571f9d10c3336f92c4ff6
master_project_file_id: 56386
id: 56387
locale_code: fr
fresh: true
Create Project
This endpoint is accessible by the read-write Organization API.
The call should be made using a POST request. The Organization API token is passed as an
organization_api_key parameter rather than in the path, because the project this call creates
does not have a token yet.
/api/projects?organization_api_key=:organization_token [POST]
Parameters
A JSON object modelled after the following:
json
{
"name": "Doughnut",
"url": "https://doughnuts.com",
"description": "A description of the project (Markdown can be used for formatting)",
"icon": "An image file (optional, can be JPG, PNG or GIF)",
"public": "false",
"webhook": "https://webhook.com"
}
name: The project name (mandatory)url: The project URL (optional). An URL linking to your project.description: A project description (optional). Markdown can be used for formattingicon: An image file (optional) passed as a multipart objectpublic: Optional. Sets if the project is open to the public. Can be"true"or"false". If unset, defaults to"false".webhook: Optional. The URL of a webhook.
POST
/api/projects?organization_api_key=:organization_tokencurl -X POST "https://webtranslateit.com/api/projects?organization_api_key=ORGANIZATION_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Doughnut",
"url": "https://doughnuts.com",
"public": "false"
}'
const response = await fetch(
'https://webtranslateit.com/api/projects?organization_api_key=ORGANIZATION_TOKEN',
{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
name: 'Doughnut',
url: 'https://doughnuts.com',
public: 'false'
})
}
)
const { project } = await response.json()
import requests
response = requests.post(
"https://webtranslateit.com/api/projects",
params={"organization_api_key": "ORGANIZATION_TOKEN"},
json={
"name": "Doughnut",
"url": "https://doughnuts.com",
"public": "false",
},
)
project = response.json()["project"]
require 'net/http'
require 'json'
uri = URI('https://webtranslateit.com/api/projects')
uri.query = URI.encode_www_form(organization_api_key: 'ORGANIZATION_TOKEN')
response = Net::HTTP.post(uri, {
name: 'Doughnut',
url: 'https://doughnuts.com',
public: 'false'
}.to_json, 'Content-Type' => 'application/json')
project = JSON.parse(response.body)['project']
<?php
$ch = curl_init('https://webtranslateit.com/api/projects?organization_api_key=ORGANIZATION_TOKEN');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'name' => 'Doughnut',
'url' => 'https://doughnuts.com',
'public' => 'false',
]));
$project = json_decode(curl_exec($ch), true)['project'];
curl_close($ch);
If everything goes well, a JSON representation of your Project will be returned, including the project’s read-write and read-only API tokens.
json
{
"project": {
"name": "Doughnut",
"id": 406,
"created_at": "2022-02-24T23:23:11Z",
"updated_at": "2022-02-24T23:23:11Z",
"source_locale": { },
"url": "https://doughnuts.com",
"description": "A description of the project",
"public": "false",
"webhook": "http://webhook.com",
"icon": "https://link_to_image"
}
}