Hi all,
Trying to speak to maas through it’s REST API.

  • curl requests go unanswered since it’s using oauth - understood…

  • no way that I’ve found to login and generate oauth keys for users (consumer, secret, api key) via json dict as described here:

  • I’m aware of the API key that each user gets generated upon creation in maas and have successfully used that to login to the maascli but it’s not been helpful in getting me anywhere in the REST API

  • have had success using the python-libmaas to access maas however it would be much easier for development if we can just send REST API requests without a middleware python library.

Any thoughts? Is there a switch I need to turn on to get the REST API to fully function?


You can actually use curl to talk to the MAAS REST API if you have some way to sign each request; I’ve hacked together an example here. You can also find Python-based examples of how to do this in python-libmaas, but if you want to do it yourself, we also have some examples here.

To get a key for testing, with, you can generate API keys from the command-line with sudo maas-region apikey --username <user>. (Add --generate if you want to create a new key for that user.)

I can’t recommend doing all this manually, though. I’m also curious: what is the reason you don’t want to use python-libmaas? It’s easier for us to support a single Python-based library than to teach everyone how to call our REST API manually. (Frankly, if you have subsequent questions you can probably just read the code for python-libmaas to find the answers - that’s what we would do!)

Thanks for the response!

Unfortunately I’m not sure I understand how to proceed. Yes, we can use the python-libmaas library to access the API but in my case it’s preferable to have a proper REST endpoint for a web application that needs access to maas for power on and power off functionality of the nodes.

Additionally when querying the endpoints other than the /api/version/ none of the routes seem to work or they return “No such resource”.

I see in your example GitHub code that you are querying cloud-config followed by sending your oauth credentials. is there some sort of reference to the consumer key, token key and token secret there?

your routes also look a little bit different than what I’m used to seeing in the docs…

I guess I can poke around inside the python-libmaas source code and try to figure out how / what endpoints you are querying.

Thanks! Any clarification or help is appreciated!

The API keys in MAAS are actually a : separated string:


Hope that helps.

Thanks for the quick response.

Where do I get the consumer-key token-key secret-key ?

Aaaasargh. I see the colons in the API key on each user. Ugh. My bad. How could I have missed it :wink:

my colleague is pointing out that even with these keys he can’t actually see any response. do we need to activate the API in some way? knowing that we need to control power what routes do you suggest we employ?

Did you set the Accept header to application/json? Here’s another good example I found on the web.

Thanks! Setting the Accept head to application/json did the trick!
Now to parse through all this data!

Much appreciated!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.