Skip to main content
API reference

Commerce Memory

Generated HTTP reference for the 12 operations the published OpenAPI document describes under commerce-memory.

11 min read
View MarkdownEdit on GitHub

Commerce Memory

This page is generated from the published OpenAPI document. It is complete with respect to that document and says nothing about surfaces the document does not describe yet. See what is generated here for what that means.

Base URL: https://api.codespar.dev

Every operation below requires a Bearer token. See Authentication.

GET /v1/commerce-memory/counterparties

List this project's counterparties (deprecated path)

Query parameters

NameTypeRequiredDescription
identifierstringno
identifier_kind"cnpj" | "cpf" | "email" | "phone" | "wallet_address" | "other"no
kind"supplier" | "customer" | "agent_peer"no
limitintegerno

Responses

StatusBodyDescription
200objectOK
400objectinvalid_query, with the validator's issue list under details.issues.

Response 200

FieldTypeRequiredDescription
counterpartiesarray of objectyes

Example response

{
  "counterparties": [
    {
      "id": "obj_0000000000000000",
      "kind": "supplier",
      "name": "Example",
      "identifier_kind": "cnpj",
      "metadata": {},
      "created_at": "2026-01-15T12:00:00.000Z",
      "last_seen_at": "2026-01-15T12:00:00.000Z"
    }
  ]
}

Example request

curl -X GET https://api.codespar.dev/v1/commerce-memory/counterparties \
  -H "Authorization: Bearer $CODESPAR_API_KEY"

POST /v1/commerce-memory/counterparties

Register a counterparty, or merge into the one already there (deprecated path)

Request body

FieldTypeRequiredDescription
identifierstringnoSet it together with identifier_kind or omit both. One without the other is refused.
identifier_kind"cnpj" | "cpf" | "email" | "phone" | "wallet_address" | "other"no
kind"supplier" | "customer" | "agent_peer"yes
metadataobjectno
namestringyes

Responses

StatusBodyDescription
201objectCreated, or merged into the existing row.
400objectinvalid_body. details.issues carries the validator's own issue list, including the case where only one of identifier / identifier_kind was sent.

Response 201

FieldTypeRequiredDescription
created_atstring (date-time)yes
idstringyescp_ prefixed.
identifierstring,nullyesNull when the counterparty was registered without one.
identifier_kind"cnpj" | "cpf" | "email" | "phone" | "wallet_address" | "other"yes
kind"supplier" | "customer" | "agent_peer"yes
last_seen_atstring (date-time)yesBumped by a re-registration of the same identifier and by every interaction written against this counterparty.
metadataobjectyes
namestringyes

Example response

{
  "id": "obj_0000000000000000",
  "kind": "supplier",
  "name": "Example",
  "identifier_kind": "cnpj",
  "metadata": {},
  "created_at": "2026-01-15T12:00:00.000Z",
  "last_seen_at": "2026-01-15T12:00:00.000Z"
}

Example request

curl -X POST https://api.codespar.dev/v1/commerce-memory/counterparties \
  -H "Authorization: Bearer $CODESPAR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
       "kind": "supplier",
       "name": "Example",
       "identifier": "string",
       "identifier_kind": "cnpj",
       "metadata": {}
     }'

GET /v1/commerce-memory/counterparties/{id}

Read one counterparty (deprecated path)

Path parameters

NameTypeRequiredDescription
idstringyescp_ prefixed.

Responses

StatusBodyDescription
200objectOK
404objectnot_found, including for a counterparty outside the caller's project.

Response 200

FieldTypeRequiredDescription
created_atstring (date-time)yes
idstringyescp_ prefixed.
identifierstring,nullyesNull when the counterparty was registered without one.
identifier_kind"cnpj" | "cpf" | "email" | "phone" | "wallet_address" | "other"yes
kind"supplier" | "customer" | "agent_peer"yes
last_seen_atstring (date-time)yesBumped by a re-registration of the same identifier and by every interaction written against this counterparty.
metadataobjectyes
namestringyes

Example response

{
  "id": "obj_0000000000000000",
  "kind": "supplier",
  "name": "Example",
  "identifier_kind": "cnpj",
  "metadata": {},
  "created_at": "2026-01-15T12:00:00.000Z",
  "last_seen_at": "2026-01-15T12:00:00.000Z"
}

