API V1 · Resources
Upload a resource file
curl --request POST \ --url https://api.lingohub.com/v1/WORKSPACE_URL/projects/PROJECT_URL/resources \ --header 'Authorization: Bearer YOUR_API_KEY' \ --header 'Content-Type: multipart/form-data' \ --form file=@translations.jsonimport requests
url = "https://api.lingohub.com/v1/WORKSPACE_URL/projects/PROJECT_URL/resources"
files = { "file": "open('translations.json', 'rb')" }headers = {"Authorization": "Bearer YOUR_API_KEY"}
response = requests.post(url, files=files, headers=headers)
print(response.json())const url = 'https://api.lingohub.com/v1/WORKSPACE_URL/projects/PROJECT_URL/resources';const form = new FormData();form.append('file', 'translations.json');
const options = {method: 'POST', headers: {Authorization: 'Bearer YOUR_API_KEY'}};
options.body = form;
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}package main
import ( "fmt" "strings" "net/http" "io")
func main() {
url := "https://api.lingohub.com/v1/WORKSPACE_URL/projects/PROJECT_URL/resources"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"translations.json\"\r\nContent-Type: application/json\r\n\r\n\r\n-----011000010111000001101001--\r\n")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer YOUR_API_KEY")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close() body, _ := io.ReadAll(res.Body)
fmt.Println(res) fmt.Println(string(body))
}OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("multipart/form-data; boundary=---011000010111000001101001");RequestBody body = RequestBody.create(mediaType, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"translations.json\"\r\nContent-Type: application/json\r\n\r\n\r\n-----011000010111000001101001--\r\n");Request request = new Request.Builder() .url("https://api.lingohub.com/v1/WORKSPACE_URL/projects/PROJECT_URL/resources") .post(body) .addHeader("Authorization", "Bearer YOUR_API_KEY") .build();
Response response = client.newCall(request).execute();<?php
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'https://api.lingohub.com/v1/WORKSPACE_URL/projects/PROJECT_URL/resources', [ 'multipart' => [ [ 'name' => 'file', 'filename' => 'translations.json', 'contents' => null, 'headers' => [ 'Content-Type' => 'application/json' ] ] ] 'headers' => [ 'Authorization' => 'Bearer YOUR_API_KEY', ],]);
echo $response->getBody();require 'uri'require 'net/http'
url = URI("https://api.lingohub.com/v1/WORKSPACE_URL/projects/PROJECT_URL/resources")
http = Net::HTTP.new(url.host, url.port)http.use_ssl = true
request = Net::HTTP::Post.new(url)request["Authorization"] = 'Bearer YOUR_API_KEY'request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"translations.json\"\r\nContent-Type: application/json\r\n\r\n\r\n-----011000010111000001101001--\r\n"
response = http.request(request)puts response.read_bodyusing System.Net.Http.Headers;var client = new HttpClient();var request = new HttpRequestMessage{ Method = HttpMethod.Post, RequestUri = new Uri("https://api.lingohub.com/v1/WORKSPACE_URL/projects/PROJECT_URL/resources"), Headers = { { "Authorization", "Bearer YOUR_API_KEY" }, }, Content = new MultipartFormDataContent { new StringContent("") { Headers = { ContentType = new MediaTypeHeaderValue("application/json"), ContentDisposition = new ContentDispositionHeaderValue("form-data") { Name = "file", FileName = "translations.json", } } }, },};using (var response = await client.SendAsync(request)){ response.EnsureSuccessStatusCode(); var body = await response.Content.ReadAsStringAsync(); Console.WriteLine(body);}Uploads a single resource file to the specified project. The file’s language is detected automatically from the file name, or can be explicitly set via the iso2_slug/iso2_code parameter. Import behavior for source and target languages (create new segments, update existing, deactivate missing) can be controlled through optional parameters. If the upload might cause a file name collision, set force=true to proceed.
Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Path Parameters
Section titled “Path Parameters”WorkspaceUrl
ProjectUrl
Query Parameters
Section titled “Query Parameters”Path the resource container (file) will be uploaded to
The iso code of the resource file locale. Overrides the language information that might be given in the path. Alias of ‘iso2_code’.
The iso code of the resource file locale. Overrides the language information that might be given in the path. Alias of ‘iso2_slug’.
If this file belongs to the source language: If new segments should be created
If this file belongs to the source language: If changed segments should be updated
If this file belongs to the source language: If removed segments should be deactivated
If this file belongs to the target language: If new segments should be created
If this file belongs to the target language: If changed segments should be updated
If this file belongs to the target language: If removed segments should be deactivated
Force the upload. Override potential security measures, eg. a collision between file names
Name of the project branch to import into. If omitted, the project’s default branch is used. Returns 422 if the branch name does not exist in the project.
Request Body
Section titled “Request Body”object
File that will be uploaded
Responses
Section titled “Responses”Successfully uploaded the resource file.
Examples
Successful upload
UploadSuccess
{ "status": "Success"}Unauthorized: Authentication credentials are missing or invalid.
object
Example generated
{ "url": "example", "message": "example", "text": "example"}Forbidden: The authenticated user does not have resource management permission on this project.
object
Example generated
{ "url": "example", "message": "example", "text": "example"}Not Found: The specified workspace or project does not exist.
object
Example generated
{ "url": "example", "message": "example", "text": "example"}Not Acceptable: A file name collision was detected and force=true was not set. Specify a path or use force=true to override.
Examples
Path collision detected
CollisionDetected
{ "status": "Not acceptable", "message": "A situation has been detected that might lead to an unwanted upload action..."}Unprocessable Entity: The specified branch name does not exist in the project, or the file has an extension the project type cannot import (error code files.invalid_extension, naming the file).
object
object
object
object
object
object
Examples
Unsupported file extension
UnsupportedFile
{ "validationErrors": [ { "field": "files", "errors": [ { "code": "files.invalid_extension", "description": "File 'Resources.en.txt' has an unsupported extension; this project imports: resx, resw.", "parameters": { "file": "Resources.en.txt" } } ] } ]}Internal Server Error: An unexpected error occurred during the import process.
object
Example generated
{ "url": "example", "message": "example", "text": "example"}