# Create workflow template

POST https://app.launchdarkly.com/api/v2/templates
Content-Type: application/json

> ### Workflows are in maintenance mode
>
> The workflows feature is in maintenance mode, and is planned for future deprecation at a date not yet specified. We will work with existing customers using workflows to migrate to a replacement solution when deprecation occurs.

Create a template for a feature flag workflow.


Reference: https://launchdarkly.com/docs/api/workflow-templates/create-workflow-template

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: LaunchDarkly REST API
  version: 1.0.0
paths:
  /api/v2/templates:
    post:
      operationId: create-workflow-template
      summary: Create workflow template
      description: >
        > ### Workflows are in maintenance mode

        >

        > The workflows feature is in maintenance mode, and is planned for
        future deprecation at a date not yet specified. We will work with
        existing customers using workflows to migrate to a replacement solution
        when deprecation occurs.


        Create a template for a feature flag workflow.
      tags:
        - subpackage_workflowTemplates
      parameters:
        - name: Authorization
          in: header
          required: true
          schema:
            type: string
      responses:
        '201':
          description: Workflow template response JSON
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WorkflowTemplateOutput'
        '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/CreateWorkflowTemplateInput'
servers:
  - url: https://app.launchdarkly.com
  - url: https://app.launchdarkly.us
components:
  schemas:
    FeatureWorkflowId:
      type: string
      title: FeatureWorkflowId
    ScheduleKind:
      type: string
      title: ScheduleKind
    UnixMillis:
      type: integer
      format: int64
      title: UnixMillis
    DurationUnit:
      type: string
      title: DurationUnit
    FormVariableConfig:
      type: object
      additionalProperties:
        description: Any type
      title: FormVariableConfig
    ConditionKind:
      type: string
      title: ConditionKind
    ConditionInput:
      type: object
      properties:
        scheduleKind:
          $ref: '#/components/schemas/ScheduleKind'
          description: >-
            Whether the scheduled execution of the workflow stage is relative or
            absolute. If relative, the <code>waitDuration</code> and
            <code>waitDurationUnit</code> specify when the execution occurs. If
            absolute, the <code>executionDate</code> specifies when the
            execution occurs.
        executionDate:
          $ref: '#/components/schemas/UnixMillis'
          description: >-
            For workflow stages whose scheduled execution is absolute, the time,
            in Unix milliseconds, when the stage should start.
        waitDuration:
          type: integer
          description: >-
            For workflow stages whose scheduled execution is relative, how far
            in the future the stage should start.
        waitDurationUnit:
          $ref: '#/components/schemas/DurationUnit'
          description: >-
            For workflow stages whose scheduled execution is relative, the unit
            of measure for the <code>waitDuration</code>.
        executeNow:
          type: boolean
          description: Whether the workflow stage should be executed immediately
        description:
          type: string
          description: A description of the approval required for this stage
        notifyMemberIds:
          type: array
          items:
            type: string
          description: >-
            A list of member IDs for the members to request approval from for
            this stage
        notifyTeamKeys:
          type: array
          items:
            type: string
          description: >-
            A list of team keys for the teams to request approval from for this
            stage
        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.
        kind:
          $ref: '#/components/schemas/ConditionKind'
          description: >-
            The type of condition to meet before executing this stage of the
            workflow. Use <code>schedule</code> to schedule a workflow stage.
            Use <code>ld-approval</code> to add an approval request to a
            workflow stage.
      title: ConditionInput
    ActionInput:
      type: object
      properties:
        instructions:
          description: >-
            An array of instructions for the stage. Each object in the array
            uses the semantic patch format for updating a feature flag.
      title: ActionInput
    StageInput:
      type: object
      properties:
        name:
          type: string
          description: The stage name
        executeConditionsInSequence:
          type: boolean
          description: Whether to execute the conditions in sequence for the given stage
        conditions:
          type: array
          items:
            $ref: '#/components/schemas/ConditionInput'
          description: An array of conditions for the stage
        action:
          $ref: '#/components/schemas/ActionInput'
          description: >-
            An <code>instructions</code> field containing an array of
            instructions for the stage. Each object in the array uses the
            semantic patch format for updating a feature flag.
      title: StageInput
    CreateWorkflowTemplateInput:
      type: object
      properties:
        key:
          type: string
        name:
          type: string
        description:
          type: string
        workflowId:
          $ref: '#/components/schemas/FeatureWorkflowId'
        stages:
          type: array
          items:
            $ref: '#/components/schemas/StageInput'
        projectKey:
          type: string
        environmentKey:
          type: string
        flagKey:
          type: string
      required:
        - key
      title: CreateWorkflowTemplateInput
    Link:
      type: object
      properties:
        href:
          type: string
          description: The URL of the link
        type:
          type: string
          description: The type of the link
      title: Link
    ExecutionOutput:
      type: object
      properties:
        status:
          type: string
          description: The status of the execution of this workflow stage
        stopDate:
          $ref: '#/components/schemas/UnixMillis'
          description: Timestamp of when the workflow was completed.
      required:
        - status
      title: ExecutionOutput
    ReviewOutput:
      type: object
      properties:
        _id:
          type: string
        kind:
          type: string
        creationDate:
          $ref: '#/components/schemas/UnixMillis'
        comment:
          type: string
        memberId:
          type: string
        serviceTokenId:
          type: string
      required:
        - _id
        - kind
      title: ReviewOutput
    ConditionOutput:
      type: object
      properties:
        _id:
          type: string
        kind:
          type: string
        _execution:
          $ref: '#/components/schemas/ExecutionOutput'
        scheduleKind:
          $ref: '#/components/schemas/ScheduleKind'
        executionDate:
          $ref: '#/components/schemas/UnixMillis'
        waitDuration:
          type: integer
        waitDurationUnit:
          $ref: '#/components/schemas/DurationUnit'
        description:
          type: string
        notifyMemberIds:
          type: array
          items:
            type: string
        allReviews:
          type: array
          items:
            $ref: '#/components/schemas/ReviewOutput'
        reviewStatus:
          type: string
        appliedDate:
          $ref: '#/components/schemas/UnixMillis'
        creationConfig:
          $ref: '#/components/schemas/FormVariableConfig'
      required:
        - _id
        - _execution
        - description
        - notifyMemberIds
        - allReviews
        - reviewStatus
      title: ConditionOutput
    Instruction:
      type: object
      additionalProperties:
        description: Any type
      title: Instruction
    Instructions:
      type: array
      items:
        $ref: '#/components/schemas/Instruction'
      title: Instructions
    ActionOutput:
      type: object
      properties:
        kind:
          type: string
          description: The type of action for this stage
        instructions:
          $ref: '#/components/schemas/Instructions'
          description: >-
            An array of instructions for the stage. Each object in the array
            uses the semantic patch format for updating a feature flag.
      required:
        - kind
        - instructions
      title: ActionOutput
    StageOutput:
      type: object
      properties:
        _id:
          type: string
          description: The ID of this stage
        name:
          type: string
          description: The stage name
        conditions:
          type: array
          items:
            $ref: '#/components/schemas/ConditionOutput'
          description: An array of conditions for the stage
        action:
          $ref: '#/components/schemas/ActionOutput'
          description: >-
            The type of instruction, and an array of instructions for the stage.
            Each object in the array uses the semantic patch format for updating
            a feature flag.
        _execution:
          $ref: '#/components/schemas/ExecutionOutput'
          description: Details on the execution of this stage
      required:
        - _id
        - conditions
        - action
        - _execution
      title: StageOutput
    WorkflowTemplateOutput:
      type: object
      properties:
        _id:
          type: string
        _key:
          type: string
        name:
          type: string
        _creationDate:
          $ref: '#/components/schemas/UnixMillis'
        _ownerId:
          type: string
        _maintainerId:
          type: string
        _links:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/Link'
        description:
          type: string
        stages:
          type: array
          items:
            $ref: '#/components/schemas/StageOutput'
      required:
        - _id
        - _key
        - _creationDate
        - _ownerId
        - _maintainerId
        - _links
      title: WorkflowTemplateOutput
    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/templates"

payload = { "key": "string" }
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/templates';
const options = {
  method: 'POST',
  headers: {Authorization: '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"key":"string"}'
};

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/templates"

	payload := strings.NewReader("{\n  \"key\": \"string\"\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/templates")

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\": \"string\"\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/templates")
  .header("Authorization", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"key\": \"string\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://app.launchdarkly.com/api/v2/templates', [
  'body' => '{
  "key": "string"
}',
  'headers' => [
    'Authorization' => '<apiKey>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://app.launchdarkly.com/api/v2/templates");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"key\": \"string\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = ["key": "string"] as [String : Any]

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

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