# /org

## Create an org

<mark style="color:green;">`POST`</mark> `https://pm415.com/api/org`

Creates an organization.

#### Headers

| Name           | Type   | Description                                   |
| -------------- | ------ | --------------------------------------------- |
| Authentication | string | `Authorization: Bearer 50ca9ba0f7b1444fa55d5` |

#### Request Body

| Name | Type   | Description          |
| ---- | ------ | -------------------- |
|      | object | `{"name" : "myOrg"}` |

{% tabs %}
{% tab title="200 Org created" %}

```javascript
{
    "success": true,
    "organization": {
        "name": "myOrg",
        "updated_at": "2019-04-20T19:22:13.740Z",
        "created_at": "2019-04-20T19:22:13.740Z",
        "id": 15
    },
    "user": {
        "id": 4,
        "email": "mattreider@tmail.com",
        "password": "f115e42cc1a509ed5a03879574e71",
        "firstName": "Matthew",
        "lastName": "Reider",
        "isActive": 1,
        "confirmedAt": "2019-04-08T02:38:54.000Z",
        "createdAt": "2019-04-08T02:38:34.000Z",
        "updatedAt": "2019-04-08T02:38:54.000Z",
        "apiKey": "50ca9ba0f7b14f1932a1f81",
        "organizations": [
            {
                "id": 6,
                "name": "foo",
                "createdAt": "2019-04-08T02:38:34.000Z",
                "updatedAt": "2019-04-08T02:38:34.000Z",
                "roles": [
                    {
                        "id": 1,
                        "role": "Admin",
                        "createdAt": "2019-04-08T02:30:37.000Z",
                        "updatedAt": "2019-04-08T02:30:37.000Z"
                    }
                ]
            }
        ]
    }
}
```

{% endtab %}

{% tab title="400 Bad request" %}

```javascript
{
    "statusCode": 400,
    "error": "Bad Request",
    "message": "\"Name\" is required",
    "success": false
}
```

{% endtab %}
{% endtabs %}

## Get org info

<mark style="color:blue;">`GET`</mark> `https://pm415.com/api/org`

Gets info about all of the orgs. There are no request parameters - only a response.

#### Headers

| Name           | Type   | Description                                   |
| -------------- | ------ | --------------------------------------------- |
| Authentication | string | `Authorization: Bearer 50ca9ba0f7b1444fa55d5` |

{% tabs %}
{% tab title="200 " %}

```
{
    "success": true,
    "organizations": [
        {
            "id": 6,
            "name": "foo",
            "createdAt": "2019-04-08T02:38:34.000Z",
            "updatedAt": "2019-04-08T02:38:34.000Z",
            "roles": [
                {
                    "id": 1,
                    "role": "Admin",
                    "createdAt": "2019-04-08T02:30:37.000Z",
                    "updatedAt": "2019-04-08T02:30:37.000Z"
                }
            ]
        },
        {
            "id": 15,
            "name": "myOrg",
            "createdAt": "2019-04-20T19:22:13.000Z",
            "updatedAt": "2019-04-20T19:22:13.000Z",
            "roles": [
                {
                    "id": 1,
                    "role": "Admin",
                    "createdAt": "2019-04-08T02:30:37.000Z",
                    "updatedAt": "2019-04-08T02:30:37.000Z"
                }
            ]
        }
    ],
    "current": {
        "id": 6,
        "name": "foo",
        "createdAt": "2019-04-08T02:38:34.000Z",
        "updatedAt": "2019-04-08T02:38:34.000Z",
        "roles": [
            {
                "id": 1,
                "role": "Admin",
                "createdAt": "2019-04-08T02:30:37.000Z",
                "updatedAt": "2019-04-08T02:30:37.000Z"
            }
        ]
    }
}
```

{% endtab %}
{% endtabs %}

## Switch orgs

<mark style="color:green;">`POST`</mark> `https://pm415.com/api/org/switch/:orgid`

Switches orgs and generates a new token. This is useful if you are building a user interface, or CLI tool, and want to operate on one org at a time. The org you operate on is encapsulated in the token. Switching orgs, and tokens, allows you to operate on different orgs without having to save sessions artifacts (cookies, web storage, files, etc) on the client.

