> For the complete documentation index, see [llms.txt](https://dev.vulos.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dev.vulos.io/reference/identity-javascript-sdk/the-base-package/organizations/organizationapi.md).

# OrganizationApi

{% hint style="info" %}
This class implements [`BaseApi`](/reference/identity-javascript-sdk/the-base-package/authentication/baseapi.md).
{% endhint %}

{% hint style="warning" %}
You need the [`organization:manage`](/identity/scopes-and-claims.md#organization-manage) scope to access this API.
{% endhint %}

{% hint style="info" %}
This is a JavaScript implementation of the [Organization API](/reference/organization-api.md).
{% endhint %}

{% hint style="success" %}
For ease of use we recommend using the [`User`](/reference/identity-javascript-sdk/the-base-package/authentication/user.md) object for interaction instead.
{% endhint %}

## Interfaces

### `RoleReference`

```typescript
interface RoleReference {
    name: string,
    id: string
}
```

### `MembershipInfo`

```typescript
interface MembershipInfo {
    roles: RoleReference[],
    firstName: string,
    lastName: string,
    email: string,
    organizationId: number,
    membershipId: string,
    userId: string
}
```

### `OrganizationCreateDetails`

```typescript
interface OrganizationCreateDetails {
    name: string,
    website: string,
    address: string,
    uniqueId: string,
    taxNumber: string,
    city: string,
    countryCode: string,
    zipCode: string,
    state?: string
}
```

### `OrganizationUpdateDetails`

```typescript
interface OrganizationUpdateDetails {
    name?: string,
    website?: string,
    address?: string,
    uniqueId?: string,
    taxNumber?: string,
    city?: string,
    countryCode?: string,
    zipCode?: string,
    state?: string
}
```

### `OrganizationInfo`

```typescript
interface OrganizationInfo {
    memberships: OrganizationMembershipReference[],
    id: number,
    name: string,
    website: string,
    address: string,
    uniqueId?: string,
    taxNumber: string,
    city: string,
    country: {
        alpha2: string,
        name: string 
    },
    zipCode: string,
    state: string,
    verified: boolean,
    created: number
}
```

### `OrganizationMembershipReference`

```typescript
interface OrganizationMembershipReference {
    organizationId: number,
    membershipId: string,
    userId: string
}
```

## Methods

### `constructor(user, endpoint)`

Create an Organization API object.

* `user` should be an instance of the [`User`](/reference/identity-javascript-sdk/the-base-package/authentication/user.md) object.
* `endpoint` should be the Vulos Identity endpoint.

```javascript
const organizationApi = new OrganizationApi(user, endpoint)
```

### `async organizationList()`

Get a list of all the organizations that the user is in.

The result is an array of objects that implement the [`OrganizationMembershipReference`](#organizationmembershipreference).

{% hint style="info" %}
This method's response has the `organization:list` [cache](/reference/identity-javascript-sdk/the-base-package/cache.md#addpolicy-key-lifespan) prefix.
{% endhint %}

```javascript
for (const membership of await organizationApi.organizationList()) {
    // do something with the membership
}
```

### `async organizationInfo(id)`

Get information of an organization by the organization's ID.

The result implements the [`OrganizationInfo`](#organizationinfo) interface.

{% hint style="info" %}
This method's response has the `organization:info` [cache](/reference/identity-javascript-sdk/the-base-package/cache.md#addpolicy-key-lifespan) prefix.
{% endhint %}

```javascript
const info = await organizationApi.organizationInfo(organizationId)
```

### `async organizationUpdate(id, details)`

Update an organization's details.

The `details` object implements the [`OrganizationUpdateDetails`](#organizationupdatedetails) interface.

The result implements the [`SuccessResponse`](/reference/identity-javascript-sdk/the-base-package/authentication/baseapi.md#successresponse) interface.

{% hint style="info" %}
This method's response has the `organization:update` [cache](/reference/identity-javascript-sdk/the-base-package/cache.md#addpolicy-key-lifespan) prefix.
{% endhint %}

```javascript
const response = await organizationApi.organizationUpdate(organizationId, {name: 'New Organization Name'})
if (response.success) {
    // the organization's name was updated successfully
}
```

### `async organizationDelete(id)`

Delete an organization.

The result implements the [`SuccessResponse`](/reference/identity-javascript-sdk/the-base-package/authentication/baseapi.md#successresponse) interface.

{% hint style="info" %}
This method's response has the `organization:delete` [cache](/reference/identity-javascript-sdk/the-base-package/cache.md#addpolicy-key-lifespan) prefix.
{% endhint %}

```javascript
const response = await organizationApi.organizationDelete(organizationId)
if (response.success) {
    // successfully deleted the organization
}
```

### `async organizationCreate(details)`

Create a new organization.

The `details` object implements the [`OrganizationCreateDetails`](#organizationcreatedetails) interface.

The result implements the [`OrganizationMembershipReference`](#organizationmembershipreference) interface.

{% hint style="info" %}
This method's response has the `organization:create` [cache](/reference/identity-javascript-sdk/the-base-package/cache.md#addpolicy-key-lifespan) prefix.
{% endhint %}

```javascript
const membership = await organizationApi.organizationCreate({
    name: 'My Organization',
    website: 'https://example.com',
    address: 'Example St. 1234',
    uniqueId: '1234-567-89',
    city: 'Example City',
    countryCode: 'AQ',
    zipCode: '1234',
    // state: 'Optional State'
})
```

### `async memberInfo(id, member)`

Get information about a specific member.

* `id` is the organization id;
* `member` is the membership id;

The result implements the [`MembershipInfo`](#membershipinfo) interface.

{% hint style="info" %}
This method's response has the `organization:member:info` [cache](/reference/identity-javascript-sdk/the-base-package/cache.md#addpolicy-key-lifespan) prefix.
{% endhint %}

```javascript
const memberInfo = await organizationApi.memberInfo(organizationId, membershipId)
```

### `async memberDelete(id, member)`

Remove a member from an organization.

The result implements the [`SuccessResponse`](/reference/identity-javascript-sdk/the-base-package/authentication/baseapi.md#successresponse) interface.

{% hint style="info" %}
This method's response has the `organization:member:delete` [cache](/reference/identity-javascript-sdk/the-base-package/cache.md#addpolicy-key-lifespan) prefix.
{% endhint %}

```javascript
const response = await organizationApi.memberDelete(organizationId, membershipId)
if (response.success) {
    // successfully deleted the membership
}
```

### `async memberInvite(id, email)`

Invite a user to an organization by email.

The result implements the [`SuccessResponse`](/reference/identity-javascript-sdk/the-base-package/authentication/baseapi.md#successresponse) interface.

{% hint style="info" %}
This method's response has the `organization:member:invite` [cache](/reference/identity-javascript-sdk/the-base-package/cache.md#addpolicy-key-lifespan) prefix.
{% endhint %}

```javascript
const response = await organizationApi.memberInvite(organizationId, email)
if (response.success) {
    // successfully invited the member
}
```

### `async roleList(id, member)`

Get all the roles for a member.

The result is an array of objects that implement the [`RoleReference`](#rolereference) interface.

{% hint style="info" %}
This method's response has the `organization:role:list` [cache](/reference/identity-javascript-sdk/the-base-package/cache.md#addpolicy-key-lifespan) prefix.
{% endhint %}

```javascript
const roles = await organizationApi.roleList(organizationId, membershipId)
for(const role of roles) {
    // do something with the role
}
```

### `async roleCreate(id, member, name)`

Add a new role to a user.

The result implements the [`RoleReference`](#rolereference) interface.

{% hint style="info" %}
This method's response has the `organization:role:create` [cache](/reference/identity-javascript-sdk/the-base-package/cache.md#addpolicy-key-lifespan) prefix.
{% endhint %}

```javascript
const role = await organizationApi.roleCreate(organizationId, membershipId, "Admin")
```

### `async roleDelete(id, member, role)`

Remove a role from a member.

* `role` is the role id;

The result implements the [`SuccessResponse`](/reference/identity-javascript-sdk/the-base-package/authentication/baseapi.md#successresponse) interface.

{% hint style="info" %}
This method's response has the `organization:role:delete` [cache](/reference/identity-javascript-sdk/the-base-package/cache.md#addpolicy-key-lifespan) prefix.
{% endhint %}

```javascript
const response = await organizationApi.roleDelete(organizationId, membershipId, roleId)
if (response.success) { 
    // successfully deleted the role
}
```
