# Update Datasource

## Description

This service is used to update a partner datasource for the authenticated user.

***

## Request

### Restrictions

This service requires an authenticated user and can only be called after a successful partner login.

### Endpoint

```
PUT https://<server-url>/api/v4/partner/datasources/{datasource_id}
```

### Parameters

| Parameter       | Location       | Description                                                                        |
| --------------- | -------------- | ---------------------------------------------------------------------------------- |
| `touchpoint`    | Query / Header | The authentication token for the API session. Use `Thalamus-Token` for the header. |
| `token`         | Query / Header | The authentication token for the API session. Use `Thalamus-Token` for the header. |
| `datasource_id` | Query / Header | <p>The ID of the datasource to be modified.</p><p></p>                             |

### Full URL Example

```
https://<server-url>/api/v4/partner/datasources/14?touchpoint=test&token=...
```

### Request Body

The request body must be a JSON object with the following fields:

| Field                | Type      | Required | Description                                                                                                                                                     |
| -------------------- | --------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `host`               | `string`  | Yes      | The host URL for the datasource (e.g., "test.myftp.net").                                                                                                       |
| `user`               | `string`  | Yes      | The username for the datasource.                                                                                                                                |
| `password`           | `string`  | Yes      | The password for the user.                                                                                                                                      |
| `workingDirectory`   | `string`  | Yes      | The remote working directory on the host (e.g., "/stock").                                                                                                      |
| `processorType`      | `integer` | Yes      | The data processor type. Supported values are: 25006 (Physical location), 25004 (Company), 25011 (Partner Sales), 25012 (Partner Stock), 25000 (Person Import). |
| `fileImportType`     | `string`  | No       | The type of file to be imported. Supported values: `PARTY`, `PRINCIPAL`.                                                                                        |
| `authenticationType` | `string`  | Yes      | The authentication method. Supported values: `PASSWORD`, `CERTIFICATE`.                                                                                         |
| `dataSourceType`     | `string`  | Yes      | The type of datasource. Supported values: `FTP`, `SFTP,S3.`                                                                                                     |
| `touchpointCode`     | `string`  | Yes      | The touchpoint code associated with the datasource.                                                                                                             |
| `amountCalculated`   | `boolean` | No       | <p>According to datasource for extra calculation</p><p></p>                                                                                                     |

JSON

```
{
  "host": "test.myftp.net",
  "user": "demo",
  "password": "password",
  "workingDirectory": "/stock",
  "processorType": 25012,
  "fileImportType": "PARTY",
  "authenticationType": "PASSWORD",
  "dataSourceType": "FTP",
  "touchpointCode": "test",
  "amountCalculated": true
}
```

***

## Response

### ✅ Successful Response: `200 Ok`

* HTTP Status Code: `200 Ok`
* Body: A JSON object confirming the successful update of the datasource.

Example Response

```
{
  "context": {
    "links": [
      {
        "ref": "home",
        "href": "http://localhost:8080/thalamus/api/v3/people/home"
      }
    ],
    "activities": [],
    "simpleProfile": {
      "firstname": null,
      "lastname": null,
      "email": null,
      "shortName": null,
      "longName": null,
      "me": false,
      "urlAvatar": ""
    }
  },
  "datasource": {
    "id": 1,
    "host": "test.myftp.net",
    "user": "demo",
    "password": "password",
    "workingDirectory": "/stock",
    "processorType": 25012,
    "fileImportType": "PARTY",
    "dataSourceType": "FTP",
    "touchpointCode": "test",
    "authenticationType": "PASSWORD",
    "touchpointCode": "REST02",
    "active": true,
    "privateKeyFile": null,
    "passphrase": null,
    "region": null,
    "reprocessingDays": null,
    "lastRunningTime": null,
    "amountCalculated": true
  }
}
```

### ❌ Unsuccessful Response: `400 Bad Request`

* HTTP Status Code: `400 Bad Request`
* Body: A JSON object containing details about the error.

Example Response

```
{
  "errors": {
    "partnerDataSource": "TouchpointCodeRequired",
    "partnerDataSource": "InvalidTouchpointCode"
  }
}
```