Example request

curl -X GET https://api.codespar.dev/v1/commerce-memory/counterparties/{id} \
  -H "Authorization: Bearer $CODESPAR_API_KEY"

GET /v1/commerce-memory/insights/counterparty-summary

Per counterparty rollup over a window

Query parameters

NameTypeRequiredDescription
kind"supplier" | "customer" | "agent_peer"no
limitintegerno
sincestring (date-time)noInclusive lower bound on occurred_at.
untilstring (date-time)noExclusive upper bound on occurred_at.

Responses

StatusBodyDescription
200objectOK
400objectinvalid_query, with the validator's issue list under details.issues.

Response 200

FieldTypeRequiredDescription
rowsarray of objectyes
windowobjectyesThe since and until of the request, echoed back, null when not supplied.

Example response

{
  "window": {},
  "rows": [
    {
      "counterparty_id": "counterparty_0000000000000000",
      "name": "Example",
      "kind": "supplier",
      "identifier_kind": "cnpj",
      "last_seen_at": "2026-01-15T12:00:00.000Z",
      "interaction_count": 1,
      "payment_count": 1,
      "total_payment_minor": 1,
      "currencies": [
        "string"
      ]
    }
  ]
}

Example request

curl -X GET https://api.codespar.dev/v1/commerce-memory/insights/counterparty-summary \
  -H "Authorization: Bearer $CODESPAR_API_KEY"

GET /v1/commerce-memory/insights/negotiation-stats

Negotiation outcomes and average discount, grouped by item

Query parameters

NameTypeRequiredDescription
item_refstringno
sincestring (date-time)noInclusive lower bound on started_at.
untilstring (date-time)noExclusive upper bound on started_at.

Responses

StatusBodyDescription
200objectOK
400objectinvalid_query, with the validator's issue list under details.issues.

Response 200

FieldTypeRequiredDescription
item_refstring,nullyesThe item_ref filter of the request, echoed back.
rowsarray of objectyes
windowobjectyesThe since and until of the request, echoed back, null when not supplied.

Example response

{
  "window": {},
  "rows": [
    {
      "outcome": "agreed",
      "n": 0,
      "currencies": [
        "string"
      ],
      "discount_sample_n": 1
    }
  ]
}

Example request

curl -X GET https://api.codespar.dev/v1/commerce-memory/insights/negotiation-stats \
  -H "Authorization: Bearer $CODESPAR_API_KEY"

GET /v1/commerce-memory/insights/top-counterparties

Counterparties ranked by payment volume in a window

Query parameters

NameTypeRequiredDescription
kind"supplier" | "customer" | "agent_peer"no
limitintegerno
sincestring (date-time)noInclusive lower bound on occurred_at.
untilstring (date-time)noExclusive upper bound on occurred_at.

Responses

StatusBodyDescription
200objectOK
400objectinvalid_query, with the validator's issue list under details.issues.

Response 200

FieldTypeRequiredDescription
kind"supplier" | "customer" | "agent_peer"yesThe kind filter of the request, echoed back.
rowsarray of objectyes
windowobjectyesThe since and until of the request, echoed back, null when not supplied.

Example response

{
  "window": {},
  "kind": "supplier",
  "rows": [
    {
      "counterparty_id": "counterparty_0000000000000000",
      "name": "Example",
      "kind": "supplier",
      "payment_count": 1,
      "total_payment_minor": 1
    }
  ]
}

Example request

curl -X GET https://api.codespar.dev/v1/commerce-memory/insights/top-counterparties \
  -H "Authorization: Bearer $CODESPAR_API_KEY"

GET /v1/commerce-memory/interactions

List recorded interactions

Query parameters

NameTypeRequiredDescription
counterparty_idstringno
kind"quote" | "negotiation" | "order" | "invoice" | "payment" | "shipment" | "message" | "other"no
limitintegerno
sincestring (date-time)noInclusive lower bound on occurred_at.
untilstring (date-time)noExclusive upper bound on occurred_at.

Responses

StatusBodyDescription
200objectOK
400objectinvalid_query, with the validator's issue list under details.issues.

Response 200

FieldTypeRequiredDescription
interactionsarray of objectyes

Example response

