# 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
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dev.vulos.io/reference/identity-javascript-sdk/the-base-package/organizations/organizationmembership.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
