# Create flag link

POST https://app.launchdarkly.com/api/v2/flag-links/projects/{projectKey}/flags/{featureFlagKey}
Content-Type: application/json

Create a new flag link. Flag links let you reference external resources and associate them with your flags.

Reference: https://launchdarkly.com/docs/api/flag-links-beta/create-flag-link

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: LaunchDarkly REST API
  version: 1.0.0
paths:
  /api/v2/flag-links/projects/{projectKey}/flags/{featureFlagKey}:
    post:
      operationId: create-flag-link
      summary: Create flag link
      description: >-
        Create a new flag link. Flag links let you reference external resources
        and associate them with your flags.
      tags:
        - subpackage_flagLinksBeta
      parameters:
        - name: projectKey
          in: path
          description: The project key
          required: true
          schema:
            type: string
            format: string
        - name: featureFlagKey
          in: path
          description: The feature flag key
          required: true
          schema:
            type: string
            format: string
        - name: Authorization
          in: header
          required: true
          schema:
            type: string
      responses:
        '201':
          description: Flag link response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FlagLinkRep'
        '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/flagLinkPost'
servers:
  - url: https://app.launchdarkly.com
  - url: https://app.launchdarkly.us
components:
  schemas:
    UnixMillis:
      type: integer
      format: int64
      title: UnixMillis
    flagLinkPost:
      type: object
      properties:
        key:
          type: string
          description: The flag link key
        integrationKey:
          type: string
          description: >-
            The integration key for an integration whose
            <code>manifest.json</code> includes the <code>flagLink</code>
            capability, if this is a flag link for an existing integration. Do
            not include for URL flag links.
        timestamp:
          $ref: '#/components/schemas/UnixMillis'
          description: >-
            The time, in Unix milliseconds, to mark this flag link as associated
            with the external URL. If omitted, defaults to the creation time of
            this flag link.
        deepLink:
          type: string
          description: The URL for the external resource you are linking the flag to
        title:
          type: string
          description: The title of the flag link
        description:
          type: string
          description: The description of the flag link
        metadata:
          type: object
          additionalProperties:
            type: string
          description: >-
            The metadata required by this integration in order to create a flag
            link, if this is a flag link for an existing integration. Defined in
            the integration's <code>manifest.json</code> file under
            <code>flagLink</code>.
      title: flagLinkPost
    Link:
      type: object
      properties:
        href:
          type: string
          description: The URL of the link
        type:
          type: string
          description: The type of the link
      title: Link
    TimestampRep:
      type: object
      properties:
        milliseconds:
          $ref: '#/components/schemas/UnixMillis'
        seconds:
          type: integer
          format: int64
        rfc3339:
          type: string
        simple:
          type: string
      title: TimestampRep
    FlagLinkMember:
      type: object
      properties:
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
        _id:
          type: string
        firstName:
          type: string
        lastName:
          type: string
      required:
        - _links
        - _id
      title: FlagLinkMember
    FlagLinkRep:
      type: object
      properties:
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
          description: The location and content type of related resources
        _key:
          type: string
          description: The flag link key
        _integrationKey:
          type: string
          description: >-
            The integration key for an integration whose
            <code>manifest.json</code> includes the <code>flagLink</code>
            capability, if this is a flag link for an existing integration
        _id:
          type: string
          description: The ID of this flag link
        _deepLink:
          type: string
          description: The URL for the external resource the flag is linked to
        _timestamp:
          $ref: '#/components/schemas/TimestampRep'
          description: >-
            The time to mark this flag link as associated with the external URL.
            Defaults to the creation time of the flag link, but can be set to
            another time during creation.
        title:
          type: string
          description: The title of the flag link
        description:
          type: string
          description: The description of the flag link
        _metadata:
          type: object
          additionalProperties:
            type: string
          description: >-
            The metadata required by this integration in order to create a flag
            link, if this is a flag link for an existing integration. Defined in
            the integration's <code>manifest.json</code> file under
            <code>flagLink</code>.
        _createdAt:
          $ref: '#/components/schemas/UnixMillis'
          description: Timestamp of when the flag link was created
        _member:
          $ref: '#/components/schemas/FlagLinkMember'
          description: Details on the member associated with this flag link
      required:
        - _links
        - _id
        - _deepLink
        - _timestamp
        - _createdAt
      title: FlagLinkRep
    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/flag-links/projects/projectKey/flags/featureFlagKey"

payload = {
    "key": "flag-link-key-123abc",
    "deepLink": "https://example.com/archives/123123123",
    "title": "Example link title",
    "description": "Example link description"
}
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/flag-links/projects/projectKey/flags/featureFlagKey';
const options = {
  method: 'POST',
  headers: {Authorization: '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"key":"flag-link-key-123abc","deepLink":"https://example.com/archives/123123123","title":"Example link title","description":"Example link description"}'
};

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/flag-links/projects/projectKey/flags/featureFlagKey"

	payload := strings.NewReader("{\n  \"key\": \"flag-link-key-123abc\",\n  \"deepLink\": \"https://example.com/archives/123123123\",\n  \"title\": \"Example link title\",\n  \"description\": \"Example link description\"\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/flag-links/projects/projectKey/flags/featureFlagKey")

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  \"key\": \"flag-link-key-123abc\",\n  \"deepLink\": \"https://example.com/archives/123123123\",\n  \"title\": \"Example link title\",\n  \"description\": \"Example link description\"\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/flag-links/projects/projectKey/flags/featureFlagKey")
  .header("Authorization", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"key\": \"flag-link-key-123abc\",\n  \"deepLink\": \"https://example.com/archives/123123123\",\n  \"title\": \"Example link title\",\n  \"description\": \"Example link description\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://app.launchdarkly.com/api/v2/flag-links/projects/projectKey/flags/featureFlagKey', [
  'body' => '{
  "key": "flag-link-key-123abc",
  "deepLink": "https://example.com/archives/123123123",
  "title": "Example link title",
  "description": "Example link description"
}',
  'headers' => [
    'Authorization' => '<apiKey>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://app.launchdarkly.com/api/v2/flag-links/projects/projectKey/flags/featureFlagKey");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"key\": \"flag-link-key-123abc\",\n  \"deepLink\": \"https://example.com/archives/123123123\",\n  \"title\": \"Example link title\",\n  \"description\": \"Example link description\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "key": "flag-link-key-123abc",
  "deepLink": "https://example.com/archives/123123123",
  "title": "Example link title",
  "description": "Example link description"
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://app.launchdarkly.com/api/v2/flag-links/projects/projectKey/flags/featureFlagKey")! 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()
```