CRADמפתחים
עברית

Change hours and availability blocks

Build a staff workflow that reviews appointment impact, detects concurrent changes and preserves accepted bookings.

לפני שימוש חי — בדקו יכולות פרוסות, הרשאות ומוכנות של החיבור שלכם.

בדקו את היכולות הפרוסות, הרשאות המפתח ומוכנות העסק בסביבה שלכם. דוגמאות HTTP נלכדו בבדיקות מבודדות; הסימון local-unreleased שלהן אינו אומר שה־API אינו פועל, ואינו מאשר את החיבור שלכם. במסלול הלקוח מאמתים טלפון בתבנית WhatsApp שהעסק הגדיר; SMS אינו נתמך. רישום בידי אדמין מורשה הוא פעולה נפרדת ללא קוד.

Approve management permissions on the same API key

Call these endpoints from your backend with a management credential. Weekly hours use hours:read/hours:write; blocks use blocks:read/blocks:write, with an explicit grant for business hours or named provider UUIDs. Date-specific hours use the separate business/provider booking-policy permissions below. A staff role in your website or an integration data key does not create a CRAD management grant.

Intake pause does not itself revoke management access. Hours edits affect working hours; they do not change timezone, services, team membership, bot status or booking policy.

Change business booking rules

For timezone, default slot duration, advance booking window, minimum booking/cancellation notice and business hours, use the separate booking-policy contract. It requires owner-issued booking-policy:read; preview, apply and recovery additionally require booking-policy:write. These permissions cover the whole business and do not require a provider or calendar resource grant. Existing keys gain no new authority.

bookingHorizonDays is one business-level rolling customer booking window shared by the website and WhatsApp. The default remains 14 days unless that business changes it. Read supportedValues.bookingHorizonDays for the current menu: 14, 30, 60 or 90. Read capabilities.bookingHorizonDays for customer date navigation instead of hardcoding a client window. Use the business timezone: 90 includes today +90 but excludes +91. Allow clear month navigation within that range and load availability only for the selected date; navigating months must not prefetch every day’s slots. WhatsApp uses bounded date pages.

GET /v1/management/booking-policy and retain its quoted ETag. POST /v1/management/booking-policy/previews with that If-Match and a proposal containing only the fields to change. Show the returned impact before applying it. A preview expires after five minutes and is bound to its credential, policy version, proposal and current appointment/provider impact.

Persist a UUID, the original If-Match, previewId and exact proposal before PATCH /v1/management/booking-policy. Existing appointments keep their saved absolute times and durations. Changing the timezone can change displayed local times; closing hours can leave existing appointments outside the new hours. New notice rules apply to future customer requests, including changes to existing appointments. No customers are contacted by this command.

Changing the booking window uses the same reviewed preview/apply sequence and preserves existing appointments and owner scheduling authority. Older immutable policy receipts may omit bookingHorizonDays; do not inject a historical default or rewrite an accepted receipt. A new window does not resolve an uncertain booking command: recover that command with its original UUID and preconditions before preparing another request.

After a timeout, recover /v1/management/booking-policy-operations/{operationId} or retry the exact original command. A not_found result does not prove a delayed request cannot still commit. The receipt records the accepted change; current is a separate fresh view. Keep the same integration and both policy scopes for recovery. Refresh and review conflicts without silently replacing a newer draft.

A known POLICY_CHANGED (412), IMPACT_CHANGED, PREVIEW_EXPIRED or PREVIEW_MISMATCH (409) refusal requires a fresh read and reviewed preview. A timeout or OUTCOME_UNCERTAIN (503) instead requires original-operation recovery first. Key rotation cannot reuse an unaccepted preview tied to the old key, but a currently authorized replacement key for the same integration can recover or replay an already accepted operation, even after preview expiry.

Future appointment-duration rewrites are not exposed by this booking-policy endpoint. Use the separate duration-policy workflow below for an explicit rewrite or provider duration inheritance. The policy read requires no WhatsApp connection or active public booking page.

