401 in REST APIs #11146
-
Hi, My cloudstack api url for create user is like http://cloudstack-host/client/api?account&command=createUser&email=userthree%40mail.com&firstname=User&lastname=Three&password=password&response=json&username=userthree&signature= It rejects me with 401 Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
Thanks for opening your first issue here! Be sure to follow the issue template! |
Beta Was this translation helpful? Give feedback.
-
@waiphyodev , I suppose you left out the signature on purpose and did include it in your attempts to create a user.
and is a post request with parameters.
if this seems ok, |
Beta Was this translation helpful? Give feedback.
-
Thanks for reply. |
Beta Was this translation helpful? Give feedback.
-
GET (401 error) POST (431 error) with payload |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
My bad! Thanks for all your helps. (error) params => get signature for params => encode signature const params = {
...queryParams, // parameters like command
apikey: <api-key>,
response: "json",
};
const sortedKeys = Object.keys(params)
.map((k) => k.toLowerCase())
.sort();
const encodedSortedQuery = sortedKeys.map((k) => `${k}=${encodeURIComponent(params[k])}`).join("&");
const signature = crypto.createHmac("sha1", <secret-key>).update(encodedSortedQuery.toLowerCase()).digest("base64");
const encodedSignature = encodeURIComponent(signature);
const signedUrl = `<host>?${encodedSortedQuery}&signature=${encodedSignature}`; For the purpose of if someone is having errors and want to check the scenario in js |
Beta Was this translation helpful? Give feedback.
My bad! Thanks for all your helps.
(error) params => get signature for params => encode signature
(success) params => encode params => get signature for encoded params => encode signature