# Create / remove organization through api

**URL:** https://forum.gitea.com/t/create-remove-organization-through-api/478
**Category:** API/SDK/Tea/HelmChart/Terraform
**Created:** [August 7, 2018, 12:03pm UTC](https://forum.gitea.com/t/create-remove-organization-through-api/478 "2018-08-07T12:03:48Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![tredeske](https://avatars.discourse-cdn.com/v4/letter/t/8baadc/32.png) [@tredeske](https://forum.gitea.com/u/tredeske)
#### Post date: [August 7, 2018, 12:03pm UTC](https://forum.gitea.com/t/create-remove-organization-through-api/478/1 "2018-08-07T12:03:48Z")

</div>

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

[https://try.gitea.io/api/swagger#/admin/adminCreateOrg](https://try.gitea.io/api/swagger#/admin/adminCreateOrg)

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?

Thanks

---

<div class="post-metadata">

### Author: ![tredeske](https://avatars.discourse-cdn.com/v4/letter/t/8baadc/32.png) [@tredeske](https://forum.gitea.com/u/tredeske)
#### Post date: [August 8, 2018, 11:27am UTC](https://forum.gitea.com/t/create-remove-organization-through-api/478/2 "2018-08-08T11:27:48Z")

</div>

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:

```auto
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"}'

```

---

<div class="post-metadata">

### Author: ![tredeske](https://avatars.discourse-cdn.com/v4/letter/t/8baadc/32.png) [@tredeske](https://forum.gitea.com/u/tredeske)
#### Post date: [August 8, 2018, 12:19pm UTC](https://forum.gitea.com/t/create-remove-organization-through-api/478/3 "2018-08-08T12:19:13Z")

</div>

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

```auto
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.
