# Task Source

## Delete

**delete** `/projects/{projectId}/task-source`

Delete the project's task source. Team admins only.

### Path Parameters

- `projectId: string`

### Returns

- `deleted: boolean`

  Whether a task source was configured and is now deleted

### Example

```http
curl https://api.cloud.scenario.com/v1/projects/$PROJECT_ID/task-source \
    -X DELETE \
    -u "$SCENARIO_SDK_API_KEY:SCENARIO_SDK_API_SECRET"
```

#### Response

```json
{
  "deleted": true
}
```

## Retrieve

**get** `/projects/{projectId}/task-source`

Get the project's task source: the endpoint that lists the tasks of the team's task tracker. The Authorization header value is never returned. Team admins only.

### Path Parameters

- `projectId: string`

### Returns

- `taskSource: object { hasAuthorization, mapping, method, 3 more }`

  A project's task source. The Authorization header value is never returned.

  - `hasAuthorization: boolean`

    Whether an Authorization header value is stored

  - `mapping: object { id, tasksPath, name, status }`

    Where the tasks sit in the response, and which fields to read

    - `id: string`

      Field of each task that holds its id (example: "code"). The id must be 1
      to 256 printable ASCII characters; a number is converted to a string.

    - `tasksPath: string`

      Dot-separated path to the array of tasks in the response (example:
      "data.items"). An empty string means the response is the array itself.

    - `name: optional string`

      Field of each task that holds its name (example: "title")

    - `status: optional string`

      Field of each task that holds its status (example: "state")

  - `method: "GET" or "POST"`

    HTTP method used to call the task source

    - `"GET"`

    - `"POST"`

  - `url: string`

    https URL of the task source

  - `body: optional string`

    JSON body sent with POST

  - `parameters: optional map[string]`

    Query string parameters sent to the task source

### Example

```http
curl https://api.cloud.scenario.com/v1/projects/$PROJECT_ID/task-source \
    -u "$SCENARIO_SDK_API_KEY:SCENARIO_SDK_API_SECRET"
```

#### Response

```json
{
  "taskSource": {
    "hasAuthorization": true,
    "mapping": {
      "id": "x",
      "tasksPath": "tasksPath",
      "name": "x",
      "status": "x"
    },
    "method": "GET",
    "url": "url",
    "body": "body",
    "parameters": {
      "foo": "string"
    }
  }
}
```

## Test

**post** `/projects/{projectId}/task-source/test`

Call a task source with the same checks as saving it, without saving it, and return the request sent, the response received and the arrays of objects it holds, to build the mapping from. The mapping is optional here. An omitted authorization uses the stored one. Enterprise only, team admins only.

### Path Parameters

- `projectId: string`

### Body Parameters

- `method: "GET" or "POST"`

  HTTP method used to call the task source

  - `"GET"`

  - `"POST"`

- `url: string`

  https URL of the task source. It may contain the placeholders
  `{user.email}`, `{user.id}` and `{project.id}`, replaced on each call.
  Never put a credential in it: only `authorization` is stored as a secret.

- `authorization: optional string`

  Value of the Authorization header sent to the task source (example:
  "Bearer abc"). Never returned. Omit it to use the stored value, or set it
  to null to send none. Omitting it is refused when the URL's scheme, host
  or port changes.

- `body: optional string`

  JSON text sent as the body of a POST, with `Content-Type: application/json`. The placeholders are replaced inside its string values.
  Refused with GET. Never put a credential in it: only `authorization` is
  stored as a secret.

- `mapping: optional object { id, tasksPath, name, status }`

  Where the tasks sit in the response, and which fields to read. Optional
  here: without it, `tasks` is empty and `candidates` helps build it.

  - `id: string`

    Field of each task that holds its id (example: "code"). The id must be 1
    to 256 printable ASCII characters; a number is converted to a string.

  - `tasksPath: string`

    Dot-separated path to the array of tasks in the response (example:
    "data.items"). An empty string means the response is the array itself.

  - `name: optional string`

    Field of each task that holds its name (example: "title")

  - `status: optional string`

    Field of each task that holds its status (example: "state")

- `parameters: optional map[string]`

  Query string parameters, sent with GET and POST: at most 20, names of 1
  to 256 characters, values up to 1,024. Values may contain the same
  placeholders as `url`. Never put a credential in them: only
  `authorization` is stored as a secret.

### Returns

