Skip to content
Denne side findes på dansk. Læs på dansk
HeyMySocial

Send CRM records in a batch

POST /api/v1/crm/{connection}/records

The key needs the scope leads:write

Applies up to 500 changes from your CRM in one request: contacts, leads, opportunities and sales, each with the CRM's own id.

They are the same records a signed CRM webhook carries, and they pass through the connection's status and field mapping. Records are applied one by one, in order, and each gets its own line in results. Applying a record twice changes nothing. A record that cannot be applied (it names a lead nobody knows, or is not a valid record) is kept as a reconciliation error and reported with result error; the request still answers 200. The key needs leads:write, and sales:write too when the batch holds a sale record: without it the whole batch is refused and nothing is applied.

Request

ParameterInNeededWhat it is
connectionpathyesId of a CRM connection in the workspace of the key. It is the last part of the address of the connection's page under Settings, Connections.
Idempotency-KeyheadernoYour own unique value for this request, 8 to 191 characters. A repeat with the same key and the same body returns the first response with the header Idempotent-Replay: true instead of applying the batch again.

Body

FieldTypeNeededWhat it is
recordsarray of objectyes The changes, oldest first. 1 to 500 in one request.
records[].typestringno What changed, written object.verb: contact, lead, opportunity or sale, then created, updated, deleted or merged. lead.updated is a changed lead.
records[].objectstringno The kind of record, when type is not given.One of: contact, lead, opportunity, sale
records[].actionstringno What to do with it, when type is not given. The default is upsert: create it or update it.One of: upsert, delete, merge
records[].external_idstringyes The CRM's own id of the record. A whole number is accepted too.
records[].updated_atstring (date-time)no When it changed in the CRM, as ISO 8601 or Unix seconds. The default is now. For lead status the newest change wins, and a record older than what is already stored is answered stale.
records[].merged_intostringno For a merge: the id of the record that stays.
records[].dataobjectno The fields of the record, after the connection's field mapping. Each kind of record reads its own fields; anything else is ignored.
records[].data.namestringno Contact and lead: the name of the person. Opportunity: what the opportunity is called.
records[].data.emailstringno Contact and lead: email address. A lead with the email of a contact already here is tied to that contact.
records[].data.phonestringno Contact and lead: phone number.
records[].data.companystringno Contact and lead: company.
records[].data.statusstringno Lead: the status in the CRM's own words. It is translated by the connection's status mapping, then by the built-in list; a status found in neither is reported as unmapped_status and the lead keeps the status it has.
records[].data.reasonstringno Lead: why it was disqualified or lost.
records[].data.contact_external_idstringno Lead: the CRM's id of the contact the lead belongs to, when contacts are sent as records of their own.
records[].data.lead_refstringno Lead, opportunity and sale: the HeyMySocial id of the lead, when the CRM stores it. It ties the record to a lead that was captured here.
records[].data.captured_atstring (date-time)no Lead: when the lead came in. Used only when the record creates the lead; the default is updated_at.
records[].data.first_contacted_atstring (date-time)no Lead: when it was first contacted. It only fills an empty value and never replaces one recorded here.
records[].data.lead_external_idstringno Opportunity and sale: the CRM's id of the lead it belongs to. The lead must have been sent on this connection first.
records[].data.valuenumberno Opportunity: the estimated value in major units (84000 is 84,000.00).
records[].data.value_minorintegerno Opportunity: the estimated value in minor units, instead of value.
records[].data.currencystringno Opportunity and sale: ISO 4217 code, three letters. A sale without one is refused as invalid_record.
records[].data.stagestringno Opportunity: the stage in the CRM's own words.
records[].data.expected_close_onstring (date)no Opportunity: the day it is expected to close.
records[].data.opportunity_external_idstringno Sale: the CRM's id of the opportunity it closes, when that was sent on this connection.
records[].data.amountnumberno Sale: the amount in major units. A negative amount is a refund.
records[].data.amount_minorintegerno Sale: the amount in minor units, instead of amount.
records[].data.occurred_atstring (date-time)no Sale: when the sale happened. The default is updated_at.
records[].data.kindstringno Sale: sale or refund. The default follows the sign of the amount.One of: sale, refund
records[].data.revenue_basisstringno Sale: what the amount stands for: booked (the default), invoiced or collected.One of: booked, invoiced, collected
records[].data.notestringno Sale: a short note, kept with the sale (250 characters).
curl -X POST https://heymysocial.com/api/v1/crm/01JDEXAMPLE0000000000000000/records \
  -H "Authorization: Bearer $HMS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "records": [
        {
            "type": "lead.created",
            "external_id": "L-1042",
            "updated_at": "2026-11-24T10:15:00Z",
            "data": {
                "name": "Mette Jensen",
                "email": "mette@example.com",
                "phone": "+45 55 51 23 45",
                "company": "Jensen Byg",
                "status": "Qualified"
            }
        },
        {
            "type": "opportunity.created",
            "external_id": "O-311",
            "updated_at": "2026-11-24T11:00:00Z",
            "data": {
                "lead_external_id": "L-1042",
                "name": "Roof installation",
                "value": 84000,
                "currency": "DKK",
                "stage": "Quote sent"
            }
        },
        {
            "type": "sale.created",
            "external_id": "S-88",
            "updated_at": "2026-11-25T08:30:00Z",
            "data": {
                "lead_external_id": "L-1042",
                "opportunity_external_id": "O-311",
                "amount": 84000,
                "currency": "DKK",
                "occurred_at": "2026-11-25T08:30:00Z",
                "revenue_basis": "invoiced"
            }
        },
        {
            "type": "sale.created",
            "external_id": "S-89",
            "updated_at": "2026-11-25T08:31:00Z",
            "data": {
                "lead_external_id": "L-9999",
                "amount": 1200,
                "currency": "DKK"
            }
        }
    ]
}'