{
  "interactions": [
    {
      "id": "obj_0000000000000000",
      "counterparty_id": "counterparty_0000000000000000",
      "kind": "quote",
      "occurred_at": "2026-01-15T12:00:00.000Z",
      "source": "agent_execute",
      "metadata": {}
    }
  ]
}

Example request

curl -X GET https://api.codespar.dev/v1/commerce-memory/interactions \
  -H "Authorization: Bearer $CODESPAR_API_KEY"

POST /v1/commerce-memory/interactions

Record a commercial event against a counterparty

Request body

FieldTypeRequiredDescription
agent_idstringno
amount_minorintegernoMinor units. Set it together with currency or omit both.
counterparty_idstringyes
currencystringno
kind"quote" | "negotiation" | "order" | "invoice" | "payment" | "shipment" | "message" | "other"yes
metadataobjectno
occurred_atstring (date-time)noDefaults to now.
source"agent_execute" | "webhook" | "manual" | "backfill"no
source_refstringnoThe idempotency key, paired with source. Omit it and every post writes a new row.

Responses

StatusBodyDescription
200objectIdempotent replay. (source, source_ref) already existed in this project; nothing was written and the stored row is returned.
201objectRecorded.
400objectinvalid_body, with the validator's issue list under details.issues.
404objectcounterparty_not_found: the id does not belong to this org and project.
500objectidempotent_lookup_failed. The insert hit the idempotency key but the conflicting row could not be read back afterwards. Nothing was written; the call is safe to retry.

Response 200

FieldTypeRequiredDescription
idempotenttrueyes
interactionobjectyes

Example response

{
  "idempotent": true,
  "interaction": {
    "id": "obj_0000000000000000",
    "counterparty_id": "counterparty_0000000000000000",
    "kind": "quote",
    "occurred_at": "2026-01-15T12:00:00.000Z",
    "source": "agent_execute",
    "metadata": {}
  }
}

Example request

curl -X POST https://api.codespar.dev/v1/commerce-memory/interactions \
  -H "Authorization: Bearer $CODESPAR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
       "counterparty_id": "counterparty_0000000000000000",
       "kind": "quote",
       "amount_minor": 1000,
       "currency": "BRL",
       "occurred_at": "2026-01-15T12:00:00.000Z",
       "source": "agent_execute",
       "source_ref": "string",
       "agent_id": "agt_0000000000000000",
       "metadata": {}
     }'

GET /v1/commerce-memory/negotiations

List negotiations

Query parameters

NameTypeRequiredDescription
counterparty_idstringno
item_refstringno
limitintegerno
outcome"agreed" | "declined" | "pending" | "expired"no

Responses

StatusBodyDescription
200objectOK
400objectinvalid_query, with the validator's issue list under details.issues.

Response 200

FieldTypeRequiredDescription
negotiationsarray of objectyes

Example response

{
  "negotiations": [
    {
      "id": "obj_0000000000000000",
      "counterparty_id": "counterparty_0000000000000000",
      "item": "string",
      "currency": "BRL",
      "rounds": 0,
      "outcome": "agreed",
      "started_at": "2026-01-15T12:00:00.000Z",
      "metadata": {}
    }
  ]
}

Example request

curl -X GET https://api.codespar.dev/v1/commerce-memory/negotiations \
  -H "Authorization: Bearer $CODESPAR_API_KEY"

POST /v1/commerce-memory/negotiations

Record a price negotiation and its outcome

Request body

FieldTypeRequiredDescription
agent_idstringno
agreed_price_minorintegernoMinor units of currency. Required when outcome is agreed.
closed_atstring (date-time)noRead only when outcome is terminal. Ignored while the outcome is pending.
counterparty_idstringyes
currencystringyes
initial_price_minorintegernoMinor units of currency.
itemstringyesFree text description of what was negotiated.
item_refstringnoStructured pointer (sku, contract id, supplier product code). It is the grouping key of the negotiation-stats rollup.
metadataobjectno
outcome"agreed" | "declined" | "pending" | "expired"noDefaults to pending.
roundsintegernoDefaults to 1.
started_atstring (date-time)noDefaults to now.

Responses

StatusBodyDescription
201objectRecorded.
400objectinvalid_body, with the validator's issue list under details.issues. Includes the outcome: agreed without agreed_price_minor case.
404objectcounterparty_not_found: the id does not belong to this org and project.

Response 201

