I m trying to get an API key . for a user , but return me 404,
my other APIs work fine, so not the header issue. I also checked the backend setup. no problem..
NathanLei reported a 404 error when trying to generate an API key for a user via the documented endpoint, despite other APIs working and backend setup being correct. david clarified that the endpoint has changed and provided the updated cURL command to create an API key using POST /admin/api/keys, while also questioning the use case. NathanLei explained they created a new user via API and wanted to post on behalf of that user, assuming they needed a dedicated API key for it. david offered a better solution: use a single “all users” API key and switch the Api-Username header per request to impersonate different users — referencing the docs for an example. NathanLei confirmed this approach works perfectly. The documentation is being updated to reflect the endpoint change.
I m trying to get an API key . for a user , but return me 404,
my other APIs work fine, so not the header issue. I also checked the backend setup. no problem..
The endpoint to create a new API key has changed - we’re working on updating the documentation ASAP. You can now create a new API key like this:
curl -X POST http://localhost:3000/admin/api/keys \
-H "Content-Type: multipart/form-data;" \
-H "Api-Key: $api_key" \
-H "Api-Username: system" \
-F "key[description]=testing" \
-F "key[username]=bobby"
I would be interested to know why you are creating new API keys… using an API key. It seems a little circular, and I wonder if we can come up with a better solution for your problem?
I have created a new user via API. (with admin API and KEY)
now I need to post a post or topic for this user.
But seems no API for me to do that.. So I think maybe I should create a API for this user, then I switch my header with this new API… then I can make a post or topic on behalf of this new user..
Rather than creating a key for each user, you can use an “all users” key, then change the Api-Username header on the request. There is an example at the top of https://docs.discourse.org/
great man! thanks. that works perfectly !