# Add a member to teams

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

Add one member to one or more teams.

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

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: LaunchDarkly REST API
  version: 1.0.0
paths:
  /api/v2/members/{id}/teams:
    post:
      operationId: post-member-teams
      summary: Add a member to teams
      description: Add one member to one or more teams.
      tags:
        - subpackage_accountMembers
      parameters:
        - name: id
          in: path
          description: The member ID
          required: true
          schema:
            type: string
            format: string
        - name: Authorization
          in: header
          required: true
          schema:
            type: string
      responses:
        '201':
          description: Member response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Member'
        '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'
        '404':
          description: Member not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NotFoundErrorRep'
        '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/MemberTeamsPostInput'
servers:
  - url: https://app.launchdarkly.com
  - url: https://app.launchdarkly.us
components:
  schemas:
    MemberTeamsPostInput:
      type: object
      properties:
        teamKeys:
          type: array
          items:
            type: string
          description: List of team keys
      required:
        - teamKeys
      title: MemberTeamsPostInput
    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
    RoleAttributeValues:
      type: array
      items:
        type: string
      title: RoleAttributeValues
    RoleAttributeMap:
      type: object
      additionalProperties:
        $ref: '#/components/schemas/RoleAttributeValues'
      title: RoleAttributeMap
    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
    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
    NotFoundErrorRep:
      type: object
      properties:
        code:
          type: string
          description: Specific error code encountered
        message:
          type: string
          description: Description of the error
      required:
        - code
        - message
      title: NotFoundErrorRep
    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/id/teams"

payload = { "teamKeys": ["team1", "team2"] }
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/id/teams';
const options = {
  method: 'POST',
  headers: {Authorization: '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"teamKeys":["team1","team2"]}'
};

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/id/teams"

	payload := strings.NewReader("{\n  \"teamKeys\": [\n    \"team1\",\n    \"team2\"\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/id/teams")

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  \"teamKeys\": [\n    \"team1\",\n    \"team2\"\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/id/teams")
  .header("Authorization", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"teamKeys\": [\n    \"team1\",\n    \"team2\"\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/id/teams', [
  'body' => '{
  "teamKeys": [
    "team1",
    "team2"
  ]
}',
  'headers' => [
    'Authorization' => '<apiKey>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

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

```swift
import Foundation

let headers = [
  "Authorization": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = ["teamKeys": ["team1", "team2"]] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://app.launchdarkly.com/api/v2/members/id/teams")! 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()
```