FieldTypeRequiredDescription
agent_idstring,nullyes
agreed_price_minorinteger,nullyesMinor units of currency.
closed_atstring,null (date-time)yesNull exactly when outcome is pending.
counterparty_idstringyes
currencystringyes
idstringyesneg_ prefixed.
initial_price_minorinteger,nullyesMinor units of currency.
itemstringyes
item_refstring,nullyes
metadataobjectyes
outcome"agreed" | "declined" | "pending" | "expired"yes
roundsintegeryes
started_atstring (date-time)yes

Example response

{
  "id": "obj_0000000000000000",
  "counterparty_id": "counterparty_0000000000000000",
  "item": "string",
  "currency": "BRL",
  "rounds": 0,
  "outcome": "agreed",
  "started_at": "2026-01-15T12:00:00.000Z",
  "metadata": {}
}

Example request

curl -X POST https://api.codespar.dev/v1/commerce-memory/negotiations \
  -H "Authorization: Bearer $CODESPAR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
       "counterparty_id": "counterparty_0000000000000000",
       "item": "string",
       "item_ref": "string",
       "initial_price_minor": 1,
       "agreed_price_minor": 1,
       "currency": "BRL",
       "rounds": 0,
       "outcome": "agreed",
       "agent_id": "agt_0000000000000000",
       "started_at": "2026-01-15T12:00:00.000Z",
       "closed_at": "2026-01-15T12:00:00.000Z",
       "metadata": {}
     }'

GET /v1/commerce-memory/preferences

List preferences

Query parameters

NameTypeRequiredDescription
counterparty_idstringno
limitintegerno
source"explicit" | "derived" | "inherited"no

Responses

StatusBodyDescription
200objectOK
400objectinvalid_query, with the validator's issue list under details.issues.

Response 200

FieldTypeRequiredDescription
preferencesarray of objectyes

Example response

{
  "preferences": [
    {
      "id": "obj_0000000000000000",
      "counterparty_id": "counterparty_0000000000000000",
      "preference_key": "string",
      "value": "string",
      "confidence": 0,
      "source": "explicit",
      "created_at": "2026-01-15T12:00:00.000Z",
      "updated_at": "2026-01-15T12:00:00.000Z",
      "metadata": {}
    }
  ]
}

Example request

curl -X GET https://api.codespar.dev/v1/commerce-memory/preferences \
  -H "Authorization: Bearer $CODESPAR_API_KEY"

POST /v1/commerce-memory/preferences

Set or update one preference on a counterparty

Request body

FieldTypeRequiredDescription
confidencenumbernoDefaults to 1.
counterparty_idstringyes
metadataobjectno
preference_keystringyesLowercase ASCII, digits and underscore. The vocabulary is open: a new key needs no migration.
source"explicit" | "derived" | "inherited"noDefaults to explicit.
valuenoAny JSON value. Send it. The validator is unknown, which in Zod accepts a body that omits the key, but the column behind it is NOT NULL, so a body without value is not a supported call.

Responses

StatusBodyDescription
201objectCreated, or updated in place.
400objectinvalid_body, with the validator's issue list under details.issues.
404objectcounterparty_not_found: the id does not belong to this org and project.

Response 201

FieldTypeRequiredDescription
confidencenumberyes0 to 1. 1 means an operator asserted it; below that it was derived.
counterparty_idstringyes
created_atstring (date-time)yes
idstringyespref_ prefixed.
metadataobjectyes
preference_keystringyes
source"explicit" | "derived" | "inherited"yes
updated_atstring (date-time)yes
valuestring | number | boolean | array of — | object | nullyesAny JSON value. Always present.

Example response

{
  "id": "obj_0000000000000000",
  "counterparty_id": "counterparty_0000000000000000",
  "preference_key": "string",
  "value": "string",
  "confidence": 0,
  "source": "explicit",
  "created_at": "2026-01-15T12:00:00.000Z",
  "updated_at": "2026-01-15T12:00:00.000Z",
  "metadata": {}
}

Example request

curl -X POST https://api.codespar.dev/v1/commerce-memory/preferences \
  -H "Authorization: Bearer $CODESPAR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
       "counterparty_id": "counterparty_0000000000000000",
       "preference_key": "string",
       "confidence": 0,
       "source": "explicit",
       "metadata": {}
     }'
Commerce Memory | CodeSpar