# Unlink resource

DELETE https://app.launchdarkly.com/api/v2/projects/{projectKey}/views/{viewKey}/link/{resourceType}
Content-Type: application/json

Unlink one or multiple resources from a view:
- Unlink flags using flag keys
- Unlink segments using segment IDs


Reference: https://launchdarkly.com/docs/api/views-beta/unlink-resource

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: LaunchDarkly REST API
  version: 1.0.0
paths:
  /api/v2/projects/{projectKey}/views/{viewKey}/link/{resourceType}:
    delete:
      operationId: unlink-resource
      summary: Unlink resource
      description: |
        Unlink one or multiple resources from a view:
        - Unlink flags using flag keys
        - Unlink segments using segment IDs
      tags:
        - subpackage_viewsBeta
      parameters:
        - name: projectKey
          in: path
          required: true
          schema:
            type: string
        - name: viewKey
          in: path
          required: true
          schema:
            type: string
        - name: resourceType
          in: path
          required: true
          schema:
            $ref: >-
              #/components/schemas/ApiV2ProjectsProjectKeyViewsViewKeyLinkResourceTypeDeleteParametersResourceType
        - name: Authorization
          in: header
          required: true
          schema:
            type: string
        - name: LD-API-Version
          in: header
          description: Version of the endpoint.
          required: true
          schema:
            $ref: >-
              #/components/schemas/ApiV2ProjectsProjectKeyViewsViewKeyLinkResourceTypeDeleteParametersLdApiVersion
      responses:
        '200':
          description: Successful response with unlink details
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UnlinkResourceSuccessResponse'
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      requestBody:
        description: >-
          The resource to link to the view. Flags are identified by key.
          Segments are identified by segment ID.
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ViewLinkRequest'
servers:
  - url: https://app.launchdarkly.com
  - url: https://app.launchdarkly.us
components:
  schemas:
    ApiV2ProjectsProjectKeyViewsViewKeyLinkResourceTypeDeleteParametersResourceType:
      type: string
      enum:
        - flags
        - segments
      title: >-
        ApiV2ProjectsProjectKeyViewsViewKeyLinkResourceTypeDeleteParametersResourceType
    ApiV2ProjectsProjectKeyViewsViewKeyLinkResourceTypeDeleteParametersLdApiVersion:
      type: string
      enum:
        - beta
      title: >-
        ApiV2ProjectsProjectKeyViewsViewKeyLinkResourceTypeDeleteParametersLdApiVersion
    ViewLinkRequestKeys:
      type: object
      properties:
        keys:
          type: array
          items:
            type: string
          description: Keys of the resources (flags, segments) to link/unlink
        filter:
          type: string
          description: >
            Optional filter string to determine which resources should be
            linked. Resources only need to match either the filter or
            explicitly-listed keys to be linked (union).

            Uses the same syntax as list endpoints: flags use comma-separated
            field:value filters, segments use queryfilter syntax.


            Supported filters by resource type:

            - flags: query, tags, maintainerId, maintainerTeamKey, type, status,
            state, staleState, sdkAvailability, targeting, hasExperiment,
            hasDataExport, evaluated, creationDate, contextKindTargeted,
            contextKindsEvaluated, filterEnv, segmentTargeted,
            codeReferences.min, codeReferences.max, excludeSettings,
            releasePipeline, applicationEvaluated, purpose, guardedRollout,
            view, key, name, archived, followerId

            - segments (queryfilter): query, tags, keys, excludedKeys,
            unbounded, external, view, type

            Some filters are only available when the corresponding feature is
            enabled on your account.
        comment:
          type: string
          default: ''
          description: Optional comment for the link/unlink operation
      required:
        - keys
      title: ViewLinkRequestKeys
    ViewLinkRequestSegmentIdentifier:
      type: object
      properties:
        environmentId:
          type: string
        segmentKey:
          type: string
      required:
        - environmentId
        - segmentKey
      title: ViewLinkRequestSegmentIdentifier
    ViewLinkRequestSegmentIdentifiers:
      type: object
      properties:
        segmentIdentifiers:
          type: array
          items:
            $ref: '#/components/schemas/ViewLinkRequestSegmentIdentifier'
          description: >-
            Identifiers of the segments to link/unlink (environmentId and
            segmentKey)
        filter:
          type: string
          description: >
            Optional filter string to determine which resources should be
            linked. Resources only need to match either the filter or
            explicitly-listed keys to be linked (union).

            Uses the same queryfilter syntax as the segments list endpoint.


            Supported filters for segments: query, tags, keys, excludedKeys,
            unbounded, external, view, type
        environmentId:
          type: string
          description: >
            Required when using filter for segment resources. Specifies which
            environment to query for segments matching the filter.

            Ignored when only using explicit segmentIdentifiers (since each
            identifier contains its own environmentId).
        comment:
          type: string
          default: ''
          description: Optional comment for the link/unlink operation
      required:
        - segmentIdentifiers
      title: ViewLinkRequestSegmentIdentifiers
    ViewLinkRequestFilter:
      type: object
      properties:
        filter:
          type: string
          description: >
            Filter string to match resources for linking. Uses the same syntax
            as list endpoints: flags use comma-separated field:value filters,
            segments use queryfilter syntax.


            Supported filters by resource type:

            - flags: query, tags, maintainerId, maintainerTeamKey, type, status,
            state, staleState, sdkAvailability, targeting, hasExperiment,
            hasDataExport, evaluated, creationDate, contextKindTargeted,
            contextKindsEvaluated, filterEnv, segmentTargeted,
            codeReferences.min, codeReferences.max, excludeSettings,
            releasePipeline, applicationEvaluated, purpose, guardedRollout,
            view, key, name, archived, followerId

            - segments (queryfilter): query, tags, keys, excludedKeys,
            unbounded, external, view, type

            Some filters are only available when the corresponding feature is
            enabled on your account.
        environmentId:
          type: string
          description: >
            Required when using filter for segment resources. Specifies which
            environment to query for segments matching the filter.

            Ignored for flag resources (flags are global across environments).
        comment:
          type: string
          default: ''
          description: Optional comment for the link/unlink operation
      required:
        - filter
      title: ViewLinkRequestFilter
    ViewLinkRequest:
      oneOf:
        - $ref: '#/components/schemas/ViewLinkRequestKeys'
        - $ref: '#/components/schemas/ViewLinkRequestSegmentIdentifiers'
        - $ref: '#/components/schemas/ViewLinkRequestFilter'
      title: ViewLinkRequest
    FailedResourceLinkResourceType:
      type: string
      enum:
        - flag
        - segment
      description: The type of the resource that failed to link.
      title: FailedResourceLinkResourceType
    FailedResourceLink:
      type: object
      properties:
        resourceKey:
          type: string
          description: The key of the resource that failed to link.
        environmentId:
          type: string
          description: Environment ID of the resource (only present for segments)
        resourceType:
          $ref: '#/components/schemas/FailedResourceLinkResourceType'
          description: The type of the resource that failed to link.
        errorMessage:
          type: string
          description: The reason why linking this resource failed.
      required:
        - resourceKey
        - resourceType
        - errorMessage
      title: FailedResourceLink
    UnlinkResourceSuccessResponse:
      type: object
      properties:
        successCount:
          type: integer
          description: The number of resources successfully unlinked.
        failureCount:
          type: integer
          description: The number of resources that failed to unlink.
        failedResources:
          type: array
          items:
            $ref: '#/components/schemas/FailedResourceLink'
          description: Details of resources that failed to unlink.
      required:
        - successCount
        - failureCount
      title: UnlinkResourceSuccessResponse
    Error:
      type: object
      properties:
        message:
          type: string
        code:
          type: string
      required:
        - message
        - code
      title: Error
  securitySchemes:
    ApiKey:
      type: apiKey
      in: header
      name: Authorization

