# Invite new members

POST https://app.launchdarkly.com/api/v2/members
Content-Type: application/json

Invite one or more new members to join an account. Each member is sent an invitation. Members with Admin or Owner roles may create new members, as well as anyone with a `createMember` permission for "member/\*". If a member cannot be invited, the entire request is rejected and no members are invited from that request.

Each member _must_ have an `email` field and either a `role` or a `customRoles` field. If any of the fields are not populated correctly, the request is rejected with the reason specified in the "message" field of the response.

Valid base role names that you can provide for the `role` field include `reader`, `writer`, `admin`, `owner/admin`, and `no_access`. To learn more about base roles, read [Organization roles](https://launchdarkly.com/docs/home/account/roles/organization-roles).

If you are using the `customRoles` field instead, you can provide the key for any role that you have created, or for any preset [organization role](https://launchdarkly.com/docs/home/account/roles/organization-roles) or [project role](https://launchdarkly.com/docs/home/account/roles/project-roles) provided by LaunchDarkly. Some preset roles additionally require that you specify `roleAttributes`. To learn more, read [Using role scope](https://launchdarkly.com/docs/home/account/roles/role-scope).

Requests to create account members will not work if SCIM is enabled for the account.

_No more than 50 members may be created per request._

A request may also fail because of conflicts with existing members. These conflicts are reported using the additional `code` and `invalid_emails` response fields with the following possible values for `code`:

- **email_already_exists_in_account**: A member with this email address already exists in this account.
- **email_taken_in_different_account**: A member with this email address exists in another account.
- **duplicate_email**s: This request contains two or more members with the same email address.

A request that fails for one of the above reasons returns an HTTP response code of 400 (Bad Request).


Reference: https://launchdarkly.com/docs/api/account-members/post-members

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: LaunchDarkly REST API
  version: 1.0.0
paths:
  /api/v2/members:
    post:
      operationId: post-members
      summary: Invite new members
      description: >
        Invite one or more new members to join an account. Each member is sent
        an invitation. Members with Admin or Owner roles may create new members,
        as well as anyone with a `createMember` permission for "member/\*". If a
        member cannot be invited, the entire request is rejected and no members
        are invited from that request.


        Each member _must_ have an `email` field and either a `role` or a
        `customRoles` field. If any of the fields are not populated correctly,
        the request is rejected with the reason specified in the "message" field
        of the response.


        Valid base role names that you can provide for the `role` field include
        `reader`, `writer`, `admin`, `owner/admin`, and `no_access`. To learn
        more about base roles, read [Organization
        roles](https://launchdarkly.com/docs/home/account/roles/organization-roles).


        If you are using the `customRoles` field instead, you can provide the
        key for any role that you have created, or for any preset [organization
        role](https://launchdarkly.com/docs/home/account/roles/organization-roles)
        or [project
        role](https://launchdarkly.com/docs/home/account/roles/project-roles)
        provided by LaunchDarkly. Some preset roles additionally require that
        you specify `roleAttributes`. To learn more, read [Using role
        scope](https://launchdarkly.com/docs/home/account/roles/role-scope).


        Requests to create account members will not work if SCIM is enabled for
        the account.


        _No more than 50 members may be created per request._


        A request may also fail because of conflicts with existing members.
        These conflicts are reported using the additional `code` and
        `invalid_emails` response fields with the following possible values for
        `code`:


        - **email_already_exists_in_account**: A member with this email address
        already exists in this account.

        - **email_taken_in_different_account**: A member with this email address
        exists in another account.

        - **duplicate_email**s: This request contains two or more members with
        the same email address.


        A request that fails for one of the above reasons returns an HTTP
        response code of 400 (Bad Request).
      tags:
        - subpackage_accountMembers
      parameters:
        - name: Authorization
          in: header
          required: true
          schema:
            type: string
      responses:
        '201':
          description: Member collection response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Members'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InvalidRequestErrorRep'
        '401':
          description: Invalid access token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UnauthorizedErrorRep'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ForbiddenErrorRep'
        '409':
          description: Status conflict
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StatusConflictErrorRep'
        '429':
          description: Rate limited
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RateLimitedErrorRep'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/NewMemberFormListPost'
servers:
  - url: https://app.launchdarkly.com
  - url: https://app.launchdarkly.us
components:
  schemas:
    NewMemberFormRole:
      type: string
      enum:
        - reader
        - writer
        - admin
        - no_access
      description: >-
        The member's initial role, if you are using a base role for the initial
        role
      title: NewMemberFormRole
    RoleAttributeValues:
      type: array
      items:
        type: string
      title: RoleAttributeValues
    RoleAttributeMap:
      type: object
      additionalProperties:
        $ref: '#/components/schemas/RoleAttributeValues'
      title: RoleAttributeMap
    NewMemberForm:
      type: object
      properties:
        email:
          type: string
          description: The member's email
        password:
          type: string
          description: The member's password
        firstName:
          type: string
          description: The member's first name
        lastName:
          type: string
          description: The member's last name
        role:
          $ref: '#/components/schemas/NewMemberFormRole'
          description: >-
            The member's initial role, if you are using a base role for the
            initial role
        customRoles:
          type: array
          items:
            type: string
          description: >-
            An array of the member's initial roles, if you are using custom
            roles or preset roles provided by LaunchDarkly
        teamKeys:
          type: array
          items:
            type: string
          description: An array of the member's teams
        roleAttributes:
          $ref: '#/components/schemas/RoleAttributeMap'
          description: An object of role attributes for the member
      required:
        - email
      title: NewMemberForm
    NewMemberFormListPost:
      type: array
      items:
        $ref: '#/components/schemas/NewMemberForm'
      title: NewMemberFormListPost
    Link:
      type: object
      properties:
        href:
          type: string
          description: The URL of the link
        type:
          type: string
          description: The type of the link
      title: Link
    UnixMillis:
      type: integer
      format: int64
      title: UnixMillis
    LastSeenMetadata:
      type: object
      properties:
        tokenId:
          type: string
          description: The ID of the token used in the member's last session
      title: LastSeenMetadata
    IntegrationStatus:
      type: object
      properties:
        display:
          type: string
        value:
          type: string
      required:
        - display
        - value
      title: IntegrationStatus
    IntegrationMetadata:
      type: object
      properties:
        externalId:
          type: string
        externalStatus:
          $ref: '#/components/schemas/IntegrationStatus'
        externalUrl:
          type: string
        lastChecked:
          $ref: '#/components/schemas/UnixMillis'
      required:
        - externalId
        - externalStatus
        - externalUrl
        - lastChecked
      title: IntegrationMetadata
    MemberTeamSummaryRep:
      type: object
      properties:
        customRoleKeys:
          type: array
          items:
            type: string
          description: A list of keys of the custom roles this team has access to
        key:
          type: string
          description: The team key
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
        name:
          type: string
          description: The team name
      required:
        - customRoleKeys
        - key
        - name
      title: MemberTeamSummaryRep
    MemberPermissionGrantSummaryRep:
      type: object
      properties:
        actionSet:
          type: string
          description: >-
            The name of the group of related actions to allow. A permission
            grant may have either an <code>actionSet</code> or a list of
            <code>actions</code> but not both at the same time.
        actions:
          type: array
          items:
            type: string
          description: >-
            A list of actions to allow. A permission grant may have either an
            <code>actionSet</code> or a list of <code>actions</code> but not
            both at the same time.
        resource:
          type: string
          description: The resource for which the actions are allowed
      required:
        - resource
      title: MemberPermissionGrantSummaryRep
    OAuthProviderKind:
      type: string
      title: OAuthProviderKind
    Member:
      type: object
      properties:
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
          description: The location and content type of related resources
        _id:
          type: string
          description: The member's ID
        firstName:
          type: string
          description: The member's first name
        lastName:
          type: string
          description: The member's last name
        role:
          type: string
          description: >-
            The member's base role. If the member has no additional roles, this
            role will be in effect.
        email:
          type: string
          description: The member's email address
        _pendingInvite:
          type: boolean
          description: Whether the member has a pending invitation
        _verified:
          type: boolean
          description: Whether the member's email address has been verified
        _pendingEmail:
          type: string
          description: >-
            The member's email address before it has been verified, for accounts
            where email verification is required
        customRoles:
          type: array
          items:
            type: string
          description: >-
            The set of additional roles, besides the base role, assigned to the
            member
        mfa:
          type: string
          description: Whether multi-factor authentication is enabled for this member
        excludedDashboards:
          type: array
          items:
            type: string
          description: Default dashboards that the member has chosen to ignore
        _lastSeen:
          $ref: '#/components/schemas/UnixMillis'
          description: The member's last session date (as Unix milliseconds since epoch)
        _lastSeenMetadata:
          $ref: '#/components/schemas/LastSeenMetadata'
          description: >-
            Additional metadata associated with the member's last session, for
            example, whether a token was used
        _integrationMetadata:
          $ref: '#/components/schemas/IntegrationMetadata'
          description: >-
            Details on the member account in an external source, if this member
            is provisioned externally
        teams:
          type: array
          items:
            $ref: '#/components/schemas/MemberTeamSummaryRep'
          description: Details on the teams this member is assigned to
        permissionGrants:
          type: array
          items:
            $ref: '#/components/schemas/MemberPermissionGrantSummaryRep'
          description: >-
            A list of permission grants. Permission grants allow a member to
            have access to a specific action, without having to create or update
            a custom role.
        creationDate:
          $ref: '#/components/schemas/UnixMillis'
          description: Timestamp of when the member was created
        oauthProviders:
          type: array
          items:
            $ref: '#/components/schemas/OAuthProviderKind'
          description: A list of OAuth providers
        version:
          type: integer
          description: Version of the current configuration
        roleAttributes:
          $ref: '#/components/schemas/RoleAttributeMap'
          description: The role attributes for the member
      required:
        - _links
        - _id
        - role
        - email
        - _pendingInvite
        - _verified
        - customRoles
        - mfa
        - _lastSeen
        - creationDate
      title: Member
    Members:
      type: object
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/Member'
          description: An array of members
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
          description: The location and content type of related resources
        totalCount:
          type: integer
          description: The number of members returned
      required:
        - items
        - _links
      title: Members
    InvalidRequestErrorRep:
      type: object
      properties:
        code:
          type: string
          description: Specific error code encountered
        message:
          type: string
          description: Description of the error
      required:
        - code
        - message
      title: InvalidRequestErrorRep
    UnauthorizedErrorRep:
      type: object
      properties:
        code:
          type: string
          description: Specific error code encountered
        message:
          type: string
          description: Description of the error
      required:
        - code
        - message
      title: UnauthorizedErrorRep
    ForbiddenErrorRep:
      type: object
      properties:
        code:
          type: string
          description: Specific error code encountered
        message:
          type: string
          description: Description of the error
      required:
        - code
        - message
      title: ForbiddenErrorRep
    StatusConflictErrorRep:
      type: object
      properties:
        code:
          type: string
          description: Specific error code encountered
        message:
          type: string
          description: Description of the error
      required:
        - code
        - message
      title: StatusConflictErrorRep
    RateLimitedErrorRep:
      type: object
      properties:
        code:
          type: string
          description: Specific error code encountered
        message:
          type: string
          description: Description of the error
      required:
        - code
        - message
      title: RateLimitedErrorRep
  securitySchemes:
    ApiKey:
      type: apiKey
      in: header
      name: Authorization

```

## SDK Code Examples

```python
import requests

url = "https://app.launchdarkly.com/api/v2/members"

payload = [{ "email": "sandy@acme.com" }]
headers = {
    "Authorization": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://app.launchdarkly.com/api/v2/members';
const options = {
  method: 'POST',
  headers: {Authorization: '<apiKey>', 'Content-Type': 'application/json'},
  body: '[{"email":"sandy@acme.com"}]'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://app.launchdarkly.com/api/v2/members"

	payload := strings.NewReader("[\n  {\n    \"email\": \"sandy@acme.com\"\n  }\n]")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://app.launchdarkly.com/api/v2/members")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "[\n  {\n    \"email\": \"sandy@acme.com\"\n  }\n]"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://app.launchdarkly.com/api/v2/members")
  .header("Authorization", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("[\n  {\n    \"email\": \"sandy@acme.com\"\n  }\n]")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://app.launchdarkly.com/api/v2/members', [
  'body' => '[
  {
    "email": "sandy@acme.com"
  }
]',
  'headers' => [
    'Authorization' => '<apiKey>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://app.launchdarkly.com/api/v2/members");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "[\n  {\n    \"email\": \"sandy@acme.com\"\n  }\n]", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [["email": "sandy@acme.com"]] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://app.launchdarkly.com/api/v2/members")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```