リクエスト方法

仮想マシングループの新規作成を自動化するLinuxシェルスクリプトは下記のような内容となります。

edit
補足

弊社ブログでも使い方例が掲載されていますので、ご参考にしてください 初心者でもできる!ホワイトクラウドASPIREのAPI機能で自動化を始めよう

# Set API Key / Secret Key
apikey='1dae9fdbff66bf7482c8a398069616ac86f32b9141aa59f5b94a2dd5c6eb8760'
secret='89b5ee89846aeb81cc09683a81ea70a323cafb1356c21c98aaee09eddc645aeaf205e50bab11c54b98a7595901f9c85c62227603c36a8ccce6f0fdb9'

# Set headder
header='{"typ":"JWT","alg":"HS256"}'

# Set payload
time=$(date -u +%s); payload='{"iat": '$time',"sub":"'$apikey'"}'

# Set signature
b64ue_header=$(echo -n "$header" | base64 -w0)
b64ue_payload=$(echo -n "$payload" | base64 -w0)
signature_rawout=$(echo -n "$b64ue_header.$b64ue_payload" | openssl dgst -binary -sha256 -hmac "$secret" | base64 -w0)

# Set token
token="Bearer $b64ue_header.$b64ue_payload.$signature_rawout"

# Set request
endpoint='https://eastapi.aspire.gcf.whitecloud.jp/api/1.0'
reqpath='/vmgroup'

# Set method
method='POST'

# Set variables for data
keiyakuResourceId="f05f432d9a774378a30cfa55180786be"
vmgroupName="TestVMGroup01"

  
## Set data
data='{
    "vmgroup": {
    "keiyakuResourceId": "'"$keiyakuResourceId"'",
    "vmgroupName": "'"$vmgroupName"'",
  }
}'
  
# Execute request
curl -i -X $method -H "Authorization:$token" -H "Content-Type:application/json" -d "$data" "$endpoint$reqpath"