← Back to Blog
UnlockLater APIscheduled credential sharingAPI automationcredential handoffcontractor onboardingemail OTPbusiness workflows

How to Share Credentials at a Scheduled Time Using an API

A new contractor starts Monday. A support engineer takes over at the beginning of an on-call shift. A vendor needs a temporary staging key during a planned maintenance window. In each case, the credential should arrive when the work begins—not days earlier in a chat thread or email draft.

An API can make that handoff part of the business workflow that already knows the date, recipient, and task. The important detail is when the API call runs.

Schedule the handoff, not an early credential link

The UnlockLater credential endpoint creates a share that is available as soon as it is created, subject to the recipient and verification settings. Its visibilityDays field controls how long the share remains available after creation; it is not a future reveal date.

So if a credential must not be available before a scheduled time, have your own scheduler call the API at that time. Use a durable job queue or your organization’s scheduled-workflow service, rather than an in-memory timer that could be lost when an application restarts.

This differs from the text-message endpoint, which accepts a future revealAt timestamp. The credential endpoint does not currently accept revealAt.

Example: contractor access begins on Monday

Suppose an onboarding system already knows a contractor’s start time and recipient email. When the start time arrives, its scheduled worker can create a short-lived API-key share:

export async function createContractorHandoff(handoff) {
  const unlockLaterKey = process.env.UNLOCKLATER_API_KEY;
  const unlockLaterBaseUrl = process.env.UNLOCKLATER_BASE_URL;
  const stagingApiKey = process.env.STAGING_API_KEY;

  if (!unlockLaterKey || !unlockLaterBaseUrl || !stagingApiKey) {
    throw new Error("Credential handoff configuration is incomplete.");
  }

  const response = await fetch(
    new URL("/api/v1/messages/credentials", unlockLaterBaseUrl),
    {
      method: "POST",
      headers: {
        Authorization: `Bearer ${unlockLaterKey}`,
        "Content-Type": "application/json",
        // Keep this stable for every retry of the same scheduled handoff.
        "Idempotency-Key": `contractor-onboarding-${handoff.id}`,
      },
      body: JSON.stringify({
        credentialType: "api_key",
        title: "Temporary staging key",
        secret: stagingApiKey,
        recipientEmail: handoff.recipientEmail,
        visibilityDays: 2,
        burnAfterReading: true,
      }),
    },
  );

  const result = await response.json();
  if (!response.ok) {
    throw new Error(
      `Credential handoff failed (${response.status}): ${result.error?.code ?? "UNKNOWN"}`,
    );
  }

  // Store the returned link only in a restricted handoff record.
  return { id: result.id, url: result.url, expiresAt: result.expiresAt };
}

In production, load the credential from your secrets manager when the scheduled worker runs. Do not place the API key or the credential value in browser code, a job description, a source repository, or routine logs. The job should carry a reference to the secret, not the secret itself.

When the worker creates the share with a recipient email, email verification is enabled by default. UnlockLater sends an invitation; the recipient verifies access to that inbox before the credential is revealed. The two-day visibility period begins when the scheduled worker creates the share. burnAfterReading can make the share unavailable after the first successful credential retrieval.

Make retries safe

Scheduled jobs can run more than once: a worker may time out after sending the request but before recording success. Send the same Idempotency-Key when retrying the same handoff, and keep the request body unchanged. That lets the API return the original result rather than creating another share.

Use a different stable key for each handoff. For example, use the onboarding record’s identifier—not a newly generated random value on each attempt. If the recipient, credential, or other request details change, treat that as a new handoff with its own identifier and review the existing share before creating another one.

If an invitation email cannot be sent, the API reports a delivery error instead of treating the handoff as complete. Let the job retry according to your queue’s policy, and alert an operator if retries are exhausted. Avoid logging request bodies or returned share links in general-purpose job logs.

Set the schedule and access window carefully

To make the handoff dependable:

  1. Save the intended time with a time zone. Convert it to an unambiguous timestamp for your scheduler. Account for daylight-saving changes if the business schedule is expressed as local time.
  2. Run the job at the handoff time. Do not create the credential share days early if it must not be available early.
  3. Choose a short visibility period. visibilityDays accepts a whole number from 1 to 365. Set it to cover the actual task, not the contractor’s entire engagement by default.
  4. Verify the recipient address. With recipientEmail supplied, the recipient receives an invitation and must verify that inbox before reveal.
  5. Use narrowly scoped credentials. Create a staging or task-specific key when possible, with only the permissions the work requires.
  6. Plan to revoke or rotate at the source. Expiring or revoking a share does not invalidate a credential that has already been revealed.

If the exact time must control when the secret becomes viewable, schedule the credential-creation request for that moment. Do not rely on visibilityDays to delay access: it sets an expiration window, not a start time.

Other business handoffs that benefit from scheduling

The same pattern can support a planned maintenance window, a vendor’s first day, a shift change, or a time-limited incident response. Your system schedules a job with the intended recipient and a secure reference to the credential; the worker creates the share only when the handoff should begin.

For application-to-application secrets that need ongoing access control, prefer an organization-managed secrets manager with scoped permissions, audit history, and rotation. A scheduled share is best for a deliberate, temporary transfer to a person—not as a replacement for runtime secret distribution.

Get started with the UnlockLater API

The credential endpoint is available to accounts with an active Pro subscription and uses the same message allowance as website-created items. Keep API keys on your server, use idempotency keys for scheduled-job retries, and restrict access to the system that stores each returned share link.

Create or revoke keys from the API access page, then review the authenticated API documentation. For a manually created share, see the credential-sharing guide.

When the schedule is already in your business system, a server-side job can turn that date into a controlled handoff—without putting the credential in an advance message.