- `candidates: array of object { count, fields, tasksPath }`

  The arrays of objects in the response, to build the mapping. A 400 from a
  mapping that does not fit carries them as `details.candidates`.

  - `count: number`

    Number of entries in the array

  - `fields: array of object { isIdCandidate, path, sample }`

    String and number fields of the entries

    - `isIdCandidate: boolean`

      Whether every entry holds a distinct, valid task id at this path

    - `path: string`

      Dot-separated path in an entry, for mapping.id, name or status

    - `sample: string`

      The value of the first entry that has one

  - `tasksPath: string`

    Value for mapping.tasksPath; empty when the response is the array itself

- `exchange: object { request, durationMs, response }`

  The test call. A 400 from a failed call carries it as `details.exchange`.

  - `request: object { headers, method, url, body }`

    The request Scenario sent to the task source, placeholders filled

    - `headers: map[string]`

      Headers set by Scenario; the Authorization value is masked

    - `method: "GET" or "POST"`

      HTTP method Scenario uses to call a task source.

      - `"GET"`

      - `"POST"`

    - `url: string`

      Full URL, query string included

    - `body: optional string`

      Body sent with POST

  - `durationMs: optional number`

    Time from sending the request to reading the whole response

  - `response: optional object { body, headers, status, isBodyTruncated }`

    Absent when no response came back (DNS, TLS, timeout): the error explains why

    - `body: string`

      Raw response body, truncated at 65,536 characters

    - `headers: map[string]`

      Response headers; a Set-Cookie value is masked

    - `status: number`

    - `isBodyTruncated: optional boolean`

      Whether `body` was truncated

- `tasks: array of object { id, name, status }`

  The first tasks read with the mapping; empty without a mapping

  - `id: string`

    The task id, to send in the X-Scenario-Task-Id header

  - `name: optional string`

    The task name

  - `status: optional string`

    The task status

### Example

```http
curl https://api.cloud.scenario.com/v1/projects/$PROJECT_ID/task-source/test \
    -H 'Content-Type: application/json' \
    -u "$SCENARIO_SDK_API_KEY:SCENARIO_SDK_API_SECRET" \
    -d '{
          "method": "GET",
          "url": "url"
        }'
```

#### Response

```json
{
  "candidates": [
    {
      "count": 0,
      "fields": [
        {
          "isIdCandidate": true,
          "path": "path",
          "sample": "sample"
        }
      ],
      "tasksPath": "tasksPath"
    }
  ],
  "exchange": {
    "request": {
      "headers": {
        "foo": "string"
      },
      "method": "GET",
      "url": "url",
      "body": "body"
    },
    "durationMs": 0,
    "response": {
      "body": "body",
      "headers": {
        "foo": "string"
      },
      "status": 0,
      "isBodyTruncated": true
    }
  },
  "tasks": [
    {
      "id": "id",
      "name": "name",
      "status": "status"
    }
  ]
}
```

## Update

**put** `/projects/{projectId}/task-source`

Create or replace the project's task source. Scenario calls the endpoint first and saves it only if the response holds tasks it can read with the mapping. The Authorization value is stored encrypted; null removes it. Enterprise only, team admins only.

### Path Parameters

- `projectId: string`

### Body Parameters

- `mapping: object { id, tasksPath, name, status }`

  Where the tasks sit in the response, and which fields to read

  - `id: string`

    Field of each task that holds its id (example: "code"). The id must be 1
    to 256 printable ASCII characters; a number is converted to a string.

  - `tasksPath: string`

    Dot-separated path to the array of tasks in the response (example:
    "data.items"). An empty string means the response is the array itself.

  - `name: optional string`

    Field of each task that holds its name (example: "title")

  - `status: optional string`

    Field of each task that holds its status (example: "state")

- `method: "GET" or "POST"`

  HTTP method used to call the task source

  - `"GET"`

  - `"POST"`

- `url: string`

  https URL of the task source. It may contain the placeholders
  `{user.email}`, `{user.id}` and `{project.id}`, replaced on each call.
  Never put a credential in it: only `authorization` is stored as a secret.

- `authorization: optional string`

  Value of the Authorization header sent to the task source (example:
  "Bearer abc"). Never returned. Omit it to use the stored value, or set it
  to null to send none. Omitting it is refused when the URL's scheme, host
  or port changes.

- `body: optional string`

  JSON text sent as the body of a POST, with `Content-Type: application/json`. The placeholders are replaced inside its string values.
  Refused with GET. Never put a credential in it: only `authorization` is
  stored as a secret.

- `parameters: optional map[string]`

  Query string parameters, sent with GET and POST: at most 20, names of 1
  to 256 characters, values up to 1,024. Values may contain the same
  placeholders as `url`. Never put a credential in them: only
  `authorization` is stored as a secret.

