# Create extinction

POST https://app.launchdarkly.com/api/v2/code-refs/repositories/{repo}/branches/{branch}/extinction-events
Content-Type: application/json

Create a new extinction.

Reference: https://launchdarkly.com/docs/api/code-references/post-extinction

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: LaunchDarkly REST API
  version: 1.0.0
paths:
  /api/v2/code-refs/repositories/{repo}/branches/{branch}/extinction-events:
    post:
      operationId: post-extinction
      summary: Create extinction
      description: Create a new extinction.
      tags:
        - subpackage_codeReferences
      parameters:
        - name: repo
          in: path
          description: The repository name
          required: true
          schema:
            type: string
            format: string
        - name: branch
          in: path
          description: The URL-encoded branch name
          required: true
          schema:
            type: string
            format: string
        - name: Authorization
          in: header
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Action succeeded
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/Code
                  references_postExtinction_Response_200
        '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: Invalid resource identifier
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NotFoundErrorRep'
        '429':
          description: Rate limited
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RateLimitedErrorRep'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ExtinctionListPost'
servers:
  - url: https://app.launchdarkly.com
  - url: https://app.launchdarkly.us
components:
  schemas:
    UnixMillis:
      type: integer
      format: int64
      title: UnixMillis
    Extinction:
      type: object
      properties:
        revision:
          type: string
          description: >-
            The identifier for the revision where flag became extinct. For
            example, a commit SHA.
        message:
          type: string
          description: >-
            Description of the extinction. For example, the commit message for
            the revision.
        time:
          $ref: '#/components/schemas/UnixMillis'
          description: Time of extinction
        flagKey:
          type: string
          description: The feature flag key
        projKey:
          type: string
          description: The project key
      required:
        - revision
        - message
        - time
        - flagKey
        - projKey
      title: Extinction
    ExtinctionListPost:
      type: array
      items:
        $ref: '#/components/schemas/Extinction'
      title: ExtinctionListPost
    Code references_postExtinction_Response_200:
      type: object
      properties: {}
      description: Empty response body
      title: Code references_postExtinction_Response_200
    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
    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/code-refs/repositories/repo/branches/branch/extinction-events"

payload = [
    {
        "revision": "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3",
        "message": "Remove flag for launched feature",
        "time": 1636558831870,
        "flagKey": "enable-feature",
        "projKey": "default"
    }
]
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/code-refs/repositories/repo/branches/branch/extinction-events';
const options = {
  method: 'POST',
  headers: {Authorization: '<apiKey>', 'Content-Type': 'application/json'},
  body: '[{"revision":"a94a8fe5ccb19ba61c4c0873d391e987982fbbd3","message":"Remove flag for launched feature","time":1636558831870,"flagKey":"enable-feature","projKey":"default"}]'
};

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/code-refs/repositories/repo/branches/branch/extinction-events"

	payload := strings.NewReader("[\n  {\n    \"revision\": \"a94a8fe5ccb19ba61c4c0873d391e987982fbbd3\",\n    \"message\": \"Remove flag for launched feature\",\n    \"time\": 1636558831870,\n    \"flagKey\": \"enable-feature\",\n    \"projKey\": \"default\"\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/code-refs/repositories/repo/branches/branch/extinction-events")

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    \"revision\": \"a94a8fe5ccb19ba61c4c0873d391e987982fbbd3\",\n    \"message\": \"Remove flag for launched feature\",\n    \"time\": 1636558831870,\n    \"flagKey\": \"enable-feature\",\n    \"projKey\": \"default\"\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/code-refs/repositories/repo/branches/branch/extinction-events")
  .header("Authorization", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("[\n  {\n    \"revision\": \"a94a8fe5ccb19ba61c4c0873d391e987982fbbd3\",\n    \"message\": \"Remove flag for launched feature\",\n    \"time\": 1636558831870,\n    \"flagKey\": \"enable-feature\",\n    \"projKey\": \"default\"\n  }\n]")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://app.launchdarkly.com/api/v2/code-refs/repositories/repo/branches/branch/extinction-events', [
  'body' => '[
  {
    "revision": "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3",
    "message": "Remove flag for launched feature",
    "time": 1636558831870,
    "flagKey": "enable-feature",
    "projKey": "default"
  }
]',
  'headers' => [
    'Authorization' => '<apiKey>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://app.launchdarkly.com/api/v2/code-refs/repositories/repo/branches/branch/extinction-events");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "[\n  {\n    \"revision\": \"a94a8fe5ccb19ba61c4c0873d391e987982fbbd3\",\n    \"message\": \"Remove flag for launched feature\",\n    \"time\": 1636558831870,\n    \"flagKey\": \"enable-feature\",\n    \"projKey\": \"default\"\n  }\n]", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  [
    "revision": "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3",
    "message": "Remove flag for launched feature",
    "time": 1636558831870,
    "flagKey": "enable-feature",
    "projKey": "default"
  ]
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://app.launchdarkly.com/api/v2/code-refs/repositories/repo/branches/branch/extinction-events")! 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()
```