Create / remove organization through api

Looking at the swagger, there is a an api method for creating orgs.

However, it is unclear what is meant to be POSTed. Trying to post the JSON shown as the expected response does not appear to work.

curl -v -X POST "https://gitea.mydomain/api/v1/admin/users/USER/orgs" -H "Authorization: TOKEN" -H "Content-Type: application/json" -H  "accept: application/json" --data '{"username": "wow"}'

A curl example of creating an org would really help out. The example in the swagger does not appear to allow the setting of the org name, which would seem to be a critical piece of info.

Also, the swagger does not show any means of removing an org as far as I can tell. Is there a way to do that?


Figured it out (the create, that is).

The 1st problem is I did not include the word ‘token’ in front of the token passed in as a header.

The 2nd problem stems from the swagger ui not being functional for this use. It does not specify what the body should be or allow you to set info about the org. It turns out the right thing to do is to send a json body of the same schema as the result json, with username set to the name of the org you wish to create.

The following is an example that works for create:

curl -v -X POST "https://gitea.mydomain/api/v1/admin/users/USER/orgs" -H "Authorization: token TOKEN" -H "Content-Type: application/json" -H  "accept: application/json" --data '{"username": "wow"}'
1 Like

Figured out the remove organization. Use the DELETE user endpoint, with org name in place of user name.

curl -v -X DELETE "https://gitea.mydomain/api/v1/admin/users/ORG" -H "Authorization: token TOKEN" -H  "accept: application/json"

This only works on empty orgs, so you must first manually remove anything in the org. It would be nice if that was not the case.

1 Like