<!-- Generated by scripts/build-docs.js. Edit docs/swagger.yaml or docs/guides/, then run `npm run docs:build`. -->

# Store raw integration records

`POST https://marketplace-api.sequifi.com/v1/integration-raw-data`

Module: Integrations · operationId: `ingestIntegrationRawData` · Auth: `Authorization: Bearer <token>`
Web page: https://apidocs.sequifi.com/#/api/ingest-integration-raw-data

Stores raw records from a connected source system (a CRM or lender system) with change detection, and returns the records that are new or changed so you can map them into sales. It creates no sales and starts no processing: send the mapped records to `POST /v1/sales` afterwards.

**Before you call:**

- Pick the `integration_type` for your source. Each type has a natural key that identifies a record: `encompass` `loan_id`, `enerflo` `pid`, `arive` `arive_loan_id`, `jobnimbus` `jnid`, `pipesolar` `pid`, `proline` `project_id`, `byte` `byte_loan_id`, `sonar` and `gaiia` `account_id`, `subhub` `pid`, `hubspot` `hs_object_id`, `monday` `item_id`, `gohighlevel` `opportunity_id`, `pocomos` `pcc_id`, `acculynx` `job_id`.
- Records are kept per company, type and key. Sending a key again updates that record.

**What happens:**

- Every record is checked first. Any error rejects the whole request with `400` and nothing is stored.
- Fixed-field types (`encompass`, `enerflo`, `arive`, `jobnimbus`, `pipesolar`, `proline`, `byte`): only the fields listed for the type are stored; other fields are dropped without a warning. The whole request is saved in one transaction.
- Flexible types (`sonar`, `gaiia`, `subhub`, `hubspot`, `monday`, `gohighlevel`, `pocomos`, `acculynx`): every field you send is stored, including misspelled ones. Records are saved in groups, not in one transaction, so a failed request can leave some records stored. A record over 400 KB is rejected.
- New key: the record is stored. On fixed-field types, fields you leave out are stored empty.
- Known key: a field you leave out keeps its stored value, `null` clears it, and any other value replaces it. Some date fields cannot be cleared once set (`sale_date` on most types, `status_date_won` on `proline`, `signed_date` on `hubspot`): `null` or `""` keeps the stored date.
- Changes are found field by field after normalizing values. Date-time values are compared by date only, so a change to the time of day alone counts as unchanged.
- `changed_records` holds the new records, then the updated ones, each as stored after the merge. Unchanged records are only counted, unless you send `return_all: true` (fixed-field types only), which adds them at the end.

**Idempotency and retries:**

- Resending identical data stores nothing new and reports the records as `unchanged`. Retrying after a `500` or a timeout is safe and completes a partly stored request.

**Formats:**

- Natural keys can be strings or numbers. They are trimmed, stored as strings (at most 255 characters), and must be unique within the request.
- Date fields listed for a type must start with a real `YYYY-MM-DD` date; only the first 10 characters are checked.
- On fixed-field types, send date-time fields such as `modified_date_time` as `YYYY-MM-DD HH:MM:SS`. A value ending in `Z` fails the whole request with `500`, and a value with an offset (`-04:00`) is converted to the server's time zone.
- JobNimbus dates are Unix timestamps in seconds, not `YYYY-MM-DD`.
- `data` holds at most 1,000 records. About 100 records per request stays well inside the 29-second gateway timeout.

**Errors:**

- `400 Bad Request: Expected a JSON object with integration_type and data array`: the body is not a JSON object.
- `400 Bad Request: integration_type is required` or `Bad Request: unknown integration_type`: `data.supported` lists the valid types.
- `400 Bad Request: "data" must be a non-empty array of records`.
- `400 Bad Request: data array exceeds 1000 records — chunk client-side`: `data.received` and `data.max` give the counts.
- `400 Validation Failed`: `data.errors[]` lists each problem (missing or duplicate key, bad date, record not an object, record too large).
- `401`: missing, invalid or expired token. The body is `{"message": "Unauthorized"}`.
- `500 Database Connection Error` or `Internal Server Error`: retry. `data.details` is a technical message; do not parse it.

**Common mistakes:**

- Expecting sales to appear. Map `changed_records` and send them to `POST /v1/sales`.
- Leaving out a field the store needs on a new fixed-field record (for example `pid` on `encompass`, `total_loan_amount` on `byte` and `arive`, or the fee fields on `arive`). The whole request fails with `500`.
- Sending `return_all` for a flexible type. It is ignored.

