# Update teams

PATCH https://app.launchdarkly.com/api/v2/teams
Content-Type: application/json

Perform a partial update to multiple teams. Updating teams uses the semantic patch format.

To make a semantic patch request, you must append `domain-model=launchdarkly.semanticpatch` to your `Content-Type` header. To learn more, read [Updates using semantic patch](https://launchdarkly.com/docs/api#updates-using-semantic-patch).

### Instructions

Semantic patch requests support the following `kind` instructions for updating teams.

<details>
<summary>Click to expand instructions for <strong>updating teams</strong></summary>

#### addMembersToTeams

Add the members to teams.

##### Parameters

- `memberIDs`: List of member IDs to add.
- `teamKeys`: List of teams to update.

Here's an example:

```json
{
  "instructions": [{
    "kind": "addMembersToTeams",
    "memberIDs": [
      "1234a56b7c89d012345e678f"
    ],
    "teamKeys": [
      "example-team-1",
      "example-team-2"
    ]
  }]
}
```

#### addAllMembersToTeams

Add all members to the team. Members that match any of the filters are **excluded** from the update.

##### Parameters

- `teamKeys`: List of teams to update.
- `filterLastSeen`: (Optional) A JSON object with one of the following formats:
  - `{"never": true}` - Members that have never been active, such as those who have not accepted their invitation to LaunchDarkly, or have not logged in after being provisioned via SCIM.
  - `{"noData": true}` - Members that have not been active since LaunchDarkly began recording last seen timestamps.
  - `{"before": 1608672063611}` - Members that have not been active since the provided value, which should be a timestamp in Unix epoch milliseconds.
- `filterQuery`: (Optional) A string that matches against the members' emails and names. It is not case sensitive.
- `filterRoles`: (Optional) A `|` separated list of roles and custom roles. For the purposes of this filtering, `Owner` counts as `Admin`.
- `filterTeamKey`: (Optional) A string that matches against the key of the team the members belong to. It is not case sensitive.
- `ignoredMemberIDs`: (Optional) A list of member IDs.

Here's an example:

```json
{
  "instructions": [{
    "kind": "addAllMembersToTeams",
    "teamKeys": [
      "example-team-1",
      "example-team-2"
    ],
    "filterLastSeen": { "never": true }
  }]
}
```

</details>


Reference: https://launchdarkly.com/docs/api/teams-beta/patch-teams

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: LaunchDarkly REST API
  version: 1.0.0
paths:
  /api/v2/teams:
    patch:
      operationId: patch-teams
      summary: Update teams
      description: >
        Perform a partial update to multiple teams. Updating teams uses the
        semantic patch format.


        To make a semantic patch request, you must append
        `domain-model=launchdarkly.semanticpatch` to your `Content-Type` header.
        To learn more, read [Updates using semantic
        patch](https://launchdarkly.com/docs/api#updates-using-semantic-patch).


        ### Instructions


        Semantic patch requests support the following `kind` instructions for
        updating teams.


        <details>

        <summary>Click to expand instructions for <strong>updating
        teams</strong></summary>


        #### addMembersToTeams


        Add the members to teams.


        ##### Parameters


        - `memberIDs`: List of member IDs to add.

        - `teamKeys`: List of teams to update.


        Here's an example:


        ```json

        {
          "instructions": [{
            "kind": "addMembersToTeams",
            "memberIDs": [
              "1234a56b7c89d012345e678f"
            ],
            "teamKeys": [
              "example-team-1",
              "example-team-2"
            ]
          }]
        }

        ```


        #### addAllMembersToTeams


        Add all members to the team. Members that match any of the filters are
        **excluded** from the update.


        ##### Parameters


        - `teamKeys`: List of teams to update.

        - `filterLastSeen`: (Optional) A JSON object with one of the following
        formats:
          - `{"never": true}` - Members that have never been active, such as those who have not accepted their invitation to LaunchDarkly, or have not logged in after being provisioned via SCIM.
          - `{"noData": true}` - Members that have not been active since LaunchDarkly began recording last seen timestamps.
          - `{"before": 1608672063611}` - Members that have not been active since the provided value, which should be a timestamp in Unix epoch milliseconds.
        - `filterQuery`: (Optional) A string that matches against the members'
        emails and names. It is not case sensitive.

        - `filterRoles`: (Optional) A `|` separated list of roles and custom
        roles. For the purposes of this filtering, `Owner` counts as `Admin`.

        - `filterTeamKey`: (Optional) A string that matches against the key of
        the team the members belong to. It is not case sensitive.

        - `ignoredMemberIDs`: (Optional) A list of member IDs.


        Here's an example:


        ```json

        {
          "instructions": [{
            "kind": "addAllMembersToTeams",
            "teamKeys": [
              "example-team-1",
              "example-team-2"
            ],
            "filterLastSeen": { "never": true }
          }]
        }

        ```


        </details>
      tags:
        - subpackage_teamsBeta
      parameters:
        - name: Authorization
          in: header
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Teams response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BulkEditTeamsRep'
        '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/teamsPatchInput'
servers:
  - url: https://app.launchdarkly.com
  - url: https://app.launchdarkly.us
components:
  schemas:
    Instruction:
      type: object
      additionalProperties:
        description: Any type
      title: Instruction
    Instructions:
      type: array
      items:
        $ref: '#/components/schemas/Instruction'
      title: Instructions
    teamsPatchInput:
      type: object
      properties:
        comment:
          type: string
          description: Optional comment describing the update
        instructions:
          $ref: '#/components/schemas/Instructions'
          description: >-
            The instructions to perform when updating. This should be an array
            with objects that look like <code>{"kind": "update_action"}</code>.
            Some instructions also require additional parameters as part of this
            object.
      required:
        - instructions
      title: teamsPatchInput
    BulkEditTeamsRep:
      type: object
      properties:
        memberIDs:
          type: array
          items:
            type: string
          description: A list of member IDs of the members who were added to the teams.
        teamKeys:
          type: array
          items:
            type: string
          description: A list of team keys of the teams that were successfully updated.
        errors:
          type: array
          items:
            type: object
            additionalProperties:
              type: string
          description: A list of team keys and errors for the teams whose updates failed.
      title: BulkEditTeamsRep
    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/teams"

payload = {
    "instructions": [
        {
            "kind": "addMembersToTeams",
            "memberIDs": ["1234a56b7c89d012345e678f"],
            "teamKeys": ["example-team-1", "example-team-2"]
        }
    ],
    "comment": "Optional comment about the update"
}
headers = {
    "Authorization": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://app.launchdarkly.com/api/v2/teams';
const options = {
  method: 'PATCH',
  headers: {Authorization: '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"instructions":[{"kind":"addMembersToTeams","memberIDs":["1234a56b7c89d012345e678f"],"teamKeys":["example-team-1","example-team-2"]}],"comment":"Optional comment about the update"}'
};

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

	payload := strings.NewReader("{\n  \"instructions\": [\n    {\n      \"kind\": \"addMembersToTeams\",\n      \"memberIDs\": [\n        \"1234a56b7c89d012345e678f\"\n      ],\n      \"teamKeys\": [\n        \"example-team-1\",\n        \"example-team-2\"\n      ]\n    }\n  ],\n  \"comment\": \"Optional comment about the update\"\n}")

	req, _ := http.NewRequest("PATCH", 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/teams")

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

request = Net::HTTP::Patch.new(url)
request["Authorization"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"instructions\": [\n    {\n      \"kind\": \"addMembersToTeams\",\n      \"memberIDs\": [\n        \"1234a56b7c89d012345e678f\"\n      ],\n      \"teamKeys\": [\n        \"example-team-1\",\n        \"example-team-2\"\n      ]\n    }\n  ],\n  \"comment\": \"Optional comment about the update\"\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.patch("https://app.launchdarkly.com/api/v2/teams")
  .header("Authorization", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"instructions\": [\n    {\n      \"kind\": \"addMembersToTeams\",\n      \"memberIDs\": [\n        \"1234a56b7c89d012345e678f\"\n      ],\n      \"teamKeys\": [\n        \"example-team-1\",\n        \"example-team-2\"\n      ]\n    }\n  ],\n  \"comment\": \"Optional comment about the update\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('PATCH', 'https://app.launchdarkly.com/api/v2/teams', [
  'body' => '{
  "instructions": [
    {
      "kind": "addMembersToTeams",
      "memberIDs": [
        "1234a56b7c89d012345e678f"
      ],
      "teamKeys": [
        "example-team-1",
        "example-team-2"
      ]
    }
  ],
  "comment": "Optional comment about the update"
}',
  'headers' => [
    'Authorization' => '<apiKey>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://app.launchdarkly.com/api/v2/teams");
var request = new RestRequest(Method.PATCH);
request.AddHeader("Authorization", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"instructions\": [\n    {\n      \"kind\": \"addMembersToTeams\",\n      \"memberIDs\": [\n        \"1234a56b7c89d012345e678f\"\n      ],\n      \"teamKeys\": [\n        \"example-team-1\",\n        \"example-team-2\"\n      ]\n    }\n  ],\n  \"comment\": \"Optional comment about the update\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "instructions": [
    [
      "kind": "addMembersToTeams",
      "memberIDs": ["1234a56b7c89d012345e678f"],
      "teamKeys": ["example-team-1", "example-team-2"]
    ]
  ],
  "comment": "Optional comment about the update"
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://app.launchdarkly.com/api/v2/teams")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PATCH"
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()
```