ByRecordDocs
byrecord.com›

Connecting a CRM

Turn a Salesforce opportunity into a quote, find an opportunity's quotes again, and write each deal's progress back to it from webhooks.

Every quote made through the partner API belongs to a CRM opportunity. Salesforce is the supported format: your integration sends the opportunity's link with the quote, every quote and every webhook carries it back, and quotes can be looked up by it.

opportunityUrl is required on POST /quotes. It must be a Salesforce opportunity link:

  • https, on a Salesforce host: *.lightning.force.com, *.my.salesforce.com or *.salesforce.com. A programme may accept links from its own Salesforce org only.
  • In Lightning form (/lightning/r/Opportunity/006…/view) or Classic form (/006…).
  • Naming an opportunity record: a 15- or 18-character id starting 006. A link to a lead, an account or a report is refused with 400.

The platform matches on the opportunity id, not the URL: on its first 15 characters, which are the same in the 15- and 18-character forms. Quotes and webhooks carry both the link as you sent it and that id:

JSON

A worked flow

  1. The opportunity is ready to quote. Your integration builds the request from it (below), generates an Idempotency-Key, stores the key on the opportunity, then calls POST /quotes.
  2. Store what comes back on the opportunity: the quote's id (quo_…) and number, and on the CRM account, the account's id (acc_…). Show needsReview and warnings to the account executive: a quote with lines needing review cannot be sent until someone resolves them in the platform.
  3. Send it with POST /quotes/:id/send when it is right. The account executive can send it from the platform or the Slack app instead.
  4. Follow it from webhooks, writing each moment back to the opportunity (below).
  5. Reconcile from time to time with GET /quotes?opportunityUrl=, which also finds quotes made for the opportunity in the platform or from Slack.

Building the request from the opportunity

A typical mapping:

Request fieldFrom
opportunityUrlThe opportunity's own link. Required
ownerEmailThe opportunity owner's email. They must be an active sales user in the platform; if not, the quote is created unowned and warnings says so
customer.accountIdThe acc_… stored on the CRM account from an earlier quote, to quote an existing customer
customer.name, legalName, email, phone, addressThe CRM account, for a new customer. Send the full service address: where the programme calculates sales tax, a quote without one cannot be sent
customer.contactThe person who receives the proposal and signs, such as the opportunity's primary contact. Required
currencyThe opportunity's currency: usd or cad
linesThe opportunity's products, each by your product code as supplierCode, with its quantity
termMonths, billingStarts, startDateThe deal's terms, if your opportunity records them
Configuration fieldsWhatever the programme's catalogue prices its subscription by

Every field is on Quotes.

  • Send codes and quantities, not prices. Every line is priced from the programme's catalogue. The one price a request can carry, agreedUnitPrice, can only lower a recurring line.
  • Reuse the account. There is no API to list or search accounts. The acc_… comes back on every quote (account.id) and every webhook (data.accountId): store it on the CRM account the first time, and send it as customer.accountId for the customer's next quote.

Retries and idempotency

A CRM's outbound calls are retried: after a timeout, a worker restart, a second click. Make each one safe to repeat.

  • One key per intended quote. Generate the Idempotency-Key once, when the integration decides to create the quote, and store it on the opportunity before the first call. Every retry sends the same key with the same body.
  • A retry gets the first answer. With the same key and body, the stored answer comes back with Idempotent-Replayed: true. Once a quote exists, a retry answers 201 with that quote, never a second one.
  • Do not derive the key from the opportunity alone. A second, deliberate quote for the same opportunity would then replay the first answer, or be refused with 422 if its body differs. Each new quote gets a new key.
  • A key lasts seven days. For a retry later than that, look first: GET /quotes?opportunityUrl= shows whether the quote was made.
  • 409 means the first request with that key is still being processed. Wait, then retry with the same key.
  • Send takes a key too. A retried POST /quotes/:id/send with the same key replays the first answer rather than emailing the customer again.

See Idempotency for exactly what is stored and replayed.

Finding an opportunity's quotes

Bash
  • The answer is { "data": [ … ] }, newest first, each a full quote.
  • Matched on the opportunity id, so a Classic link finds quotes created from a Lightning one.
  • limit is 50 by default, and at most 200.
  • An opportunity can have several quotes: a deal quoted again, or re-quoted after one expired. A quote can also have several versions: version goes up when a sent quote is revised in the platform, and the customer's link always opens the latest.

Writing progress back

Every webhook carries the deal's opportunity, so writing back needs no lookup on our side.

  1. Verify the signature and answer 2xx within 10 seconds. Update the CRM after answering, not before.
  2. De-duplicate on the event id.
  3. Find the opportunity by data.opportunityId, or by the data.quoteId you stored.
  4. Apply the moment. A typical mapping:
EventOn the opportunity
quote.viewedThe proposal was opened. Sent once per quote version
quote.acceptedAccepted, by acceptedName (acceptedEmail). Store data.contractId
contract.signedThe agreement is signed
payment_method.savedA payment method is on file
installation.recordedInstalled, with service from serviceStartDate
billing.liveBilling: the first invoice went out
  1. Never move an opportunity backwards. Deliveries can arrive out of order: order the moments by each event's createdAt, and keep the furthest one reached.

Service events (service.suspended, service.restored, service.reversed) are about the customer's service, not one deal, and can happen many times. Record them on the CRM account found by data.accountId, once per data.occurrenceId. See Service events.

Every event's fields, and more on handling them, are on Webhook events.

Verifying in Apex

If your receiver runs in Salesforce, the same check is a few lines of Apex. t and v1 come from the X-ByRecord-Signature header, and rawBody is the request body exactly as received:

JAVA
Blob mac = Crypto.generateMac('hmacSHA256', Blob.valueOf(t + '.' + rawBody), Blob.valueOf(secret));
Boolean signatureOk = EncodingUtil.convertToHex(mac).equals(v1);
Boolean fresh = Math.abs(Datetime.now().getTime() / 1000 - Long.valueOf(t)) <= 300;

Accept the delivery only when both hold. The full method is on Verifying the signature.

Keys for a CRM

  • A key of its own. Create one key for the integration, named for it, with See quotes and Make and send quotes. A reporting job that only reads gets its own key with See quotes alone. Keys are made on API & webhooks by the vendor's finance team or ByRecord's admins; see Authentication and keys.
  • 60 requests a minute per key. A reconcile over many opportunities should pace itself; see Rate limits.
  • Build it in the sandbox first. Sandbox keys and endpoints are separate from production's; see Sandbox and testing.
© 2026 ByRecord · byrecord.com · Status