**Related:**

- `POST /v1/sales`: send the mapped sales.
- `GET /v1/products`, `GET /v1/milestones`, `GET /v1/users`: values for the mapping.

## Request body

- `integration_type` (string, **required**): Source system. Case-insensitive; surrounding spaces are removed. `encompass`, `enerflo`, `arive`, `jobnimbus`, `pipesolar`, `proline` and `byte` store a fixed list of fields. `sonar`, `gaiia`, `subhub`, `hubspot`, `monday`, `gohighlevel`, `pocomos` and `acculynx` store every field sent. One of: `encompass`, `enerflo`, `arive`, `jobnimbus`, `pipesolar`, `proline`, `byte`, `sonar`, `gaiia`, `subhub`, `hubspot`, `monday`, `gohighlevel`, `pocomos`, `acculynx`.
- `data` (array of object | object | object | object | object | object | object | object, **required**): 1 to 1,000 raw records. The shape depends on `integration_type`. Only the natural key is required; every other field is optional. Max items: 1000.
- `return_all` (boolean): `true` also returns unchanged records at the end of `changed_records`, so you can map and resend them (for example after adding a rep who was missing). They are still counted as `unchanged` and not rewritten. Fixed-field types only; ignored for flexible types. Default: `false`.

Example (enerflo_batch): Enerflo, one solar install

```json
{
  "integration_type": "enerflo",
  "data": [
    {
      "pid": "EF-20931",
      "customer_id": "67890",
      "proposal_id": "PROP-2026-0042",
      "product_name": "Solar Rooftop",
      "customer_name": "Alex Morgan",
      "customer_email": "alex.morgan@example.com",
      "customer_phone": "555-010-4821",
      "customer_address": "1200 Desert Willow Rd",
      "customer_city": "Phoenix",
      "customer_state": "AZ",
      "location_code": "AZ",
      "customer_zip": "85001",
      "install_partner": "Brightline Solar",
      "gross_account_value": 27720,
      "kw": 7.2,
      "epc": 3.85,
      "net_epc": 3.2,
      "dealer_fee": 4158,
      "dealer_fee_percentage": 0.15,
      "adders_total": 1100,
      "system_cost_base_adders": 28820,
      "job_status": "Install Scheduled",
      "sale_date": "2026-05-01",
      "m1_date": "2026-05-08",
      "m2_date": null,
      "m3_date": null,
      "sales_rep_id": "4521",
      "sales_rep_name": "Jordan Reyes",
      "sales_rep_email": "jordan.reyes@example.com",
      "setter_id": "3310",
      "setter_name": "Casey Lee",
      "setter_email": "casey.lee@example.com"
    }
  ]
}
```

Example (encompass_batch): Encompass, one loan

```json
{
  "integration_type": "encompass",
  "data": [
    {
      "loan_id": "95f78daa-bcc7-4f08-88ed-eb29a811d57d",
      "pid": "LN-2026-0042",
      "customer_name": "Morgan Ellis",
      "customer_email": "morgan.ellis@example.com",
      "customer_mobile": "5550104821",
      "customer_address1": "88 Live Oak Ln",
      "customer_city": "Austin",
      "customer_state": "TX",
      "customer_zip": "78701",
      "base_amount": "350000",
      "gross_revenue": "3500",
      "credit_report_fee": "75",
      "loan_status": "Funded",
      "sale_date": "2026-05-15",
      "product_name": "Conventional",
      "mlo_email": "morgan.hayes@example.com",
      "loa_email": "dana.kim@example.com",
      "processor_email": "sam.ortiz@example.com"
    }
  ]
}
```

Example (arive_batch): Arive, one loan

```json
{
  "integration_type": "arive",
  "data": [
    {
      "arive_loan_id": "AR-2026-0001",
      "lender_loan_identifier": "LL-001",
      "lender_name": "Example Lending",
      "mortgage_type": "Conventional",
      "borrower_name": "Morgan Ellis",
      "borrower_email": "morgan.ellis@example.com",
      "borrower_state": "TX",
      "borrower_city": "Austin",
      "borrower_zip": "78701",
      "total_loan_amount": "350000",
      "dealer_fee": "0",
      "dealer_fee_percentage": "0",
      "sow_adder_fee": "0",
      "compensation_type": "Broker",
      "loan_status": "Funded",
      "sale_date": "2026-05-15",
      "loan_originator_email": "morgan.hayes@example.com",
      "loan_officer_assistant_email": "dana.kim@example.com"
    }
  ]
}
```