Responses

200 Every record was looked at. Read results: one line for each record, in the order you sent them.

FieldTypeWhat it is
processedintegerRecords that were applied or needed no change.
failedintegerRecords with the result error. Each is kept as a reconciliation error.
resultsarray of objectWhat happened to each record, in the order sent.
results[].objectstringThe kind of record: contact, lead, opportunity or sale. Missing when the record did not say.
results[].external_idstringThe CRM's id of the record.
results[].resultstringcreated, updated, linked (tied to a lead or contact that was already here), unchanged, stale (older than what is stored), echo_ignored (a status this product sent, coming back), superseded (a newer status here stands and is sent to the CRM), deleted, merged, skipped or error.
results[].idstringThe id of the record here, when there is one.
results[].detailstringMore about the result. For error, the kind of problem: unknown_lead, unknown_contact, invalid_record or merge_review. Otherwise a note: unmapped_status (applied, but the status has no mapping), not_linked, kept_locally, relinked, duplicate_marked or erased.
{
    "processed": 3,
    "failed": 1,
    "results": [
        {
            "object": "lead",
            "external_id": "L-1042",
            "result": "created",
            "id": "01m88q4x13nxs8p0w4ejpg4rhp"
        },
        {
            "object": "opportunity",
            "external_id": "O-311",
            "result": "created",
            "id": "01m88q4x3a6qtyt80b8e2qk6ry"
        },
        {
            "object": "sale",
            "external_id": "S-88",
            "result": "created",
            "id": "01m88q4x3dspgnkctw8qr2kd54"
        },
        {
            "object": "sale",
            "external_id": "S-89",
            "result": "error",
            "detail": "unknown_lead"
        }
    ]
}

401 unauthenticated: the API key is missing, mistyped, revoked or expired.

The error shape and every code

403 access_denied: the key lacks the scope leads:write, or the batch holds a sale record and the key lacks sales:write. Nothing was applied.

The error shape and every code

404 not_found: no CRM connection with this id in the workspace of the key, or the connection was disconnected.

The error shape and every code

409 duplicate: the Idempotency-Key was already used with a different request, or the first request with it is still running (then retryable is true).

The error shape and every code

422 validation_failed: records is missing, empty, not a list of objects, or longer than 500.

The error shape and every code

429 rate_limited: too many requests with this key in one minute. Wait and send it again.

The error shape and every code