Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This page is writing about the correct steps to configure the required request headers before sending an API request at HCP OpenAPI.

...

  1. Form a string with the request method, header’s Accept, header’s Content-Type and URI, separated by “\n“

Expand
titleGuide on forming the string

Example 1: POST /artemis/api/example?qa=value1&qb=value2&qc ; Accept = */* ; Content-Type=application/json

String: “POSTPOST\n*/*\napplication/json\n/artemis/api/example?qa=value1&qb=value2&qc“qc

Example 2: POST /artemis/api/example ; Accept = application/json ; Content-Type=application/json

String: “POST\napplicationPOST\napplication/json\napplication/json\n/artemis/api/example“example

Note

URI must start with “/“, contain containing the endpoint and request parameters.

...

Code Block
languagepy
def generate_signature(app_key, app_secret, method, path):
    message = f"{method}POST\n*/*\napplication/json\n/artemis/api/example" # Initial string

    key_bytes = bytes(app_secret, 'utf-8') # key
    message_bytes = bytes(message, 'utf-8') # messagemsg
    signature = hmac.new(key_bytes, msg=message_bytes, digestmod=hashlib.sha256).digest() # message digest

    encoded_signature = base64.b64encode(signature).decode('utf-8') # signature string

    return encoded_signature

Creating the request header

Code Block
languagepy
headers = {
    'X-Ca-Key': app_key,                  # Get from Open Platform
    'X-Ca-Signature': encoded_signature   # Get from calculation
}