## Example request

```bash
curl -X POST "https://marketplace-api.sequifi.com/v1/integration-raw-data" \
  -H "Authorization: Bearer $SEQUIFI_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"integration_type":"enerflo","data":[{"pid":"EF-20931","customer_id":"67890","proposal_id":"PROP-2026-0042","product_name":"Solar Rooftop","customer_name":"Alex Morgan","customer_email":"alex.morgan@example.com","customer_phone":"555-010-4821","customer_address":"1200 Desert Willow Rd","customer_city":"Phoenix","customer_state":"AZ","location_code":"AZ","customer_zip":"85001","install_partner":"Brightline Solar","gross_account_value":27720,"kw":7.2,"epc":3.85,"net_epc":3.2,"dealer_fee":4158,"dealer_fee_percentage":0.15,"adders_total":1100,"system_cost_base_adders":28820,"job_status":"Install Scheduled","sale_date":"2026-05-01","m1_date":"2026-05-08","m2_date":null,"m3_date":null,"sales_rep_id":"4521","sales_rep_name":"Jordan Reyes","sales_rep_email":"jordan.reyes@example.com","setter_id":"3310","setter_name":"Casey Lee","setter_email":"casey.lee@example.com"}]}'
```

## Responses

### 200: Records stored. Read `changed_records` for what to map.

- `status` (integer): The HTTP status code, repeated. Example: `200`.
- `message` (string): Short text. Wording varies by endpoint; branch on the HTTP status, not on this text. Example: `success`.
- `data` (object)
  - `integration_type` (string): The type used, lower case.
  - `stats` (object): Counts for this request.
    - `inserted` (integer): New keys stored.
    - `updated` (integer): Known keys with at least one changed field.
    - `unchanged` (integer): Known keys with no change.
    - `totalProcessed` (integer): Records in the request.
  - `changed_records` (array of object): New records, then updated records, then (with `return_all`) unchanged records. Fixed-field types return every stored field of the type, with `null` for empty ones; flexible types return the fields stored for the record.

```json
{
  "status": 200,
  "message": "Integration Raw Data Processed Successfully",
  "data": {
    "integration_type": "enerflo",
    "stats": {
      "inserted": 1,
      "updated": 0,
      "unchanged": 1,
      "totalProcessed": 2
    },
    "changed_records": [
      {
        "pid": "EF-20931",
        "customer_id": "67890",
        "proposal_id": "PROP-2026-0042",
        "product_name": "Solar Rooftop",
        "customer_name": "Alex Morgan",
        "customer_email": "alex.morgan@example.com",
        "customer_phone": "555-010-4821",
        "customer_address": "1200 Desert Willow Rd",
        "customer_city": "Phoenix",
        "customer_state": "AZ",
        "location_code": "AZ",
        "customer_zip": "85001",
        "install_partner": "Brightline Solar",
        "gross_account_value": 27720,
        "kw": 7.2,
        "epc": 3.85,
        "net_epc": 3.2,
        "dealer_fee": 4158,
        "dealer_fee_percentage": 0.15,
        "adders_total": 1100,
        "system_cost_base_adders": 28820,
        "job_status": "Install Scheduled",
        "sale_date": "2026-05-01",
        "cancel_date": null,
        "m1_date": "2026-05-08",
        "m2_date": null,
        "m3_date": null,
        "sales_rep_id": "4521",
        "sales_rep_name": "Jordan Reyes",
        "sales_rep_email": "jordan.reyes@example.com",
        "setter_id": "3310",
        "setter_name": "Casey Lee",
        "setter_email": "casey.lee@example.com"
      }
    ]
  }
}
```

### 400: Nothing was stored. The message says what to fix.

Example (missing_type): integration_type missing

```json
{
  "status": 400,
  "message": "Bad Request: integration_type is required",
  "data": {
    "supported": [
      "encompass",
      "enerflo",
      "arive",
      "jobnimbus",
      "pipesolar",
      "proline",
      "byte",
      "sonar",
      "gaiia",
      "subhub",
      "hubspot",
      "monday",
      "gohighlevel",
      "pocomos",
      "acculynx"
    ]
  }
}
```

### 401: Missing, invalid or expired token. The body has only `message`.

```json
{
  "message": "Unauthorized"
}
```

### 500: Server error. Some flexible-type records may be stored; resending is safe.

```json
{
  "status": 500,
  "message": "Internal Server Error",
  "data": {
    "details": "Technical detail"
  }
}
```
