Pricing 
API Pricing

Try For Free Now

Dark

Light

AUTHENTICATION
Nonce
For security purpose, it is required to access this API with the generated signature.
Header
Header
Description
accessKey
Your access key.
nonce
Numeric string. The numeric value should increase for each subsequent request. Using the UNIX timestamp(millisecond) is recommended. The maximum number that can be specified for nonce is 9223372036854775807.
signature
Authentication signature. Using your secret key as the HMAC key, apply SHA256 HMAC to hash both nonce and url (except the domain part) to obtain the hexadecimal string.

Sample codes of various programming languages are provided to demonstrate the general logic flow.


Generate the authentication signature. Signature should be set in header when connecting our API. For instance, we connect an API called "hello".

/api/v1/hello
"hello" as an API which does nothing. Please replace it with any API you want to use.

01

/

First implement the signature generation function.

Go
JavaScript
Java
PHP
C#
VB.NET
func MakeHMAC(nonce, path, secretKey string) string {
    // Create a new HMAC by defining the hash type and the key (as byte array)
    h := hmac.New(sha256.New, []byte(secretKey))
  
    // Write Data to it
    h.Write([]byte(nonce))
    h.Write([]byte(path))
  
    // Get result and encode as hexadecimal string
    sha := hex.EncodeToString(h.Sum(nil))
  
    fmt.Println("Result: " + sha)
    return sha
  }

02

/

Set the request header when accessing the API.

Go
JavaScript
Java
PHP
C#
VB.NET
// Generate a full URL
func GetFullUrl(base, path string) string {
  var buffer bytes.Buffer
  buffer.WriteString(base)
  buffer.WriteString(path)
  return buffer.String()
}

func GetApiExample(accessKey, secretKey, basePath, nonce string) {
  helloPath := "/api/v1/hello"
  // Generate a signature
  signHello := MakeHMAC(nonce, helloPath, secretKey)

  // Set headers and call the api
  client := &http.Client{}
  req, _ := http.NewRequest("GET", GetFullUrl(basePath, helloPath), nil)
  req.Header.Set("nonce", nonce)
  req.Header.Set("accessKey", accessKey)
  req.Header.Set("signature", signHello)
  res, err := client.Do(req)

  // Output response
  if err != nil {
    fmt.Printf("The HTTP request failed with error %s\n", err)
  } else {
    data, _ := ioutil.ReadAll(res.Body)
    fmt.Println(string(data))
  }
}

03

/

Implement the main function and execute it.

Go
JavaScript
Java
PHP
C#
VB.NET
import "strconv"

  func main() {
    fmt.Println("Starting the application...")

    accessKey := "Your Access Key"
    secretKey := "Your Secret Key"
    BasePath := "https://translate.rozetta-api.io"
    millis:= time.Now().UnixNano() / 1e6
    nonce := strconv.FormatInt(millis, 10)

    GetApiExample(accessKey, secretKey, BasePath, nonce)
    fmt.Println("Terminating the application...")
  }
You can get a full version of sample codes here
©️ 2019 Rozetta API  ・  Powered by Rozetta

Rozetta Corp.

^