#### Path Parameters

| Name   | Type   | Description                             |
| ------ | ------ | --------------------------------------- |
| :orgid | number | The ID of the org you want to switch to |

#### Headers

| Name           | Type   | Description                                   |
| -------------- | ------ | --------------------------------------------- |
| Authentication | string | `Authorization: Bearer 50ca9ba0f7b1444fa55d5` |

{% tabs %}
{% tab title="200 Switched orgs" %}

```
{
    "success": true,
    "organization": 1,
    "token": "00jf9w4dog73jfosdfu"
}
```

{% endtab %}
{% endtabs %}

## Update an org

<mark style="color:orange;">`PUT`</mark> `https://pm415.com/api/org/:orgid`

Update an org's name

#### Path Parameters

| Name   | Type   | Description                          |
| ------ | ------ | ------------------------------------ |
| :orgid | number | The ID of the org you want to update |

#### Headers

| Name           | Type   | Description                                   |
| -------------- | ------ | --------------------------------------------- |
| Authentication | string | `Authorization: Bearer 50ca9ba0f7b1444fa55d5` |

#### Request Body

| Name | Type   | Description                  |
| ---- | ------ | ---------------------------- |
|      | object | `{"name": "updatedOrgName"}` |

{% tabs %}
{% tab title="200 {\
"success": true,\
"organization": 6\
}" %}

```
```

{% endtab %}
{% endtabs %}

## Delete an org

<mark style="color:red;">`DELETE`</mark> `https://pm415.com/api/org/:orgid`

#### Path Parameters

| Name   | Type   | Description                          |
| ------ | ------ | ------------------------------------ |
| :orgid | number | The ID of the org you want to delete |

#### Headers

| Name           | Type   | Description                                   |
| -------------- | ------ | --------------------------------------------- |
| Authentication | string | `Authorization: Bearer 50ca9ba0f7b1444fa55d5` |

{% tabs %}
{% tab title="200 " %}

```
{
    "success": true
}
```

{% endtab %}
{% endtabs %}

## Get users

<mark style="color:blue;">`GET`</mark> `https://pm415.com/api/org/:orgid/users`

Gets information about an organization's users

#### Path Parameters

| Name   | Type   | Description                         |
| ------ | ------ | ----------------------------------- |
| :orgid | number | The ID of the org you want to query |

#### Headers

| Name           | Type   | Description                                   |
| -------------- | ------ | --------------------------------------------- |
| Authentication | string | `Authorization: Bearer 50ca9ba0f7b1444fa55d5` |

{% tabs %}
{% tab title="200 " %}

```
{
    "success": true,
    "users": [
        {
            "userId": 4,
            "email": "mattr@tmail.com",
            "firstName": "Matthew",
            "lastName": "Reider",
            "isActive": 1,
            "role": "Admin"
        },
        {
            "userId": 6,
            "email": "suziereider@tmail.com",
            "firstName": "Suzie",
            "lastName": "Reider",
            "isActive": 1,
            "role": "Admin"
        }
    ]
}
```

{% endtab %}
{% endtabs %}

## Validate an user invite token

<mark style="color:blue;">`GET`</mark> `https://pm415.com/api/org/invite/?token=8s80f934kf94`

Checks an invite token to see if it is valid and who it belongs to.*This method is used by the PM415 user interface and may not have any other practical use case.*

#### Query Parameters

| Name  | Type   | Description                      |
| ----- | ------ | -------------------------------- |
| token | string | Invitation token sent to a user. |

#### Headers

| Name           | Type   | Description                                   |
| -------------- | ------ | --------------------------------------------- |
| Authentication | string | `Authorization: Bearer 50ca9ba0f7b1444fa55d5` |

{% tabs %}
{% tab title="200 " %}

```
{
    success: true,
    "email": "mattreider@tmail.com",
    "organization": "my-org"
}
```

{% endtab %}
{% endtabs %}

## Generate an invite link

<mark style="color:green;">`POST`</mark> `https://pm415.com/api/org/:orgid/invitelink`

Creates an invite link for a new user.

