Skip to main content

Create Sales Rep

This POST endpoint is used to create a new sales representative in the system. The request must include necessary sales rep details, including personal information, contact details, and company/customer assignments.

Endpoint

  • URL: /api/salesRep
  • Method: POST

Authentication

  • Header: accessToken
  • Type: Bearer Token
  • Value: <ACCESS-TOKEN>

Request Headers

HeaderTypeDescription
Content-TypestringMust be application/json.
accessTokenstringAccess token for authentication. (required)

Request Body

The body of the request should be a JSON object containing the following sales rep details:

FieldTypeDescription
firstNamestringThe first name of the sales rep. (required)
lastNamestringThe last name of the sales rep. (optional)
emailstringThe email address of the sales rep. (required)
phoneNumberstringThe contact number of the sales rep. (optional)
statusstringThe status of the sales rep (e.g., "active", "inactive"). (optional)
salesRepCompaniesarrayArray of company assignments with customers and access type.
metaFieldsarrayArray of meta-information fields for the sales rep.

Sales Rep Companies Object (salesRepCompanies[])

This field defines which companies and customers the sales rep can access.

FieldTypeDescription
companystringCompany ID that the sales rep is assigned to. (required)
customersarrayArray of customer IDs assigned to this sales rep. (required)
accessTypestringType of access for this company. Valid values: "customer", "role", "all". Defaults to "customer" if not specified.

Important Validation:

  • All customers must exist in the system
  • Each customer must belong to the company specified in the same salesRepCompanies object
  • If validation fails, the request will return an error

MetaFields Object (metaFields[])

FieldTypeDescription
codestringCode for the metafield.
valuemixedValue of the metafield.

Sample Request Body

{
"firstName": "John",
"lastName": "Doe",
"email": "john.doe@example.com",
"phoneNumber": "+1234567890",
"salesRepCompanies": [
{
"company": "665434c100e82884676936b9",
"customers": [
"66a5023524b16685e42a1eda",
"66a5023524b16685e42a1edb"
],
"accessType": "customer"
},
{
"company": "665434c100e82884676936ba",
"customers": [
"66a5023524b16685e42a1edc"
],
"accessType": "role"
}
],
"metaFields": [
{
"code": "territory",
"value": "Northeast"
},
{
"code": "employee_id",
"value": "EMP-12345"
}
]
}

Response

  • Status Code: 200 OK

Success Response Body

{
"success": true,
"message": "SalesRep created successfully",
"data": {
"id": "66a5023524b16685e42a1eda",
"email": "john.doe@example.com",
"firstName": "John",
"lastName": "Doe",
"phoneNumber": "+1234567890",
"status": "invited",
"verifiedEmail": false,
"salesRepCompanies": [
{
"id": "665434c100e82884676936b9",
"company": "665434c100e82884676936b9",
"customers": [
"66a5023524b16685e42a1eda",
"66a5023524b16685e42a1edb"
],
"accessType": "customer"
}
],
"metaFields": [
{
"id": "66a5023524b16685e42a1edf",
"code": "territory",
"value": "Northeast"
}
],
"createdBy": {
"name": "API Name api",
"type": "api"
},
"createdAt": "2024-07-27T14:20:37.573Z",
"updatedAt": "2024-07-27T14:20:37.573Z"
}
}

Success Response Structure

FieldTypeDescription
successbooleanIndicates if the request was successful.
messagestringMessage indicating the result of the operation.
dataobjectContains details of the newly created sales rep.

Data Object (data)

FieldTypeDescription
idstringUnique identifier for the sales rep.
emailstringEmail address of the sales rep.
firstNamestringFirst name of the sales rep.
lastNamestringLast name of the sales rep.
phoneNumberstringContact number of the sales rep.
statusstringCurrent status (active
verifiedEmailbooleanEmail verification status (false initially).
salesRepCompaniesarrayArray of company assignments with IDs transformed.
metaFieldsarrayAdditional metadata with generated IDs.
createdByobjectInformation about who created the sales rep.
createdAtstring (ISO 8601)Timestamp of when the sales rep was created.
updatedAtstring (ISO 8601)Timestamp of the last update.

Error Responses

Status CodeDescription
400 Bad RequestInvalid data, missing required fields, or validation errors.
401 UnauthorizedThe access token is invalid or missing.
403 ForbiddenYou do not have permission to create sales reps.
500 Internal Server ErrorAn error occurred on the server.