Review duration changes and preserve booked terms

Use /v1/management/duration-policy for the business or /v1/management/duration-policy/providers/{providerId} for one provider. Business changes require booking-policy:read/write. Provider changes require provider-booking-policy:read/write and that provider UUID in the key’s providerIds; businessSchedule alone is insufficient. Read-only calls need only the corresponding read scope.

Read the current ETag, then POST to the resource’s /previews with If-Match and {proposal}. Provider proposals contain openingHours and/or slotDurationMinutes; null restores inheritance and an explicit value equal to the business value remains an override. The provider version also binds its parent policy. Business proposals support the same fields as booking-policy.

Review the separate rewritable, conflict, protected and unchanged counts. The review examines at most 10,000 future appointments and 10,000 future blocks. A larger set is refused explicitly. A preview expires after five minutes and is bound to the key, proposal, policy and reviewed impact.

Persist an operation UUID and the exact {previewId, proposal, mode} before PATCH with the original If-Match and Idempotency-Key. keep_existing preserves all appointment times. rewrite_eligible additionally requires booking-duration:rewrite and atomically updates at most 1,000 reviewed eligible legacy end times. Starts, booked price/duration snapshots and protected overrides stay unchanged. Conflicting appointments are counted and retained; no partial command is reported as saved. Neither mode sends customer messages.

Recover uncertainty with /v1/management/duration-policy-operations/{operationId}; not_found does not cancel a delayed command. Current authority for the original business/provider resource and mode is still required, including rewrite scope for a rewrite receipt. A rotated key for the same integration can recover an accepted operation but cannot reuse an unaccepted preview bound to the previous key. A retained draft must use the accepted receipt version, not a later unseen current version.

Change one date without changing the recurring week

Discover date-hours support by sending X-CRAD-Capabilities: day-schedule-overrides only on GET /v1/management. The exact case-sensitive value requests the optional capabilities.dayScheduleOverrides field; an absent header or another value, including a comma-separated list, leaves the field omitted. Require dayScheduleOverrides:true before enabling date edits. If the flag is absent or false, keep the existing weekly-hours display read-only and date controls unavailable. This negotiation does not change authentication, grant scopes or resource access, or establish deployment by itself.

Use /v1/management/schedules/{resource}/dates, where resource is business or an explicitly granted provider UUID. The discovery header is not required on these date routes; their authorization checks remain unchanged. A date override can open, extend, shorten or close one day. A time block only subtracts availability; changing date hours does not remove a block or alter existing appointments.

Business reads require booking-policy:read, with booking-policy:write additionally required for preview, apply and accepted-operation recovery. Provider calls require the corresponding provider-booking-policy:read/write scopes and the exact provider grant. hours:* and businessSchedule alone do not grant these permissions. Keep the key on your backend and omit Origin.

GET the collection with inclusive from/to civil dates, at most 93 dates, or GET /dates/{date} for the day and its quoted ds:<hash> ETag. Use the returned business timezone for YYYY-MM-DD dates and HH:mm hours. dayHours is effective, weeklyHours is the recurring fallback, and overridden describes an override on this exact resource/date. An inheriting provider can use a business date override while its own overridden is false.

Precedence is provider date override, explicit provider weekly hours, business date override, then business weekly hours. An explicit provider week, including a closed or missing weekday, takes precedence over a business date override. A business-wide block can close every resource regardless of its hours. Existing business/provider blocks, notice, duration and capacity still apply: use canonical availability and final booking admission.

POST /dates/{date}/change-previews with the exact If-Match and {dayHours}. Supply one complete enabled day with open/close and optional non-overlapping breaks, {enabled:false} to close it, or null to remove only this resource/date exception. Reset restores the precedence above, which may include a business date override. Review normalized dayHours, effectiveDayHours, affected appointment IDs/times, affectedCount and expiresAt. Overnight hours are unsupported.

