{site_url}/wp-json/polytrans/v1/
Bearer Token (Recommended):
Authorization: Bearer your-secret-tokenCustom Header:
X-PolyTrans-Secret: your-secret-tokenReceive and process translation requests (for multi-server setups).
Request:
{
"post_id": 123,
"target_language": "es",
"source_language": "en",
"provider": "openai",
"scope": "regional"
}Response:
{
"success": true,
"message": "Translation request received",
"task_id": "task_abc123"
}Note: This endpoint is primarily for multi-server setups where translation work is distributed. For single-server setups, translations are triggered via the WordPress admin interface.
Receive completed translations from external translation services.
Request:
{
"post_id": 123,
"target_language": "es",
"translated_content": {
"post_title": "Título traducido",
"post_content": "Contenido traducido...",
"post_excerpt": "Resumen traducido..."
},
"metadata": {
"translation_provider": "openai",
"translation_time": "2025-12-16T10:00:00Z"
}
}Response:
{
"success": true,
"message": "Translation received and processed",
"translated_post_id": 456
}Note: This endpoint is used in multi-server setups where a separate translation server sends completed translations back to the main server.
The plugin currently focuses on WordPress admin interface for most operations. REST API endpoints are primarily designed for:
- Multi-server setups - Distributed translation workflows
- External integrations - Custom translation services
For single-server setups, use the WordPress admin interface:
- Translation: Edit post → Translation Scheduler meta box
- Workflows: PolyTrans → Post-Processing
- Status: PolyTrans → Translation Logs
{
"success": false,
"code": "invalid_post_id",
"message": "Post not found"
}Common Error Codes:
invalid_post_id- Post doesn't existunsupported_language- Language not configuredtranslation_failed- Translation provider errorworkflow_not_found- Workflow doesn't existunauthorized- Invalid authentication
Register webhook URLs to receive notifications:
Settings → API Settings → Webhooks
Events:
translation.completed- Translation finishedtranslation.failed- Translation errorworkflow.completed- Workflow finished
Payload Example:
{
"event": "translation.completed",
"post_id": 123,
"translation_id": 456,
"language": "es",
"timestamp": "2025-10-07T12:00:00Z"
}- Default: 60 requests/minute
- Configurable per API key
- Headers returned:
X-RateLimit-LimitX-RateLimit-RemainingX-RateLimit-Reset
$response = wp_remote_post('https://translator-server.com/wp-json/polytrans/v1/translation/translate', [
'headers' => [
'Authorization' => 'Bearer ' . $api_key,
'Content-Type' => 'application/json'
],
'body' => json_encode([
'post_id' => 123,
'target_language' => 'es',
'source_language' => 'en',
'provider' => 'openai'
])
]);
$result = json_decode(wp_remote_retrieve_body($response), true);$response = wp_remote_post('https://main-server.com/wp-json/polytrans/v1/translation/receive-post', [
'headers' => [
'Authorization' => 'Bearer ' . $api_key,
'Content-Type' => 'application/json'
],
'body' => json_encode([
'post_id' => 123,
'target_language' => 'es',
'translated_content' => [
'post_title' => 'Título traducido',
'post_content' => 'Contenido traducido...'
]
])
]);
$result = json_decode(wp_remote_retrieve_body($response), true);// Before translation
add_filter('polytrans_pre_translate', function($content, $lang) {
return $content;
}, 10, 2);
// After translation
add_action('polytrans_translation_complete', function($post_id, $lang) {
// Custom logic
}, 10, 2);
// Modify workflow context
add_filter('polytrans_workflow_context', function($context, $workflow) {
return $context;
}, 10, 2);See Hooks and Filters for complete hook reference.