# Create approval request for a flag

POST https://app.launchdarkly.com/api/v2/projects/{projectKey}/flags/{featureFlagKey}/environments/{environmentKey}/approval-requests
Content-Type: application/json

Create an approval request for a feature flag.

Reference: https://launchdarkly.com/docs/api/approvals/post-approval-request-for-flag

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: LaunchDarkly REST API
  version: 1.0.0
paths:
  /api/v2/projects/{projectKey}/flags/{featureFlagKey}/environments/{environmentKey}/approval-requests:
    post:
      operationId: post-approval-request-for-flag
      summary: Create approval request for a flag
      description: Create an approval request for a feature flag.
      tags:
        - subpackage_approvals
      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: environmentKey
          in: path
          description: The environment key
          required: true
          schema:
            type: string
            format: string
        - name: Authorization
          in: header
          required: true
          schema:
            type: string
      responses:
        '201':
          description: Approval request response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FlagConfigApprovalRequestResponse'
        '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'
        '429':
          description: Rate limited
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RateLimitedErrorRep'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/createFlagConfigApprovalRequestRequest'
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
    UnixMillis:
      type: integer
      format: int64
      title: UnixMillis
    FormVariableConfig:
      type: object
      additionalProperties:
        description: Any type
      title: FormVariableConfig
    createFlagConfigApprovalRequestRequest:
      type: object
      properties:
        comment:
          type: string
          description: Optional comment describing the approval request
        description:
          type: string
          description: A brief description of the changes you're requesting
        instructions:
          $ref: '#/components/schemas/Instructions'
          description: >-
            List of instructions in semantic patch format to be applied to the
            feature flag. Review the [Update feature
            flag](https://launchdarkly.com/docs/ld-docs/api/feature-flags/patch-feature-flag)
            documentation for details on available instructions.
        notifyMemberIds:
          type: array
          items:
            type: string
          description: >-
            An array of member IDs. These members are notified to review the
            approval request.
        notifyTeamKeys:
          type: array
          items:
            type: string
          description: >-
            An array of team keys. The members of these teams are notified to
            review the approval request.
        executionDate:
          $ref: '#/components/schemas/UnixMillis'
          description: Timestamp for when instructions will be executed
        operatingOnId:
          type: string
          description: >-
            The ID of a scheduled change. Include this if your
            <code>instructions</code> include editing or deleting a scheduled
            change.
        integrationConfig:
          $ref: '#/components/schemas/FormVariableConfig'
          description: >-
            Additional approval request fields for third-party integration
            approval systems. If you are using a third-party integration to
            manage approval requests, these additional fields will be described
            in the <code>manifest.json</code> for that integration, at
            https://github.com/launchdarkly/integration-framework.
      required:
        - description
        - instructions
      title: createFlagConfigApprovalRequestRequest
    ApprovalRequestServiceKind:
      type: string
      title: ApprovalRequestServiceKind
    FlagConfigApprovalRequestResponseReviewStatus:
      type: string
      enum:
        - approved
        - declined
        - pending
      description: Current status of the review of this approval request
      title: FlagConfigApprovalRequestResponseReviewStatus
    ReviewResponseKind:
      type: string
      enum:
        - approve
        - decline
        - comment
      description: The type of review action to take
      title: ReviewResponseKind
    ReviewResponse:
      type: object
      properties:
        _id:
          type: string
          description: The approval request ID
        kind:
          $ref: '#/components/schemas/ReviewResponseKind'
          description: The type of review action to take
        creationDate:
          $ref: '#/components/schemas/UnixMillis'
          description: Timestamp of when the request was created
        comment:
          type: string
          description: A comment describing the approval response
        memberId:
          type: string
          description: ID of account member that reviewed request
        serviceTokenId:
          type: string
          description: ID of account service token that reviewed request
      required:
        - _id
        - kind
      title: ReviewResponse
    FlagConfigApprovalRequestResponseStatus:
      type: string
      enum:
        - pending
        - completed
        - failed
        - scheduled
      description: Current status of the approval request
      title: FlagConfigApprovalRequestResponseStatus
    Conflict:
      type: object
      properties:
        instruction:
          $ref: '#/components/schemas/Instruction'
          description: >-
            Instruction in semantic patch format to be applied to the feature
            flag
        reason:
          type: string
          description: Reason why the conflict exists
      title: Conflict
    IntegrationStatus:
      type: object
      properties:
        display:
          type: string
        value:
          type: string
      required:
        - display
        - value
      title: IntegrationStatus
    IntegrationMetadata:
      type: object
      properties:
        externalId:
          type: string
        externalStatus:
          $ref: '#/components/schemas/IntegrationStatus'
        externalUrl:
          type: string
        lastChecked:
          $ref: '#/components/schemas/UnixMillis'
      required:
        - externalId
        - externalStatus
        - externalUrl
        - lastChecked
      title: IntegrationMetadata
    CopiedFromEnv:
      type: object
      properties:
        key:
          type: string
          description: Key of feature flag copied
        version:
          type: integer
          description: Version of feature flag copied
      required:
        - key
      title: CopiedFromEnv
    CustomWorkflowStageMeta:
      type: object
      properties:
        index:
          type: integer
          description: The zero-based index of the workflow stage
        name:
          type: string
          description: The name of the workflow stage
      title: CustomWorkflowStageMeta
    CustomWorkflowMeta:
      type: object
      properties:
        name:
          type: string
          description: The name of the workflow stage that required this approval request
        stage:
          $ref: '#/components/schemas/CustomWorkflowStageMeta'
          description: >-
            Details on the stage of the workflow where this approval request is
            required
      title: CustomWorkflowMeta
    FlagConfigApprovalRequestResponse:
      type: object
      properties:
        _id:
          type: string
          description: The ID of this approval request
        _version:
          type: integer
          description: Version of the approval request
        creationDate:
          $ref: '#/components/schemas/UnixMillis'
          description: Timestamp of when the approval request was created
        serviceKind:
          $ref: '#/components/schemas/ApprovalRequestServiceKind'
          description: >-
            The approval service for this request. May be LaunchDarkly or an
            external approval service, such as ServiceNow or JIRA.
        requestorId:
          type: string
          description: The ID of the member who requested the approval
        description:
          type: string
          description: A human-friendly name for the approval request
        reviewStatus:
          $ref: '#/components/schemas/FlagConfigApprovalRequestResponseReviewStatus'
          description: Current status of the review of this approval request
        allReviews:
          type: array
          items:
            $ref: '#/components/schemas/ReviewResponse'
          description: An array of individual reviews of this approval request
        notifyMemberIds:
          type: array
          items:
            type: string
          description: >-
            An array of member IDs. These members are notified to review the
            approval request.
        appliedDate:
          $ref: '#/components/schemas/UnixMillis'
          description: Timestamp of when the approval request was applied
        appliedByMemberId:
          type: string
          description: The member ID of the member who applied the approval request
        appliedByServiceTokenId:
          type: string
          description: >-
            The service token ID of the service token which applied the approval
            request
        status:
          $ref: '#/components/schemas/FlagConfigApprovalRequestResponseStatus'
          description: Current status of the approval request
        instructions:
          $ref: '#/components/schemas/Instructions'
          description: >-
            List of instructions in semantic patch format to be applied to the
            feature flag
        conflicts:
          type: array
          items:
            $ref: '#/components/schemas/Conflict'
          description: Details on any conflicting approval requests
        _links:
          type: object
          additionalProperties:
            description: Any type
          description: The location and content type of related resources
        executionDate:
          $ref: '#/components/schemas/UnixMillis'
          description: Timestamp for when instructions will be executed
        operatingOnId:
          type: string
          description: ID of scheduled change to edit or delete
        integrationMetadata:
          $ref: '#/components/schemas/IntegrationMetadata'
          description: >-
            Details about the object in an external service corresponding to
            this approval request, such as a ServiceNow change request or a JIRA
            ticket, if an external approval service is being used
        source:
          $ref: '#/components/schemas/CopiedFromEnv'
          description: Details about the source feature flag, if copied
        customWorkflowMetadata:
          $ref: '#/components/schemas/CustomWorkflowMeta'
          description: >-
            Details about the custom workflow, if this approval request is part
            of a custom workflow
      required:
        - _id
        - _version
        - creationDate
        - serviceKind
        - reviewStatus
        - allReviews
        - notifyMemberIds
        - status
        - instructions
        - conflicts
        - _links
      title: FlagConfigApprovalRequestResponse
    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
    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/projects/projectKey/flags/featureFlagKey/environments/environmentKey/approval-requests"

payload = {
    "description": "Requesting to update targeting",
    "instructions": ["[{\"kind\": \"addTargets\", \"values\": [ \"context-key-123abc\"], \"variationId\": \"ce67d625-a8b9-4fb5-a344-ab909d9d4f4d\" }]"]
}
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/projects/projectKey/flags/featureFlagKey/environments/environmentKey/approval-requests';
const options = {
  method: 'POST',
  headers: {Authorization: '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"description":"Requesting to update targeting","instructions":["[{\"kind\": \"addTargets\", \"values\": [ \"context-key-123abc\"], \"variationId\": \"ce67d625-a8b9-4fb5-a344-ab909d9d4f4d\" }]"]}'
};

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/projectKey/flags/featureFlagKey/environments/environmentKey/approval-requests"

	payload := strings.NewReader("{\n  \"description\": \"Requesting to update targeting\",\n  \"instructions\": [\n    \"[{\\\"kind\\\": \\\"addTargets\\\", \\\"values\\\": [ \\\"context-key-123abc\\\"], \\\"variationId\\\": \\\"ce67d625-a8b9-4fb5-a344-ab909d9d4f4d\\\" }]\"\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/projects/projectKey/flags/featureFlagKey/environments/environmentKey/approval-requests")

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  \"description\": \"Requesting to update targeting\",\n  \"instructions\": [\n    \"[{\\\"kind\\\": \\\"addTargets\\\", \\\"values\\\": [ \\\"context-key-123abc\\\"], \\\"variationId\\\": \\\"ce67d625-a8b9-4fb5-a344-ab909d9d4f4d\\\" }]\"\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/projects/projectKey/flags/featureFlagKey/environments/environmentKey/approval-requests")
  .header("Authorization", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"description\": \"Requesting to update targeting\",\n  \"instructions\": [\n    \"[{\\\"kind\\\": \\\"addTargets\\\", \\\"values\\\": [ \\\"context-key-123abc\\\"], \\\"variationId\\\": \\\"ce67d625-a8b9-4fb5-a344-ab909d9d4f4d\\\" }]\"\n  ]\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://app.launchdarkly.com/api/v2/projects/projectKey/flags/featureFlagKey/environments/environmentKey/approval-requests', [
  'body' => '{
  "description": "Requesting to update targeting",
  "instructions": [
    "[{\\"kind\\": \\"addTargets\\", \\"values\\": [ \\"context-key-123abc\\"], \\"variationId\\": \\"ce67d625-a8b9-4fb5-a344-ab909d9d4f4d\\" }]"
  ]
}',
  'headers' => [
    'Authorization' => '<apiKey>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://app.launchdarkly.com/api/v2/projects/projectKey/flags/featureFlagKey/environments/environmentKey/approval-requests");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"description\": \"Requesting to update targeting\",\n  \"instructions\": [\n    \"[{\\\"kind\\\": \\\"addTargets\\\", \\\"values\\\": [ \\\"context-key-123abc\\\"], \\\"variationId\\\": \\\"ce67d625-a8b9-4fb5-a344-ab909d9d4f4d\\\" }]\"\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "description": "Requesting to update targeting",
  "instructions": ["[{\"kind\": \"addTargets\", \"values\": [ \"context-key-123abc\"], \"variationId\": \"ce67d625-a8b9-4fb5-a344-ab909d9d4f4d\" }]"]
] as [String : Any]

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

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