cURL
curl "https://api.phrase.com/v2/projects/:project_id/keys" \
-u USERNAME_OR_ACCESS_TOKEN \
-X POST \
-F branch=my-feature-branch \
-F name=home.index.headline \
-F description=Some%20description%20worth%20knowing... \
-F name_plural=home.index.headlines \
-F data_type=number \
-F tags=awesome-feature,needs-proofreading \
-F max_characters_allowed=140 \
-F screenshot=@/path/to/my/screenshot.png \
-F custom_metadata[property]=valuephrase keys create \
--project_id <project_id> \
--data '{"branch":"my-feature-branch", "name":"home.index.headline", "description": "Some description worth knowing...", "name_plural":"home.index.headlines", "data_type":"number", "tags":"awesome-feature,needs-proofreading", "max_characters_allowed":"140", "screenshot":"/path/to/my/screenshot.png", "custom_metadata": {"property" => "value"}}' \
--access_token <token>import requests
url = "https://api.phrase.com/v2/projects/{project_id}/keys"
payload = {
"name": "home.index.headline",
"branch": "my-feature-branch",
"description": "Some description worth knowing...",
"plural": None,
"use_ordinal_rules": None,
"name_plural": "home.index.headlines",
"data_type": "number",
"tags": "awesome-feature,needs-proofreading",
"max_characters_allowed": 140,
"screenshot": "/path/to/my/screenshot.png",
"remove_screenshot": None,
"unformatted": None,
"default_translation_content": "Default translation content",
"autotranslate": None,
"xml_space_preserve": None,
"original_file": None,
"localized_format_string": None,
"localized_format_key": None,
"custom_metadata": {
"fruit": "Apple",
"vegetable": "Tomato"
},
"excluded_in_locales": ["de", "fr"],
"format_value_type": "string"
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: 'home.index.headline',
branch: 'my-feature-branch',
description: 'Some description worth knowing...',
plural: null,
use_ordinal_rules: null,
name_plural: 'home.index.headlines',
data_type: 'number',
tags: 'awesome-feature,needs-proofreading',
max_characters_allowed: 140,
screenshot: '/path/to/my/screenshot.png',
remove_screenshot: null,
unformatted: null,
default_translation_content: 'Default translation content',
autotranslate: null,
xml_space_preserve: null,
original_file: null,
localized_format_string: null,
localized_format_key: null,
custom_metadata: {fruit: 'Apple', vegetable: 'Tomato'},
excluded_in_locales: ['de', 'fr'],
format_value_type: 'string'
})
};
fetch('https://api.phrase.com/v2/projects/{project_id}/keys', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.phrase.com/v2/projects/{project_id}/keys",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => 'home.index.headline',
'branch' => 'my-feature-branch',
'description' => 'Some description worth knowing...',
'plural' => null,
'use_ordinal_rules' => null,
'name_plural' => 'home.index.headlines',
'data_type' => 'number',
'tags' => 'awesome-feature,needs-proofreading',
'max_characters_allowed' => 140,
'screenshot' => '/path/to/my/screenshot.png',
'remove_screenshot' => null,
'unformatted' => null,
'default_translation_content' => 'Default translation content',
'autotranslate' => null,
'xml_space_preserve' => null,
'original_file' => null,
'localized_format_string' => null,
'localized_format_key' => null,
'custom_metadata' => [
'fruit' => 'Apple',
'vegetable' => 'Tomato'
],
'excluded_in_locales' => [
'de',
'fr'
],
'format_value_type' => 'string'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.phrase.com/v2/projects/{project_id}/keys"
payload := strings.NewReader("{\n \"name\": \"home.index.headline\",\n \"branch\": \"my-feature-branch\",\n \"description\": \"Some description worth knowing...\",\n \"plural\": null,\n \"use_ordinal_rules\": null,\n \"name_plural\": \"home.index.headlines\",\n \"data_type\": \"number\",\n \"tags\": \"awesome-feature,needs-proofreading\",\n \"max_characters_allowed\": 140,\n \"screenshot\": \"/path/to/my/screenshot.png\",\n \"remove_screenshot\": null,\n \"unformatted\": null,\n \"default_translation_content\": \"Default translation content\",\n \"autotranslate\": null,\n \"xml_space_preserve\": null,\n \"original_file\": null,\n \"localized_format_string\": null,\n \"localized_format_key\": null,\n \"custom_metadata\": {\n \"fruit\": \"Apple\",\n \"vegetable\": \"Tomato\"\n },\n \"excluded_in_locales\": [\n \"de\",\n \"fr\"\n ],\n \"format_value_type\": \"string\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.phrase.com/v2/projects/{project_id}/keys")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"home.index.headline\",\n \"branch\": \"my-feature-branch\",\n \"description\": \"Some description worth knowing...\",\n \"plural\": null,\n \"use_ordinal_rules\": null,\n \"name_plural\": \"home.index.headlines\",\n \"data_type\": \"number\",\n \"tags\": \"awesome-feature,needs-proofreading\",\n \"max_characters_allowed\": 140,\n \"screenshot\": \"/path/to/my/screenshot.png\",\n \"remove_screenshot\": null,\n \"unformatted\": null,\n \"default_translation_content\": \"Default translation content\",\n \"autotranslate\": null,\n \"xml_space_preserve\": null,\n \"original_file\": null,\n \"localized_format_string\": null,\n \"localized_format_key\": null,\n \"custom_metadata\": {\n \"fruit\": \"Apple\",\n \"vegetable\": \"Tomato\"\n },\n \"excluded_in_locales\": [\n \"de\",\n \"fr\"\n ],\n \"format_value_type\": \"string\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.phrase.com/v2/projects/{project_id}/keys")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"home.index.headline\",\n \"branch\": \"my-feature-branch\",\n \"description\": \"Some description worth knowing...\",\n \"plural\": null,\n \"use_ordinal_rules\": null,\n \"name_plural\": \"home.index.headlines\",\n \"data_type\": \"number\",\n \"tags\": \"awesome-feature,needs-proofreading\",\n \"max_characters_allowed\": 140,\n \"screenshot\": \"/path/to/my/screenshot.png\",\n \"remove_screenshot\": null,\n \"unformatted\": null,\n \"default_translation_content\": \"Default translation content\",\n \"autotranslate\": null,\n \"xml_space_preserve\": null,\n \"original_file\": null,\n \"localized_format_string\": null,\n \"localized_format_key\": null,\n \"custom_metadata\": {\n \"fruit\": \"Apple\",\n \"vegetable\": \"Tomato\"\n },\n \"excluded_in_locales\": [\n \"de\",\n \"fr\"\n ],\n \"format_value_type\": \"string\"\n}"
response = http.request(request)
puts response.read_body{
"id": "abcd1234cdef1234abcd1234cdef1234",
"name": "home.index.headline",
"description": "My description for this key...",
"name_hash": "1b31d2580ce324f246f66b3be00ed399",
"plural": false,
"use_ordinal_rules": false,
"tags": [
"awesome-feature",
"needs-proofreading"
],
"data_type": "string",
"created_at": "2015-01-28T09:52:53Z",
"updated_at": "2015-01-28T09:52:53Z",
"name_plural": "home.index.headlines",
"comments_count": 2,
"max_characters_allowed": 140,
"screenshot_url": "http://assets.example.com/screenshot.png",
"unformatted": false,
"xml_space_preserve": false,
"original_file": "",
"format_value_type": "",
"creator": {
"id": "abcd1234cdef1234abcd1234cdef1234",
"username": "joe.doe",
"name": "Joe Doe"
},
"custom_metadata": {
"fruit": "Apple",
"vegetable": "Tomato"
}
}{
"message": "Validation Failed",
"errors": [
{
"resource": "Resource",
"field": "name",
"message": "can't be blank"
}
]
}Keys
Create a key
Create a new key.
POST
/
projects
/
{project_id}
/
keys
cURL
curl "https://api.phrase.com/v2/projects/:project_id/keys" \
-u USERNAME_OR_ACCESS_TOKEN \
-X POST \
-F branch=my-feature-branch \
-F name=home.index.headline \
-F description=Some%20description%20worth%20knowing... \
-F name_plural=home.index.headlines \
-F data_type=number \
-F tags=awesome-feature,needs-proofreading \
-F max_characters_allowed=140 \
-F screenshot=@/path/to/my/screenshot.png \
-F custom_metadata[property]=valuephrase keys create \
--project_id <project_id> \
--data '{"branch":"my-feature-branch", "name":"home.index.headline", "description": "Some description worth knowing...", "name_plural":"home.index.headlines", "data_type":"number", "tags":"awesome-feature,needs-proofreading", "max_characters_allowed":"140", "screenshot":"/path/to/my/screenshot.png", "custom_metadata": {"property" => "value"}}' \
--access_token <token>import requests
url = "https://api.phrase.com/v2/projects/{project_id}/keys"
payload = {
"name": "home.index.headline",
"branch": "my-feature-branch",
"description": "Some description worth knowing...",
"plural": None,
"use_ordinal_rules": None,
"name_plural": "home.index.headlines",
"data_type": "number",
"tags": "awesome-feature,needs-proofreading",
"max_characters_allowed": 140,
"screenshot": "/path/to/my/screenshot.png",
"remove_screenshot": None,
"unformatted": None,
"default_translation_content": "Default translation content",
"autotranslate": None,
"xml_space_preserve": None,
"original_file": None,
"localized_format_string": None,
"localized_format_key": None,
"custom_metadata": {
"fruit": "Apple",
"vegetable": "Tomato"
},
"excluded_in_locales": ["de", "fr"],
"format_value_type": "string"
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
name: 'home.index.headline',
branch: 'my-feature-branch',
description: 'Some description worth knowing...',
plural: null,
use_ordinal_rules: null,
name_plural: 'home.index.headlines',
data_type: 'number',
tags: 'awesome-feature,needs-proofreading',
max_characters_allowed: 140,
screenshot: '/path/to/my/screenshot.png',
remove_screenshot: null,
unformatted: null,
default_translation_content: 'Default translation content',
autotranslate: null,
xml_space_preserve: null,
original_file: null,
localized_format_string: null,
localized_format_key: null,
custom_metadata: {fruit: 'Apple', vegetable: 'Tomato'},
excluded_in_locales: ['de', 'fr'],
format_value_type: 'string'
})
};
fetch('https://api.phrase.com/v2/projects/{project_id}/keys', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.phrase.com/v2/projects/{project_id}/keys",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'name' => 'home.index.headline',
'branch' => 'my-feature-branch',
'description' => 'Some description worth knowing...',
'plural' => null,
'use_ordinal_rules' => null,
'name_plural' => 'home.index.headlines',
'data_type' => 'number',
'tags' => 'awesome-feature,needs-proofreading',
'max_characters_allowed' => 140,
'screenshot' => '/path/to/my/screenshot.png',
'remove_screenshot' => null,
'unformatted' => null,
'default_translation_content' => 'Default translation content',
'autotranslate' => null,
'xml_space_preserve' => null,
'original_file' => null,
'localized_format_string' => null,
'localized_format_key' => null,
'custom_metadata' => [
'fruit' => 'Apple',
'vegetable' => 'Tomato'
],
'excluded_in_locales' => [
'de',
'fr'
],
'format_value_type' => 'string'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.phrase.com/v2/projects/{project_id}/keys"
payload := strings.NewReader("{\n \"name\": \"home.index.headline\",\n \"branch\": \"my-feature-branch\",\n \"description\": \"Some description worth knowing...\",\n \"plural\": null,\n \"use_ordinal_rules\": null,\n \"name_plural\": \"home.index.headlines\",\n \"data_type\": \"number\",\n \"tags\": \"awesome-feature,needs-proofreading\",\n \"max_characters_allowed\": 140,\n \"screenshot\": \"/path/to/my/screenshot.png\",\n \"remove_screenshot\": null,\n \"unformatted\": null,\n \"default_translation_content\": \"Default translation content\",\n \"autotranslate\": null,\n \"xml_space_preserve\": null,\n \"original_file\": null,\n \"localized_format_string\": null,\n \"localized_format_key\": null,\n \"custom_metadata\": {\n \"fruit\": \"Apple\",\n \"vegetable\": \"Tomato\"\n },\n \"excluded_in_locales\": [\n \"de\",\n \"fr\"\n ],\n \"format_value_type\": \"string\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.phrase.com/v2/projects/{project_id}/keys")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"home.index.headline\",\n \"branch\": \"my-feature-branch\",\n \"description\": \"Some description worth knowing...\",\n \"plural\": null,\n \"use_ordinal_rules\": null,\n \"name_plural\": \"home.index.headlines\",\n \"data_type\": \"number\",\n \"tags\": \"awesome-feature,needs-proofreading\",\n \"max_characters_allowed\": 140,\n \"screenshot\": \"/path/to/my/screenshot.png\",\n \"remove_screenshot\": null,\n \"unformatted\": null,\n \"default_translation_content\": \"Default translation content\",\n \"autotranslate\": null,\n \"xml_space_preserve\": null,\n \"original_file\": null,\n \"localized_format_string\": null,\n \"localized_format_key\": null,\n \"custom_metadata\": {\n \"fruit\": \"Apple\",\n \"vegetable\": \"Tomato\"\n },\n \"excluded_in_locales\": [\n \"de\",\n \"fr\"\n ],\n \"format_value_type\": \"string\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.phrase.com/v2/projects/{project_id}/keys")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"home.index.headline\",\n \"branch\": \"my-feature-branch\",\n \"description\": \"Some description worth knowing...\",\n \"plural\": null,\n \"use_ordinal_rules\": null,\n \"name_plural\": \"home.index.headlines\",\n \"data_type\": \"number\",\n \"tags\": \"awesome-feature,needs-proofreading\",\n \"max_characters_allowed\": 140,\n \"screenshot\": \"/path/to/my/screenshot.png\",\n \"remove_screenshot\": null,\n \"unformatted\": null,\n \"default_translation_content\": \"Default translation content\",\n \"autotranslate\": null,\n \"xml_space_preserve\": null,\n \"original_file\": null,\n \"localized_format_string\": null,\n \"localized_format_key\": null,\n \"custom_metadata\": {\n \"fruit\": \"Apple\",\n \"vegetable\": \"Tomato\"\n },\n \"excluded_in_locales\": [\n \"de\",\n \"fr\"\n ],\n \"format_value_type\": \"string\"\n}"
response = http.request(request)
puts response.read_body{
"id": "abcd1234cdef1234abcd1234cdef1234",
"name": "home.index.headline",
"description": "My description for this key...",
"name_hash": "1b31d2580ce324f246f66b3be00ed399",
"plural": false,
"use_ordinal_rules": false,
"tags": [
"awesome-feature",
"needs-proofreading"
],
"data_type": "string",
"created_at": "2015-01-28T09:52:53Z",
"updated_at": "2015-01-28T09:52:53Z",
"name_plural": "home.index.headlines",
"comments_count": 2,
"max_characters_allowed": 140,
"screenshot_url": "http://assets.example.com/screenshot.png",
"unformatted": false,
"xml_space_preserve": false,
"original_file": "",
"format_value_type": "",
"creator": {
"id": "abcd1234cdef1234abcd1234cdef1234",
"username": "joe.doe",
"name": "Joe Doe"
},
"custom_metadata": {
"fruit": "Apple",
"vegetable": "Tomato"
}
}{
"message": "Validation Failed",
"errors": [
{
"resource": "Resource",
"field": "name",
"message": "can't be blank"
}
]
}Body
application/json
Response
Created
Was this page helpful?