# Update Onboarded Carrier Contact

### Authentication

- Include your `Access-Token` in the header of your requests.
- Include your `x-api-key` The API key provided by GenLogs.

### Permissions

The `external-api-update-onboarded-carrier-contact` permission is required to access this endpoint.

### Endpoint

- **URL:** `https://api.genlogs.io/onboarded-carrier/contacts/{contact_id}`
- **Method:** `PATCH`

### Headers

- **Access-Token**: (string, required): Access token obtained from the "Create Access Token" endpoint.
- **X-Api-Key** (string, required): The API key provided by GenLogs.

### Path Params

- **contact_id** (string, required): Existent contact ID, to be updated.

### Request Body:

- **name** (string, optional): Contact name.
- **phone** (string, optional): Contact phone number.
- **email** (string, optional): Contact email address.

### Request Example:

```bash
curl --location --request PATCH 'https://api.genlogs.io/onboarded-carrier/contacts/ca387122-4153-418b-82df-03008cc9af9b' \
--header 'access-token: <your-api-access-token>' \
--header 'x-api-key: <your-x-api-key>' \
--header 'Content-Type: application/json' \
--data '{\n    "email": "peter_parker@test_email.com",\n    "name": "Peter Parker",\n    "phone": "3432434234"\n}'
```

### Response:

- **200 OK:** A JSON object containing updated information of carrier contact.
- **400 Bad Request:** If required parameters are missing or invalid.
- **401 Unauthorized:** If the authentication credentials (Access-Token) are missing or incorrect.
- **403 Forbidden**: If the permission has not been added to your user.
- **404 Not Found**: If the provided `contact_id` doesn't exist or is not created.
- **500 Internal Server Error:** If there is an issue on the server that prevents processing the request.

### Response Body:

#### 200 OK – Contact Created Successfully

```json
{
  "contact": {
    "contact_id": "bd849e72-09f0-4d19-8b20-e227cd4ef455",
    "name": "Peter Parker",
    "phone": "3432434234",
    "email": "peter.parker@marvel.com"
  }
}
```

#### 400 Bad Request
Returned when:
- All of `name`, `phone`, and `email` are null.
- All of `name`, `phone`, and `email` are empty strings.
- All the provided values are exactly the same as stored.

```json
{
    "detail": "Value error, at least one of name, email, or phone must be provided for update."
}
```

#### 401 Unauthorized
When access-token is missing or expired.

```json
{
    "detail": "Token is missing!"
}
```

#### 403 Forbidden

```json
{
    "detail": "User not allowed to access this endpoint"
}
```

#### 404 Not Found

```json
{
    "detail": "Preferred carrier contact not found."
}
```

### Update an onboarded carrier contact

`PATCH https://api.genlogs.io/onboarded-carrier/contacts/{contact_id}`

Updates an existing onboarded carrier contact for the authenticated customer. Requires a valid JWT token and the appropriate permission. Only the fields provided in the request body will be updated. USDOT updates are not supported by this endpoint; including `usdot` in the PATCH body returns Bad Request before any persistence operation.

#### Authorizations

- **AccessTokenAuth** & **ApiKeyAuth**

#### Path parameters

- **contact_id** (string, required): Unique identifier of the contact to update. Example: `bd849e72-09f0-4d19-8b20-e227cd4ef455`

#### Body

- Must be in **application/json** format with at least one field provided. `usdot` is not accepted in PATCH requests.

#### Responses

- **200:** Contact updated successfully.

```json
{
  "contact": {
    "id": "bd849e72-09f0-4d19-8b20-e227cd4ef455",
    "name": "Peter Parker",
    "phone": "3432434234",
    "email": "peter.parker@marvel.com"
  }
}
```

- **400:** Bad Request – Missing or invalid fields.

- **401:** Unauthorized – Invalid or missing Access-Token.

- **403:** Forbidden – The user lacks required permission or does not own the contact.

- **404:** Contact not found.

- **500:** Internal Server Error.
