## Update

`projects.task_source.update(strproject_id, TaskSourceUpdateParams**kwargs)  -> TaskSourceUpdateResponse`

**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.

### Parameters

- `project_id: str`

- `mapping: Mapping`

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

  - `id: str`

    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.

  - `tasks_path: str`

    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[str]`

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

  - `status: Optional[str]`

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

- `method: Literal["GET", "POST"]`

  HTTP method used to call the task source

  - `"GET"`

  - `"POST"`

- `url: str`

  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[str]`

  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[str]`

  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[Dict[str, str]]`

  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

- `class TaskSourceUpdateResponse: …`

  - `exchange: Exchange`

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

    - `request: ExchangeRequest`

      The request Scenario sent to the task source, placeholders filled

      - `headers: Dict[str, str]`

        Headers set by Scenario; the Authorization value is masked

      - `method: Literal["GET", "POST"]`

        HTTP method Scenario uses to call a task source.

        - `"GET"`

        - `"POST"`

      - `url: str`

        Full URL, query string included

      - `body: Optional[str]`

        Body sent with POST

    - `duration_ms: Optional[float]`

      Time from sending the request to reading the whole response

    - `response: Optional[ExchangeResponse]`

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

      - `body: str`

        Raw response body, truncated at 65,536 characters

      - `headers: Dict[str, str]`

        Response headers; a Set-Cookie value is masked

      - `status: float`

      - `is_body_truncated: Optional[bool]`

        Whether `body` was truncated

  - `tasks: List[Task]`

    The first tasks the task source returned during the validation call

    - `id: str`

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

    - `name: Optional[str]`

      The task name

    - `status: Optional[str]`

      The task status

  - `task_source: TaskSource`

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

    - `has_authorization: bool`

      Whether an Authorization header value is stored

    - `mapping: TaskSourceMapping`

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

      - `id: str`

        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.

      - `tasks_path: str`

        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[str]`

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

      - `status: Optional[str]`

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

    - `method: Literal["GET", "POST"]`

      HTTP method used to call the task source

      - `"GET"`

      - `"POST"`

    - `url: str`

      https URL of the task source

    - `body: Optional[str]`

      JSON body sent with POST

    - `parameters: Optional[Dict[str, str]]`

      Query string parameters sent to the task source

### Example

```python
import os
from scenario_sdk import Scenario

client = Scenario(
    api_key=os.environ.get("SCENARIO_SDK_API_KEY"),  # This is the default and can be omitted
    api_secret=os.environ.get("SCENARIO_SDK_API_SECRET"),  # This is the default and can be omitted
)
task_source = client.projects.task_source.update(
    project_id="projectId",
    mapping={
        "id": "x",
        "tasks_path": "tasksPath",
    },
    method="GET",
    url="url",
)
print(task_source.exchange)
```

#### 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"
    }
  }
}
```
