All Products
Search
Document Center

Machine Translation:Using REST API

Last Updated:Jun 19, 2023

Request Structure

Service Address

Territory

Access Address

hangzhou

mt.cn-hangzhou.aliyuncs.com

Request body and return result

The request body is a json structure string, and the service return is also a json string. For details, refer to each API document. Example request (java):

public class SampleRequest {
    public static void main(String[] args) {        
      String serviceURL = "http://mt.cn-hangzhou.aliyuncs.com/api/translate/web/ecommerce";  
      String accessKeyId = "<yourAccessKeyId>";//  AccessKeyId  
      String accessKeySecret = "<yourAccessKeySecret>"; // accessKeySecret  
      String postBody = "{\n" +  
        " \"FormatType\": \"text\",\n" +  
        " \"SourceLanguage\": \"en\",\n" +  
        " \"TargetLanguage\": \"zh\",\n" +  
        " \"SourceText\": \"Hello\",\n" +  
        " \"Scene\": \"title\"\n" +  
        "}";
// For the Sender code, please refer to the help document "Signature Method"
String result =  Sender.sendPost(serviceURL, postBody, accessKeyId, accessKeySecret);  
System.out.println(result);
    }
}

Machine translated version

API version

Access address

General version

http://mt.cn-hangzhou.aliyuncs.com/api/translate/web/general

E-commerce version

http://mt.cn-hangzhou.aliyuncs.com/api/translate/web/ecommerce

Normal return

Request a normal result as a json string.

Error return

{"Message","RequestId","Code"}

Character Encoding

Both the request and the return result are encoded using the UTF-8 character set.