> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wazper.com/llms.txt
> Use this file to discover all available pages before exploring further.

# User Sync API

> API for synchronizing user data.

## POST `/v1/user-sync`

This endpoint is used to sync a user you have with the Wazper algorithm.

When it is called, it will run the Wazper algorithm to try to find the colleagues of that user.

### Endpoint URL

The endpoint URL is`https://api.wazper.com/v1/user-sync`

### HTTP Method

`POST`

### Headers

| Header         | Type   | Required | Description                     |
| -------------- | ------ | -------- | ------------------------------- |
| `X-API-Key`    | String | Yes      | Your Wazper API Key.            |
| `Content-Type` | String | Yes      | Must be `application/json`.     |
| `Accept`       | String | No       | Recommended `application/json`. |

### Request Body

The request body must be a JSON object containing a `user` object.

```json theme={null}
{
  "user": {
    "email": "string",
    "country": "string",
    "firstName": "string (optional)",
    "lastName": "string (optional)",
    "name": "string (optional)",
    "jobTitle": "string (optional)",
    "inviteLink": "string (optional)"
  }
}
```

**User Object Fields:**

| Field        | Type   | Required | Description                                                                                                                                                                                    |
| ------------ | ------ | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `email`      | String | Yes      | The user's email address. This is used as the primary identifier for creating or updating the user.                                                                                            |
| `country`    | String | Yes      | The user's country. This needs to be a country name, if you are using the API, you need to provide this Information accurately to get accurate results.                                        |
| `firstName`  | String | No       | The user's first name.                                                                                                                                                                         |
| `lastName`   | String | No       | The user's last name.                                                                                                                                                                          |
| `name`       | String | No       | The user's full name. If `firstName` and `lastName` are provided, they will be concatenated if `name` is not.                                                                                  |
| `jobTitle`   | String | No       | The user's job title.                                                                                                                                                                          |
| `inviteLink` | String | No       | A custom invite link for the user. If not provided, the client's default invite link may be used. (in the case where you have an invitation link per user that can be used by his colleagues). |

### Example Request (cURL)

```bash theme={null}
curl -X POST 'https://api.wazper.com/v1/user-sync' \
-H 'X-API-Key: YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
  "user": {
    "email": "john.doe@example.com",
    "country": "US",
    "firstName": "John",
    "lastName": "Doe",
    "jobTitle": "Software Engineer"
  }
}'
```

### Success Response (202 Accepted)

The response indicates that the request has been accepted for processing. The actual user synchronization and webhook trigger happen asynchronously.

```json theme={null}
{
  "success": true,
  "status": "processing",
  "requestId": "req_generated_id",
  "userId": "user_generated_id",
  "message": "Request accepted and is being processed asynchronously."
}
```

### Error Responses

* **400 Bad Request - User Email Required:**

  ```json theme={null}
  { "error": "User email is required" }
  ```
* **400 Bad Request - User IP/Country Required:**

  ```json theme={null}
  { "error": "User IP (country) is required" }
  ```
* **400 Bad Request - API Key Not Linked:**

  ```json theme={null}
  { "error": "API Key is not linked to a valid organization." }
  ```
* **401 Unauthorized - API Key Required:**

  ```json theme={null}
  { "error": "API Key is required" }
  ```
* **401 Unauthorized - Invalid API Key:**

  ```json theme={null}
  { "error": "Invalid API Key" }
  ```
* **401 Unauthorized - Invalid Organization:**

  ```json theme={null}
  { "error": "Invalid organization ID" }
  ```
* **402 Payment Required - No Credits:**

  ```json theme={null}
  { "error": "API Key has no remaining credits." }
  ```
* **500 Internal Server Error:**

  ```json theme={null}
  { "success": false, "error": "Internal server error", "details": "The error message from the server." }
  ```

### Notes

* This API will run the Wazper algorithm to find the colleagues of the user.
* If the user has a personal email address (gmail, outlook, etc..) the algorithm will not run for him.
* You are only billed a credit when more than 1 colleague is found.
* You need to handle the `country` recognition using the IP of the user for example and pass the name of the country to the API.


## OpenAPI

````yaml POST /v1/user-sync
openapi: 3.0.1
info:
  title: Wazper API
  description: >-
    API for Wazper services, including user synchronization and colleague
    management.
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://api.wazper.com
security:
  - ApiKeyAuth: []
paths:
  /v1/user-sync:
    post:
      tags:
        - V1 API
      summary: User Sync
      description: Creates or updates a user in the Wazper platform.
      operationId: postV1UserSync
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/V1UserSyncPayload'
      responses:
        '202':
          description: Request accepted for asynchronous processing.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/V1UserSyncAcceptedResponse'
        '400':
          $ref: '#/components/responses/BadRequestError'
        '401':
          $ref: '#/components/responses/UnauthorizedError'
        '402':
          $ref: '#/components/responses/PaymentRequiredError'
        '500':
          $ref: '#/components/responses/InternalServerError'
      security:
        - ApiKeyAuth: []
components:
  schemas:
    V1UserSyncPayload:
      type: object
      properties:
        user:
          $ref: '#/components/schemas/V1UserObject'
      required:
        - user
    V1UserSyncAcceptedResponse:
      type: object
      properties:
        success:
          type: boolean
          example: true
        status:
          type: string
          example: processing
          description: Indicates the request is being processed asynchronously.
        requestId:
          type: string
          description: ID of the request log.
        userId:
          type: string
          description: ID of the created/updated ClientUser.
        message:
          type: string
          example: Request accepted and is being processed asynchronously.
    V1UserObject:
      type: object
      properties:
        email:
          type: string
          format: email
          description: User's email address.
        country:
          type: string
          description: User's country or IP address.
        firstName:
          type: string
          description: User's first name.
          nullable: true
        lastName:
          type: string
          description: User's last name.
          nullable: true
        name:
          type: string
          description: User's full name.
          nullable: true
        jobTitle:
          type: string
          description: User's job title.
          nullable: true
        inviteLink:
          type: string
          format: url
          description: Custom invite link.
          nullable: true
      required:
        - email
        - country
    WazperError:
      type: object
      properties:
        error:
          type: string
      required:
        - error
  responses:
    BadRequestError:
      description: >-
        Bad Request - The request could not be understood by the server due to
        malformed syntax. The client SHOULD NOT repeat the request without
        modifications.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/WazperError'
          examples:
            missingField:
              value:
                error: Field X is required
            invalidFormat:
              value:
                error: Invalid format for field Y
    UnauthorizedError:
      description: >-
        Unauthorized - The request requires user authentication. The client may
        repeat the request with a valid X-Client-ID or other authorization.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/WazperError'
          example:
            error: Invalid client ID
    PaymentRequiredError:
      description: >-
        Payment Required - The API key has insufficient credits or the
        associated subscription is not active.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/WazperError'
          example:
            error: API Key has no remaining credits.
    InternalServerError:
      description: >-
        Internal Server Error - The server encountered an unexpected condition
        which prevented it from fulfilling the request.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/WazperError'
          example:
            error: Internal server error
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key

````