Persist the original resource/date, UUID, If-Match and {previewId} before PATCH /dates/{date}; send the UUID as Idempotency-Key and only previewId in the body. Known version, impact or expiry conflicts need a fresh read and reviewed preview. Existing appointments remain saved, and no customer message is sent.

After uncertainty, recover GET /v1/management/operations/{operationId} or repeat the exact PATCH. A found date operation returns status:committed, its immutable date_schedule receipt, a separate current state and replayed:true. Current may reflect a later edit; the receipt proves only the accepted operation. not_found does not fence a delayed command. Retain the original UUID/body/ETag and current policy/resource authority after key rotation.

Read, preview, review and commit

The impact projection supplies IDs, versions and times, not customer details or business-wide appointment management. Arrange any necessary customer follow-up through the business’s authorized appointment tools; closing hours does not contact, cancel or reschedule affected customers.

  1. Read the current resource

    GET schedules/business or schedules/{providerId}. Keep the returned strong ETag, such as "b1" or "b1:p2". Provider versions include the business version so a parent-hours change is detected.

    Retrieve working hours
  2. Prepare a complete proposal

    An override contains all seven weekdays. Enabled days need opening and closing times; breaks must fit within those hours and not overlap. Overnight hours are unsupported. Only provider schedules can inherit; send mode: inherit without hours for that choice.

    Preview a schedule change
  3. Review impact

    POST the proposal to change-previews using the current If-Match. Show affectedCount, the appointment times and expiry. Existing appointments remain saved even when the proposal closes their working day. An impact appointmentId is not a public bookingId or permission to read/change a customer booking.

  4. Commit the reviewed preview

    Persist a commit UUID, previewId and exact If-Match before PATCH. Send only the previewId body. If the schedule version or appointment impact changed, fetch a new preview and require another review.

    Update working hours
  5. Refresh current state

    Use the receipt to establish the operation result, then read the current resource for the editor. A recovered immutable receipt can precede another administrator’s subsequent edit.

    Recover an accepted management receiptRetrieve working hours

Read business and provider blocks separately

Resource selection is exclusive. Omitting providerId returns business-wide blocks only and requires the business-schedule grant. Supplying a granted providerId returns only that provider’s blocks; it excludes business-wide blocks.

For an effective provider calendar, combine both authorized lists over the same period. Paginate each list independently: keep separate cursor state and do not reuse a cursor for the other query. A denied resource is unknown, not empty. Use the availability API and authoritative booking result to determine whether a slot can be reserved.

Run the following reads on your backend only when both resources are granted. Replace the API base, dates and provider UUID with your issued or current values. Each response has its own continuation cursor.

Two independent resource reads · cURL
curl --get "https://api.crad.ai/v1/management/blocks" \
  --header "Authorization: Bearer ${CRAD_API_KEY}" \
  --data-urlencode "from=${FROM}" \
  --data-urlencode "to=${TO}"

curl --get "https://api.crad.ai/v1/management/blocks" \
  --header "Authorization: Bearer ${CRAD_API_KEY}" \
  --data-urlencode "from=${FROM}" \
  --data-urlencode "to=${TO}" \
  --data-urlencode "providerId=${PROVIDER_ID}"

Create, update or release a block

Ordinary block writes are limited to this integration’s blocks. Editing another origin’s block needs blocks:write:any as well as the resource grant. A block cannot be moved to another resource with PATCH; use separately reviewed release and create operations.

The block list accepts a positive half-open UTC-instant range [from,to) of at most 31 elapsed days (31 × 24 hours), with 100 records per page. Reasons belonging to another origin can be hidden. A business-local calendar month is not always within that limit: October 2026 in Asia/Jerusalem spans 31 elapsed days plus one hour because the offset changes.

Convert the business-local start and exclusive end to UTC, then split oversized ranges into consecutive windows no longer than 31 * 24 * 60 * 60 * 1000 milliseconds. Keep the exact original endpoints, including any final daylight-saving hour. Start each window and each resource without a cursor; exhaust nextCursor only within that same window/resource. Combine business-wide and provider blocks only when both resources are granted. Deduplicate overlapping results by blockId and retain the latest version; do not drop distinct blocks or reuse a cursor across windows/resources.

