// Define struct of request json body
type TranslateJson struct {
FieldId string `json:"fieldId"`
Text []string `json:"text"`
TargetLang string `json:"targetLang"`
SourceLang string `json:"sourceLang"`
}
// Post translate request and get queue ID
func PostApiExample(accessKey, secretKey, basePath, nonce string) {
translatePath := "/api/v1/translate/async"
signTranslate := MakeHMAC(nonce, translatePath, secretKey)
testJson := &TranslateJson{
FieldId: "1",
Text: []string{"This is a pen.", "I have an apple."},
TargetLang: "ja",
SourceLang: "en",
ContractId: "your contractId"}
jsonValue, _ := json.Marshal(testJson)
client := &http.Client{}
req, err := http.NewRequest(
"POST",
GetFullUrl(basePath, translatePath),
bytes.NewBuffer([]byte(jsonValue)),
)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("nonce", nonce)
req.Header.Set("accessKey", accessKey)
req.Header.Set("signature", signTranslate)
res, err := client.Do(req)
if err != nil {
fmt.Printf("The HTTP request failed with error %s\n", err)
} else {
data, _ := ioutil.ReadAll(res.Body)
fmt.Println(string(data))
}
}