### Returns

- `exchange: object { request, durationMs, response }`

  The validation call. A 400 from a failed call carries it as
  `details.exchange`.

  - `request: object { headers, method, url, body }`

    The request Scenario sent to the task source, placeholders filled

    - `headers: map[string]`

      Headers set by Scenario; the Authorization value is masked

    - `method: "GET" or "POST"`

      HTTP method Scenario uses to call a task source.

      - `"GET"`

      - `"POST"`

    - `url: string`

      Full URL, query string included

    - `body: optional string`

      Body sent with POST

  - `durationMs: optional number`

    Time from sending the request to reading the whole response

  - `response: optional object { body, headers, status, isBodyTruncated }`

    Absent when no response came back (DNS, TLS, timeout): the error explains why

    - `body: string`

      Raw response body, truncated at 65,536 characters

    - `headers: map[string]`

      Response headers; a Set-Cookie value is masked

    - `status: number`

    - `isBodyTruncated: optional boolean`

      Whether `body` was truncated

- `tasks: array of object { id, name, status }`

  The first tasks the task source returned during the validation call

  - `id: string`

    The task id, to send in the X-Scenario-Task-Id header

  - `name: optional string`

    The task name

  - `status: optional string`

    The task status

- `taskSource: object { hasAuthorization, mapping, method, 3 more }`

  A project's task source. The Authorization header value is never returned.

  - `hasAuthorization: boolean`

    Whether an Authorization header value is stored

  - `mapping: object { id, tasksPath, name, status }`

    Where the tasks sit in the response, and which fields to read

    - `id: string`

      Field of each task that holds its id (example: "code"). The id must be 1
      to 256 printable ASCII characters; a number is converted to a string.

    - `tasksPath: string`

      Dot-separated path to the array of tasks in the response (example:
      "data.items"). An empty string means the response is the array itself.

    - `name: optional string`

      Field of each task that holds its name (example: "title")

    - `status: optional string`

      Field of each task that holds its status (example: "state")

  - `method: "GET" or "POST"`

    HTTP method used to call the task source

    - `"GET"`

    - `"POST"`

  - `url: string`

    https URL of the task source

  - `body: optional string`

    JSON body sent with POST

  - `parameters: optional map[string]`

    Query string parameters sent to the task source

### Example

```http
curl https://api.cloud.scenario.com/v1/projects/$PROJECT_ID/task-source \
    -X PUT \
    -H 'Content-Type: application/json' \
    -u "$SCENARIO_SDK_API_KEY:SCENARIO_SDK_API_SECRET" \
    -d '{
          "mapping": {
            "id": "x",
            "tasksPath": "tasksPath"
          },
          "method": "GET",
          "url": "url"
        }'
```

#### Response

```json
{
  "exchange": {
    "request": {
      "headers": {
        "foo": "string"
      },
      "method": "GET",
      "url": "url",
      "body": "body"
    },
    "durationMs": 0,
    "response": {
      "body": "body",
      "headers": {
        "foo": "string"
      },
      "status": 0,
      "isBodyTruncated": true
    }
  },
  "tasks": [
    {
      "id": "id",
      "name": "name",
      "status": "status"
    }
  ],
  "taskSource": {
    "hasAuthorization": true,
    "mapping": {
      "id": "x",
      "tasksPath": "tasksPath",
      "name": "x",
      "status": "x"
    },
    "method": "GET",
    "url": "url",
    "body": "body",
    "parameters": {
      "foo": "string"
    }
  }
}
```

## Domain Types

### Task Source Delete Response

- `TaskSourceDeleteResponse object { deleted }`

  - `deleted: boolean`

    Whether a task source was configured and is now deleted

### Task Source Retrieve Response

- `TaskSourceRetrieveResponse object { taskSource }`

  - `taskSource: object { hasAuthorization, mapping, method, 3 more }`

    A project's task source. The Authorization header value is never returned.

    - `hasAuthorization: boolean`

      Whether an Authorization header value is stored

    - `mapping: object { id, tasksPath, name, status }`

      Where the tasks sit in the response, and which fields to read

      - `id: string`

        Field of each task that holds its id (example: "code"). The id must be 1
        to 256 printable ASCII characters; a number is converted to a string.

      - `tasksPath: string`

        Dot-separated path to the array of tasks in the response (example:
        "data.items"). An empty string means the response is the array itself.

      - `name: optional string`

        Field of each task that holds its name (example: "title")

      - `status: optional string`

        Field of each task that holds its status (example: "state")

    - `method: "GET" or "POST"`

      HTTP method used to call the task source

      - `"GET"`

      - `"POST"`

    - `url: string`

      https URL of the task source

    - `body: optional string`

      JSON body sent with POST

    - `parameters: optional map[string]`

      Query string parameters sent to the task source

