## Create a task

`client.Task.New(ctx, body) (*TaskCreateResponse, error)`

**post** `/v1/tasks`

Creates a new task record. The `$title` and `$status` fields and the `$assignedTo` relationship are required.

If `$createdBy` is omitted it defaults to the authenticated user (for a workspace API key, the member who created the key), or to the assignee when no member is acting. The `$note` relationship is read-only — manage notes via their own relationships.

Supports idempotency via the `Idempotency-Key` header.

**[Required scope](/using-the-api/scopes/):** `tasks:create`

**[Rate limit category](/using-the-api/rate-limits/):** Write

### Parameters

- `body TaskNewParams`

  - `Fields param.Field[TaskNewParamsFields]`

    Field values for the new task. Tasks only support the documented system fields, all prefixed with `$` (e.g. `$title`, `$status`). Required: `$title` (string) and `$status` (one of `TODO`, `IN_PROGRESS`, `COMPLETE`, `CANCELLED`). Call the <u>[definitions endpoint](/api/resources/task/methods/definitions)</u> to discover the available fields. See <u>[Fields and relationships](/using-the-api/fields-and-relationships/)</u> for value type details.

    - `Status string`

      Task status. One of: `TODO`, `IN_PROGRESS`, `COMPLETE`, `CANCELLED`.

    - `Title string`

      Title of the task.

    - `Description string`

      Description of the task in markdown format.

    - `DueAt string`

      Due date as an ISO 8601 datetime string.

  - `Relationships param.Field[map[string, TaskNewParamsRelationshipUnion]]`

    Relationships to set on the new task. System relationships use a `$` prefix (e.g. `$account`, `$assignedTo`); custom relationships use their bare slug. `$assignedTo` is required. Each value is a single entity ID or an array of IDs. Call the <u>[definitions endpoint](/api/resources/task/methods/definitions)</u> to list available relationship keys.

    - `map[string, TaskNewParamsRelationshipUnion]`

      - `string`

      - `type TaskNewParamsRelationshipArray []string`

### Returns