This live pagination is not an atomic snapshot or synchronization feed. Re-read to resolve concurrent edits. The appointment directory has a separate 93-elapsed-day UTC range limit; date-hours GET uses at most 93 inclusive business-local civil dates. Initial loading and refresh after tab focus must respect each endpoint’s own range and cursor rules.

  1. Select the exact resource and action

    For create or update, use localDate for an all-day block, or explicit-offset startAt/endAt for an interval. Do not send both forms. The server maps an all-day date to local midnight through the next local midnight, including 23/25-hour daylight-saving days. Release sends no period.

    List availability blocks
  2. Preview the change

    POST block-change-previews with one complete action body below. Update requires a complete replacement period, not a partial patch. Update and release require the existing blockId and current numeric expectedVersion. Review the normalized proposal and appointment impact.

    Preview a block change
  3. Apply that preview

    Persist an operation UUID and the exact commit body containing only previewId. Create through POST blocks; update through PATCH blocks/{id}; release through POST blocks/{id}/release. Update/release require If-Match: "vN". The route, ID, action and version must match the preview.

    Create a blockUpdate a blockRelease a block

Choose one complete preview body

These are illustrative request bodies, not recorded transactions or ready-to-send commands. Replace the example date, interval, block UUID and version with the intended period and current read results. Send exactly one object to POST block-change-previews. The later commit sends only its returned previewId.

Create omits blockId and expectedVersion. Update replaces the full period. Release accepts no period or reason. Optional providerId on update or release must match the block’s existing resource; omitting it does not move the block.

Update replaces the reason too. Include reason to retain or change it; omitting reason clears the previous text. Read the current value and decide deliberately before requesting the preview.

Create · business all-day preview · JSON
{
  "action": "create",
  "localDate": "2026-11-15",
  "reason": "Closed for maintenance"
}
Update · replace an existing block’s interval · JSON
{
  "action": "update",
  "blockId": "00000000-0000-4000-8000-000000000001",
  "expectedVersion": 2,
  "startAt": "2026-11-15T09:00:00+02:00",
  "endAt": "2026-11-15T12:00:00+02:00",
  "reason": "Closed for maintenance"
}
Release · existing block · JSON
{
  "action": "release",
  "blockId": "00000000-0000-4000-8000-000000000001",
  "expectedVersion": 3
}

Handle conflicts without bypassing review

These are workflow-specific cases, not an exhaustive runtime error list. Resolve any earlier uncertain attempt before starting a different reviewed change.

ResponseMeaningAction
412 VERSION_CONFLICTThe acknowledged resource version is no longer current.Read the resource again, rebuild the proposal and show a fresh preview.
409 IMPACT_CHANGEDAppointment impact changed after the preview.Generate a new preview and ask the staff member to review it.
409 PREVIEW_EXPIREDThe preview is missing, mismatched or expired.Create a fresh preview from current state.
409 OPERATION_CONFLICTThe UUID or preview does not match the submitted command.Recover the original operation and inspect the saved route, body and preconditions. Do not alter a pending retry.
428 PRECONDITION_REQUIRED / 422 INVALID_PRECONDITIONA required key or strong version header is missing or malformed.Use the exact returned quoted version; weak validators and * are invalid.
422 INVALID_SCHEDULE / OVERNIGHT_SCHEDULE_UNSUPPORTED / INVALID_BLOCKThe proposed hours or block is unsupported.Correct the form before requesting a new preview.
Timeout, 503, or operation status not_foundA write result is unresolved; not_found alone does not fence an in-flight attempt.Keep the original UUID/body/If-Match. Recover through management operations or repeat the exact commit; do not start a replacement merely to retry.
401/403Current authority is missing or denied.Restore legitimate authority. Recovery after rotation still requires the original action and resource grants.