#### Path Parameters

| Name   | Type   | Description                             |
| ------ | ------ | --------------------------------------- |
| :orgid | number | The ID of the org you want to work with |

#### Headers

| Name           | Type   | Description                                   |
| -------------- | ------ | --------------------------------------------- |
| Authentication | string | `Authorization: Bearer 50ca9ba0f7b1444fa55d5` |

#### Request Body

| Name | Type   | Description                        |
| ---- | ------ | ---------------------------------- |
|      | object | `{email: “suziereider@tmail.com”}` |

{% tabs %}
{% tab title="200 " %}

```
{
   "success": true,
   "confirmUrl": "https://pm415.com/account/invite/?token=eyJh
}
```

{% endtab %}
{% endtabs %}

## Remove users

<mark style="color:green;">`POST`</mark> `https://pm415.com//api/org/:orgid/users/remove`

Removes users from an organization. This does not delete the user's profile - just the link between the org and the user. To add them back, you must re-invite them.

#### Path Parameters

| Name   | Type   | Description                             |
| ------ | ------ | --------------------------------------- |
| :orgid | number | The ID of the org you want to work with |

#### Headers

| Name           | Type   | Description                                   |
| -------------- | ------ | --------------------------------------------- |
| Authentication | string | `Authorization: Bearer 50ca9ba0f7b1444fa55d5` |

#### Request Body

| Name | Type   | Description               |
| ---- | ------ | ------------------------- |
|      | object | `{"usersId": ["4", "6"]}` |

{% tabs %}
{% tab title="200 " %}

```
{
   "success": true
}
```

{% endtab %}
{% endtabs %}

## Grant admin

<mark style="color:orange;">`PUT`</mark> `https://pm415.com/api/org/:orgid/admin/grant`

Gives a user admin privileges. Admins can perform all operations on an org and its users.

#### Path Parameters

| Name   | Type   | Description                             |
| ------ | ------ | --------------------------------------- |
| :orgid | number | The ID of the org you want to work with |

#### Headers

| Name           | Type   | Description                                   |
| -------------- | ------ | --------------------------------------------- |
| Authentication | string | `Authorization: Bearer 50ca9ba0f7b1444fa55d5` |

#### Request Body

| Name | Type   | Description               |
| ---- | ------ | ------------------------- |
|      | object | `{"usersId": ["4", "6"]}` |

{% tabs %}
{% tab title="200 " %}

```
{
   "success": true
}
```

{% endtab %}
{% endtabs %}

## Revoke admin

<mark style="color:orange;">`PUT`</mark> `https://pm415.com/api/org/:orgid/admin/revoke`

Revokes a user's admin privileges.

#### Path Parameters

| Name   | Type   | Description                             |
| ------ | ------ | --------------------------------------- |
| :orgid | number | The ID of the org you want to work with |

#### Headers

| Name           | Type   | Description                                   |
| -------------- | ------ | --------------------------------------------- |
| Authentication | string | `Authorization: Bearer 50ca9ba0f7b1444fa55d5` |

#### Request Body

| Name | Type   | Description               |
| ---- | ------ | ------------------------- |
|      | object | `{"usersId": ["4", "6"]}` |

{% tabs %}
{% tab title="200 " %}

```
{
   "success": true
}
```

{% endtab %}
{% endtabs %}

## Reset password

<mark style="color:orange;">`PUT`</mark> `https://pm415.com/api/org/:orgid/admin/resetpassword`

Resets user passwords and sends emails with reset links.

#### Path Parameters

| Name   | Type   | Description                             |
| ------ | ------ | --------------------------------------- |
| :orgid | number | The ID of the org you want to work with |

#### Headers

| Name           | Type   | Description                                   |
| -------------- | ------ | --------------------------------------------- |
| Authentication | string | `Authorization: Bearer 50ca9ba0f7b1444fa55d5` |

#### Request Body

| Name | Type   | Description               |
| ---- | ------ | ------------------------- |
|      | object | `{"usersId": ["4", "6"]}` |

{% tabs %}
{% tab title="200 " %}

```
{
   "success": true
}
```

{% endtab %}
{% endtabs %}