- `type TaskCreateResponse struct{…}`

  - `ID string`

    Unique identifier for the entity.

  - `CreatedAt string`

    ISO 8601 timestamp of when the entity was created.

  - `Fields map[string, TaskCreateResponseField]`

    Map of field names to their typed values. System fields are prefixed with `$` (e.g. `$name`, `$email`); custom attributes use their bare slug.

    - `Value TaskCreateResponseFieldValueUnion`

      The field value, or null if unset.

      - `string`

      - `float64`

      - `bool`

      - `type TaskCreateResponseFieldValueArray []string`

      - `type TaskCreateResponseFieldValueAddress struct{…}`

        - `City string`

          City name.

        - `Country string`

          2-letter ISO 3166-1 alpha-2 country code.

        - `Latitude float64`

          Latitude coordinate.

        - `Longitude float64`

          Longitude coordinate.

        - `PostalCode string`

          Postal or ZIP code.

        - `State string`

          State or province.

        - `Street string`

          Street address line 1.

        - `Street2 string`

          Street address line 2.

      - `type TaskCreateResponseFieldValueFullName struct{…}`

        - `FirstName string`

          The contact's first name.

        - `LastName string`

          The contact's last name.

    - `ValueType string`

      The data type of the field.

      - `const TaskCreateResponseFieldValueTypeAddress TaskCreateResponseFieldValueType = "ADDRESS"`

      - `const TaskCreateResponseFieldValueTypeCheckbox TaskCreateResponseFieldValueType = "CHECKBOX"`

      - `const TaskCreateResponseFieldValueTypeCurrency TaskCreateResponseFieldValueType = "CURRENCY"`

      - `const TaskCreateResponseFieldValueTypeDatetime TaskCreateResponseFieldValueType = "DATETIME"`

      - `const TaskCreateResponseFieldValueTypeEmail TaskCreateResponseFieldValueType = "EMAIL"`

      - `const TaskCreateResponseFieldValueTypeFullName TaskCreateResponseFieldValueType = "FULL_NAME"`

      - `const TaskCreateResponseFieldValueTypeMarkdown TaskCreateResponseFieldValueType = "MARKDOWN"`

      - `const TaskCreateResponseFieldValueTypeMultiSelect TaskCreateResponseFieldValueType = "MULTI_SELECT"`

      - `const TaskCreateResponseFieldValueTypeNumber TaskCreateResponseFieldValueType = "NUMBER"`

      - `const TaskCreateResponseFieldValueTypeSingleSelect TaskCreateResponseFieldValueType = "SINGLE_SELECT"`

      - `const TaskCreateResponseFieldValueTypeSocialHandle TaskCreateResponseFieldValueType = "SOCIAL_HANDLE"`

      - `const TaskCreateResponseFieldValueTypeTelephone TaskCreateResponseFieldValueType = "TELEPHONE"`

      - `const TaskCreateResponseFieldValueTypeText TaskCreateResponseFieldValueType = "TEXT"`

      - `const TaskCreateResponseFieldValueTypeURL TaskCreateResponseFieldValueType = "URL"`

      - `const TaskCreateResponseFieldValueTypeHTML TaskCreateResponseFieldValueType = "HTML"`

  - `HTTPLink string`

    URL to view the entity in the Lightfield web app, or null.

  - `Relationships map[string, TaskCreateResponseRelationship]`

    Map of relationship names to their associated entities. System relationships are prefixed with `$` (e.g. `$owner`, `$contact`). A self-referential relationship keeps its merged values and includes optional directional values. List filters select the current record's role with `:asSource` or `:asDestination`, for example `?parent:asSource[contains]=account_id`.

    - `Cardinality string`

      Whether the relationship is `has_one` or `has_many`.

    - `ObjectType string`

      The type of the related object (e.g. `account`, `contact`).

    - `Values []string`

      IDs of the related entities.

    - `Directions TaskCreateResponseRelationshipDirections`

      Directional values for a self-referential relationship. List filters use the relationship key with `:asSource` or `:asDestination`; writes continue to use the bare key.

      - `AsDestination TaskCreateResponseRelationshipDirectionsAsDestination`

        The current record is the destination (incoming) endpoint.

        - `Cardinality string`

          Whether this endpoint direction is `HAS_ONE` or `HAS_MANY`.

          - `const TaskCreateResponseRelationshipDirectionsAsDestinationCardinalityHasOne TaskCreateResponseRelationshipDirectionsAsDestinationCardinality = "HAS_ONE"`

          - `const TaskCreateResponseRelationshipDirectionsAsDestinationCardinalityHasMany TaskCreateResponseRelationshipDirectionsAsDestinationCardinality = "HAS_MANY"`

        - `Values []string`

          IDs of the related entities in this direction.

      - `AsSource TaskCreateResponseRelationshipDirectionsAsSource`

        The current record is the source (outgoing) endpoint.

        - `Cardinality string`

          Whether this endpoint direction is `HAS_ONE` or `HAS_MANY`.

          - `const TaskCreateResponseRelationshipDirectionsAsSourceCardinalityHasOne TaskCreateResponseRelationshipDirectionsAsSourceCardinality = "HAS_ONE"`

          - `const TaskCreateResponseRelationshipDirectionsAsSourceCardinalityHasMany TaskCreateResponseRelationshipDirectionsAsSourceCardinality = "HAS_MANY"`

        - `Values []string`

          IDs of the related entities in this direction.

  - `UpdatedAt string`

    ISO 8601 timestamp of when the entity was last updated, or null.

  - `ExternalID string`

    External identifier for the entity, or null if unset.

### Example

```go
package main

import (
  "context"
  "fmt"

  "github.com/Lightfld/lightfield-go"
  "github.com/Lightfld/lightfield-go/option"
)

func main() {
  client := githubcomlightfldlightfieldgo.NewClient(
    option.WithAPIKey("My API Key"),
  )
  taskCreateResponse, err := client.Task.New(context.TODO(), githubcomlightfldlightfieldgo.TaskNewParams{
    Fields: githubcomlightfldlightfieldgo.TaskNewParamsFields{
      Status: "$status",
      Title: "$title",
    },
    Relationships: map[string]githubcomlightfldlightfieldgo.TaskNewParamsRelationshipUnion{
    "foo": githubcomlightfldlightfieldgo.TaskNewParamsRelationshipUnion{
      OfString: githubcomlightfldlightfieldgo.String("string"),
    },
    },
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", taskCreateResponse.ID)
}
```

#### Response

```json
{
  "id": "id",
  "createdAt": "createdAt",
  "fields": {
    "foo": {
      "value": "string",
      "valueType": "ADDRESS"
    }
  },
  "httpLink": "httpLink",
  "relationships": {
    "foo": {
      "cardinality": "cardinality",
      "objectType": "objectType",
      "values": [
        "string"
      ],
      "directions": {
        "asDestination": {
          "cardinality": "HAS_ONE",
          "values": [
            "string"
          ]
        },
        "asSource": {
          "cardinality": "HAS_ONE",
          "values": [
            "string"
          ]
        }
      }
    }
  },
  "updatedAt": "updatedAt",
  "externalId": "externalId"
}
```
