> 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/organizationmembership.md).

# OrganizationMembership

## Members

### `api :` [`OrganizationApi`](/reference/identity-javascript-sdk/the-base-package/organizations/organizationapi.md)

The `OrganizationApi` that this object was created with.

### `organizationId : number`

The organization id that this membership is associated with.

### `membershipId : string`

The id of this membership.

### `userId : string`

The id of the user that this membership is associated with.

## Methods

### `constructor(api, membership)`

Create a new Membership object using the [Organization API](/reference/organization-api.md).

* `api` must be an instance of [`OrganizationApi`](/reference/identity-javascript-sdk/the-base-package/organizations/organizationapi.md);
* `membership` must implement the [`OrganizationMembershipReference`](/reference/identity-javascript-sdk/the-base-package/organizations/organizationapi.md#organizationmembershipreference) interface.

```javascript
const details = await organizationApi.organizationInfo(organizationId)
const [membershipData] = details.memberships
const membership = new OrganizationMembership(organizationApi, membershipData)
```

### `async addRole(name)`

Add a new role to this membership.

The result is an [`OrganizationRole`](/reference/identity-javascript-sdk/the-base-package/organizations/organizationrole.md) object or `false` if it failed.

```javascript
const role = await membership.addRole('Admin')
```

### `async getRoles()`

Get all the roles associated with this membership.

The result is an array of [`OrganizationRole`](/reference/identity-javascript-sdk/the-base-package/organizations/organizationrole.md) objects or `false` if it failed.

```javascript
const roles = await membership.getRoles()
```

### `async getOrganization()`

Get the organization associated with this membership.

The result is an [`Organization`](/reference/identity-javascript-sdk/the-base-package/organizations/organization.md) object or `false` if it failed.

```javascript
const organization = await membership.getOrganization()
```

### `reference()`

Create a [`UserReference`](/reference/identity-javascript-sdk/the-base-package/profile/userreference.md) object that is associated with this membership's user.

```javascript
const ref = membership.reference()
```

### `async organizationProfile()`

Get this membership's organization profile.

The result of this function implements the [`OrganizationProfileInfo`](/reference/identity-javascript-sdk/the-base-package/profile/profileapi.md#organizationprofileinfo) interface.

```javascript
const organizatonProfile = await membership.organizationProfile()
```

### `async remove()`

Remove this membership from the organization.

The result is a boolean that indicates success.

```javascript
if (await membership.remove()) {
    // the membership was successfully removed from the organization
}
```