### Task Source Test Response

- `TaskSourceTestResponse object { candidates, exchange, tasks }`

  - `candidates: array of object { count, fields, tasksPath }`

    The arrays of objects in the response, to build the mapping. A 400 from a
    mapping that does not fit carries them as `details.candidates`.

    - `count: number`

      Number of entries in the array

    - `fields: array of object { isIdCandidate, path, sample }`

      String and number fields of the entries

      - `isIdCandidate: boolean`

        Whether every entry holds a distinct, valid task id at this path

      - `path: string`

        Dot-separated path in an entry, for mapping.id, name or status

      - `sample: string`

        The value of the first entry that has one

    - `tasksPath: string`

      Value for mapping.tasksPath; empty when the response is the array itself

  - `exchange: object { request, durationMs, response }`

    The test call. A 400 from a failed call carries it as `details.exchange`.

    - `request: object { headers, method, url, body }`

      The request Scenario sent to the task source, placeholders filled

      - `headers: map[string]`

        Headers set by Scenario; the Authorization value is masked

      - `method: "GET" or "POST"`

        HTTP method Scenario uses to call a task source.

        - `"GET"`

        - `"POST"`

      - `url: string`

        Full URL, query string included

      - `body: optional string`

        Body sent with POST

    - `durationMs: optional number`

      Time from sending the request to reading the whole response

    - `response: optional object { body, headers, status, isBodyTruncated }`

      Absent when no response came back (DNS, TLS, timeout): the error explains why

      - `body: string`

        Raw response body, truncated at 65,536 characters

      - `headers: map[string]`

        Response headers; a Set-Cookie value is masked

      - `status: number`

      - `isBodyTruncated: optional boolean`

        Whether `body` was truncated

  - `tasks: array of object { id, name, status }`

    The first tasks read with the mapping; empty without a mapping

    - `id: string`

      The task id, to send in the X-Scenario-Task-Id header

    - `name: optional string`

      The task name

    - `status: optional string`

      The task status

### Task Source Update Response

- `TaskSourceUpdateResponse object { exchange, tasks, taskSource }`

  - `exchange: object { request, durationMs, response }`

    The validation call. A 400 from a failed call carries it as
    `details.exchange`.

    - `request: object { headers, method, url, body }`

      The request Scenario sent to the task source, placeholders filled

      - `headers: map[string]`

        Headers set by Scenario; the Authorization value is masked

      - `method: "GET" or "POST"`

        HTTP method Scenario uses to call a task source.

        - `"GET"`

        - `"POST"`

      - `url: string`

        Full URL, query string included

      - `body: optional string`

        Body sent with POST

    - `durationMs: optional number`

      Time from sending the request to reading the whole response

    - `response: optional object { body, headers, status, isBodyTruncated }`

      Absent when no response came back (DNS, TLS, timeout): the error explains why

      - `body: string`

        Raw response body, truncated at 65,536 characters

      - `headers: map[string]`

        Response headers; a Set-Cookie value is masked

      - `status: number`

      - `isBodyTruncated: optional boolean`

        Whether `body` was truncated

  - `tasks: array of object { id, name, status }`

    The first tasks the task source returned during the validation call

    - `id: string`

      The task id, to send in the X-Scenario-Task-Id header

    - `name: optional string`

      The task name

    - `status: optional string`

      The task status

  - `taskSource: object { hasAuthorization, mapping, method, 3 more }`

    A project's task source. The Authorization header value is never returned.

    - `hasAuthorization: boolean`

      Whether an Authorization header value is stored

    - `mapping: object { id, tasksPath, name, status }`

      Where the tasks sit in the response, and which fields to read

      - `id: string`

        Field of each task that holds its id (example: "code"). The id must be 1
        to 256 printable ASCII characters; a number is converted to a string.

      - `tasksPath: string`

        Dot-separated path to the array of tasks in the response (example:
        "data.items"). An empty string means the response is the array itself.

      - `name: optional string`

        Field of each task that holds its name (example: "title")

      - `status: optional string`

        Field of each task that holds its status (example: "state")

    - `method: "GET" or "POST"`

      HTTP method used to call the task source

      - `"GET"`

      - `"POST"`

    - `url: string`

      https URL of the task source

    - `body: optional string`

      JSON body sent with POST

    - `parameters: optional map[string]`

      Query string parameters sent to the task source
