This page is writing about the correct steps to configure the required request headers before sending an API request at HCP OpenAPI.
...
Info |
---|
Prerequisite
|
APPkey and APPsecret
Both APPkey and APPsecret can be found after creating a partner at Open Platform (https://IPaddress/artemis-web > Partner Management).
APPkey is included in the request header, while APPsecret is used for the calculation of signature string.
Signature String
Form a string with the request method, header’s Accept, header’s Content-Type and URI, separated by “\n“
Expand | ||
---|---|---|
| ||
Example 1: POST /artemis/api/example?qa=value1&qb=value2&qc ; Accept = */* ; Content-Type=application/json String: “POST\n*/*\napplication/json\n/artemis/api/example?qa=value1&qb=value2&qc“ Example 2: POST /artemis/api/example ; Accept = application/json ; Content-Type=application/json String: “POST\napplication/json\napplication/json\n/artemis/api/example“
|
Convert the string with HmacSHA256 algorithm and APPsecret as the key, to generate message digest.
Encode the message digest in Base64, to generate the signature string.
Prepare the request header
Use the APPkey and Signature String to form the request header.
Code Block | ||
---|---|---|
| ||
{ 'X-Ca-Key': <APPkey>, 'X-Ca-Signature': <Signature String> } |
Sample Code
Calculating Signature String
...
Code Block | ||
---|---|---|
| ||
headers = {
'X-Ca-Key': app_key, # Get from Open Platform
'X-Ca-Signature': encoded_signature # Get from calculation
}
response = requests.request("POST", url, headers=headers, json=request_body) |