Update Sales Rep
This PUT endpoint is used to update the details of an existing sales representative identified by their unique ID. You can update personal information, contact details, status, and company/customer assignments.
Endpoint
- URL:
/api/salesRep/:id - Method:
PUT
Path Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | The unique identifier of the sales rep to update. |
Authentication
- Header:
accessToken - Type: Bearer Token
- Value:
<ACCESS-TOKEN>
Request Headers
| Header | Type | Description |
|---|---|---|
Content-Type | string | Must be application/json. |
accessToken | string | Access token for authentication. (required) |
Request Body
The body of the request should be a JSON object containing the updated details of the sales rep. All fields are optional - include only the fields you want to update:
| Field | Type | Description |
|---|---|---|
firstName | string | The first name of the sales rep. |
lastName | string | The last name of the sales rep. |
email | string | The email address of the sales rep. |
phoneNumber | string | The contact number of the sales rep. |
status | string | The status of the sales rep (e.g., "active", "inactive"). |
salesRepCompanies | array | Array of company assignments with customers and access type. |
metaFields | array | Array of meta-information fields for the sales rep. |
Sales Rep Companies Object (salesRepCompanies[])
| Field | Type | Description |
|---|---|---|
company | string | Company ID that the sales rep is assigned to. |
customers | array | Array of customer IDs assigned to this sales rep. |
accessType | string | Type of access for this company. Valid values: "customer", "role", "all". Defaults to "customer" if not specified. |
MetaFields Object (metaFields[])
| Field | Type | Description |
|---|---|---|
code | string | Code for the metafield. |
value | mixed | Value of the metafield. |
Note: When updating metafields, existing metafields with the same code will be updated, and new ones will be added.
Sample Request Body
{
"firstName": "John",
"lastName": "Doe",
"email": "john.doe.updated@example.com",
"phoneNumber": "+1234567890",
"status": "active",
"salesRepCompanies": [
{
"company": "665434c100e82884676936b9",
"customers": [
"66a5023524b16685e42a1eda",
"66a5023524b16685e42a1edb",
"66a5023524b16685e42a1edc"
],
"accessType": "customer"
},
{
"company": "665434c100e82884676936ba",
"customers": [
"66a5023524b16685e42a1edd"
],
"accessType": "role"
}
],
"metaFields": [
{
"code": "territory",
"value": "Southeast"
},
{
"code": "commission_rate",
"value": 7.5
}
]
}
Response
- Status Code: 200 OK
Success Response Body
{
"success": true,
"message": "SalesRep updated successfully",
"data": {
"id": "66a5023524b16685e42a1eda",
"email": "john.doe.updated@example.com",
"firstName": "John",
"lastName": "Doe",
"phoneNumber": "+1234567890",
"status": "active",
"verifiedEmail": true,
"salesRepCompanies": [
{
"id": "665434c100e82884676936b9",
"company": "665434c100e82884676936b9",
"customers": [
"66a5023524b16685e42a1eda",
"66a5023524b16685e42a1edb",
"66a5023524b16685e42a1edc"
],
"accessType": "customer"
},
{
"id": "665434c100e82884676936ba",
"company": "665434c100e82884676936ba",
"customers": [
"66a5023524b16685e42a1edd"
],
"accessType": "role"
}
],
"metaFields": [
{
"id": "66a5023524b16685e42a1edf",
"code": "territory",
"value": "Southeast"
},
{
"id": "66a5023524b16685e42a1ee0",
"code": "commission_rate",
"value": 7.5
}
],
"createdBy": {
"name": "API Name api",
"type": "api"
},
"createdAt": "2024-07-27T14:20:37.573Z",
"updatedAt": "2024-08-15T10:45:22.891Z"
}
}
Success Response Structure
| Field | Type | Description |
|---|---|---|
success | boolean | Indicates if the request was successful. |
message | string | Message indicating the update result. |
data | object | Contains details of the updated sales rep. |
Data Object (data)
| Field | Type | Description |
|---|---|---|
id | string | Unique identifier for the sales rep. |
email | string | Email address of the sales rep. |
firstName | string | First name of the sales rep. |
lastName | string | Last name of the sales rep. |
phoneNumber | string | Contact number of the sales rep. |
status | string | Current status of the sales rep. |
verifiedEmail | boolean | Email verification status. |
salesRepCompanies | array | Array of company assignments with IDs transformed. |
metaFields | array | Additional metadata with generated IDs. |
createdBy | object | Information about who created the sales rep. |
createdAt | string (ISO 8601) | Timestamp of when the sales rep was created. |
updatedAt | string (ISO 8601) | Timestamp of the last update (reflects this update). |
Error Responses
| Status Code | Description |
|---|---|
| 400 Bad Request | The request body contains invalid data or validation errors. |
| 401 Unauthorized | The access token is invalid or missing. |
| 403 Forbidden | You do not have permission to update sales reps. |
| 404 Not Found | No sales rep matches the specified id. |
| 500 Internal Server Error | An error occurred on the server. |