Hi,

If you use Go you can just use the cloudstack-go client (and maybe check
how they implemented the signing there).

Check out our project that uses cloudstack-go!
https://github.com/kthcloud/go-deploy

I got it working with JavaScript too, which is just based on the CloudStack
client in npm:

***
function createCloudstackUrl (baseUrl, command, apiKey, secretKey) {
  let queryDict = {
    'apiKey': apiKey,
    'command': command,
    'response': 'json',
  }

  let hmac = crypto.createHmac('sha1', secretKey)
  let orderedQuery = qs.stringify(queryDict, { encode: true })
    .replace(/\%5B(\D*?)\%5D/g, '.$1')
    .replace(/\%5B(\d*?)\%5D/g, '[$1]')
    .split('&')
    .sort()
    .join('&')
    .toLowerCase()
  hmac.update(orderedQuery)
  const signature = hmac.digest('base64')

  queryDict['signature'] = signature

  let apiURL = url.parse(baseUrl)
  apiURL.path += qs.stringify(queryDict, { encode: true })
    .replace(/\%5B(\D*?)\%5D/g, '.$1')

  return `${apiURL.protocol}//${apiURL.host}${apiURL.path}`

}
***

Hope that helps,

Emil
kthcloud

On Thu, Jan 26, 2023 at 10:36 AM <[email protected]> wrote:

> Hi,
>
>
>
> I want to use CS api to interact with some other services, but it looks
> like
> I do not get it to work.
>
> Is this still valid:
>
> http://docs.cloudstack.apache.org/en/latest/developersguide/dev.html#making-
> api-requests
> <http://docs.cloudstack.apache.org/en/latest/developersguide/dev.html#making-api-requests>
>
>
>
> I am using scripts which are working with other versions of CS, but it is
> not working in 4.17.2.0. I always get "unable to verify user credentials
> and/or request signature".
>
> Does someone using signed api calls with success in 4.17.2.0?
>
>
>
> Regards,
>
> Swen
>
>

Reply via email to