# Get expiring targets for segment

GET https://app.launchdarkly.com/api/v2/segments/{projectKey}/{segmentKey}/expiring-targets/{environmentKey}

Get a list of a segment's context targets that are scheduled for removal.

Reference: https://launchdarkly.com/docs/api/segments/get-expiring-targets-for-segment

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: LaunchDarkly REST API
  version: 1.0.0
paths:
  /api/v2/segments/{projectKey}/{segmentKey}/expiring-targets/{environmentKey}:
    get:
      operationId: get-expiring-targets-for-segment
      summary: Get expiring targets for segment
      description: >-
        Get a list of a segment's context targets that are scheduled for
        removal.
      tags:
        - subpackage_segments
      parameters:
        - name: projectKey
          in: path
          description: The project key
          required: true
          schema:
            type: string
            format: string
        - name: environmentKey
          in: path
          description: The environment key
          required: true
          schema:
            type: string
            format: string
        - name: segmentKey
          in: path
          description: The segment key
          required: true
          schema:
            type: string
            format: string
        - name: Authorization
          in: header
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Expiring context target response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExpiringTargetGetResponse'
        '401':
          description: Invalid access token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UnauthorizedErrorRep'
        '404':
          description: Invalid resource identifier
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NotFoundErrorRep'
        '429':
          description: Rate limited
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RateLimitedErrorRep'
servers:
  - url: https://app.launchdarkly.com
  - url: https://app.launchdarkly.us
components:
  schemas:
    UnixMillis:
      type: integer
      format: int64
      title: UnixMillis
    ResourceKind:
      type: string
      title: ResourceKind
    ResourceId:
      type: object
      properties:
        environmentKey:
          type: string
          description: The environment key
        flagKey:
          type: string
          description: Deprecated, use <code>key</code> instead
        key:
          type: string
          description: The key of the flag or segment
        kind:
          $ref: '#/components/schemas/ResourceKind'
          description: The type of resource, <code>flag</code> or <code>segment</code>
        projectKey:
          type: string
          description: The project key
      title: ResourceId
    ExpiringTarget:
      type: object
      properties:
        _id:
          type: string
          description: The ID of this expiring target
        _version:
          type: integer
          description: The version of this expiring target
        expirationDate:
          $ref: '#/components/schemas/UnixMillis'
          description: A timestamp for when the target expires
        contextKind:
          type: string
          description: The context kind of the context to be removed
        contextKey:
          type: string
          description: A unique key used to represent the context to be removed
        targetType:
          type: string
          description: >-
            A segment's target type, <code>included</code> or
            <code>excluded</code>. Included when expiring targets are updated on
            a segment.
        variationId:
          type: string
          description: >-
            A unique ID used to represent the flag variation. Included when
            expiring targets are updated on a feature flag.
        _resourceId:
          $ref: '#/components/schemas/ResourceId'
          description: >-
            Details on the segment or flag this expiring target belongs to, its
            environment, and its project
      required:
        - _id
        - _version
        - expirationDate
        - contextKind
        - contextKey
        - _resourceId
      title: ExpiringTarget
    Link:
      type: object
      properties:
        href:
          type: string
          description: The URL of the link
        type:
          type: string
          description: The type of the link
      title: Link
    ExpiringTargetGetResponse:
      type: object
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/ExpiringTarget'
          description: A list of expiring targets
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
          description: The location and content type of related resources
      required:
        - items
      title: ExpiringTargetGetResponse
    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
    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
    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/segments/projectKey/segmentKey/expiring-targets/environmentKey"

headers = {"Authorization": "<apiKey>"}

response = requests.get(url, headers=headers)

print(response.json())
```

```javascript
const url = 'https://app.launchdarkly.com/api/v2/segments/projectKey/segmentKey/expiring-targets/environmentKey';
const options = {method: 'GET', headers: {Authorization: '<apiKey>'}};

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"
	"net/http"
	"io"
)

func main() {

	url := "https://app.launchdarkly.com/api/v2/segments/projectKey/segmentKey/expiring-targets/environmentKey"

	req, _ := http.NewRequest("GET", url, nil)

	req.Header.Add("Authorization", "<apiKey>")

	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/segments/projectKey/segmentKey/expiring-targets/environmentKey")

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

request = Net::HTTP::Get.new(url)
request["Authorization"] = '<apiKey>'

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.get("https://app.launchdarkly.com/api/v2/segments/projectKey/segmentKey/expiring-targets/environmentKey")
  .header("Authorization", "<apiKey>")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://app.launchdarkly.com/api/v2/segments/projectKey/segmentKey/expiring-targets/environmentKey', [
  'headers' => [
    'Authorization' => '<apiKey>',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://app.launchdarkly.com/api/v2/segments/projectKey/segmentKey/expiring-targets/environmentKey");
var request = new RestRequest(Method.GET);
request.AddHeader("Authorization", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Authorization": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://app.launchdarkly.com/api/v2/segments/projectKey/segmentKey/expiring-targets/environmentKey")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers

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()
```