```

## SDK Code Examples

```python
import requests

url = "https://app.launchdarkly.com/api/v2/projects/default/views/my-view/link/flags"

payload = {
    "keys": ["flag-1", "flag-2"],
    "filter": "maintainerId:507f1f77bcf86cd799439011,tags:backend+beta",
    "comment": ""
}
headers = {
    "LD-API-Version": "beta",
    "Authorization": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://app.launchdarkly.com/api/v2/projects/default/views/my-view/link/flags';
const options = {
  method: 'DELETE',
  headers: {
    'LD-API-Version': 'beta',
    Authorization: '<apiKey>',
    'Content-Type': 'application/json'
  },
  body: '{"keys":["flag-1","flag-2"],"filter":"maintainerId:507f1f77bcf86cd799439011,tags:backend+beta","comment":""}'
};

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/projects/default/views/my-view/link/flags"

	payload := strings.NewReader("{\n  \"keys\": [\n    \"flag-1\",\n    \"flag-2\"\n  ],\n  \"filter\": \"maintainerId:507f1f77bcf86cd799439011,tags:backend+beta\",\n  \"comment\": \"\"\n}")

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

	req.Header.Add("LD-API-Version", "beta")
	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/projects/default/views/my-view/link/flags")

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

request = Net::HTTP::Delete.new(url)
request["LD-API-Version"] = 'beta'
request["Authorization"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"keys\": [\n    \"flag-1\",\n    \"flag-2\"\n  ],\n  \"filter\": \"maintainerId:507f1f77bcf86cd799439011,tags:backend+beta\",\n  \"comment\": \"\"\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.delete("https://app.launchdarkly.com/api/v2/projects/default/views/my-view/link/flags")
  .header("LD-API-Version", "beta")
  .header("Authorization", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"keys\": [\n    \"flag-1\",\n    \"flag-2\"\n  ],\n  \"filter\": \"maintainerId:507f1f77bcf86cd799439011,tags:backend+beta\",\n  \"comment\": \"\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('DELETE', 'https://app.launchdarkly.com/api/v2/projects/default/views/my-view/link/flags', [
  'body' => '{
  "keys": [
    "flag-1",
    "flag-2"
  ],
  "filter": "maintainerId:507f1f77bcf86cd799439011,tags:backend+beta",
  "comment": ""
}',
  'headers' => [
    'Authorization' => '<apiKey>',
    'Content-Type' => 'application/json',
    'LD-API-Version' => 'beta',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://app.launchdarkly.com/api/v2/projects/default/views/my-view/link/flags");
var request = new RestRequest(Method.DELETE);
request.AddHeader("LD-API-Version", "beta");
request.AddHeader("Authorization", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"keys\": [\n    \"flag-1\",\n    \"flag-2\"\n  ],\n  \"filter\": \"maintainerId:507f1f77bcf86cd799439011,tags:backend+beta\",\n  \"comment\": \"\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "LD-API-Version": "beta",
  "Authorization": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "keys": ["flag-1", "flag-2"],
  "filter": "maintainerId:507f1f77bcf86cd799439011,tags:backend+beta",
  "comment": ""
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://app.launchdarkly.com/api/v2/projects/default/views/my-view/link/flags")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "DELETE"
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()
```