Skip to Content
Lock API

Lock API

The Synchronize Lock API provides distributed lock management capabilities. This API allows you to acquire, release, and query locks across distributed systems.

Base URL

https://www.synchronize.dev/api

Authentication

All endpoints (except anonymous user creation) require Bearer token authentication.

Authorization: Bearer <your-api-key>

Endpoints

Create Anonymous User

Creates an anonymous user and returns an API key for authentication.

Endpoint: POST /v0/users/anonymous

Note: This endpoint does not require authentication.

Response: 200 OK

{ "userId": "string", "apiKey": "uuid" }
FieldTypeRequiredDescription
userIdstringYesThe unique identifier for the created user
apiKeystring (uuid)YesThe API key to use for authentication

Example:

curl -X POST https://www.synchronize.dev/api/v0/users/anonymous

Create a Lock

Acquires a lock on a specific resource identifier.

Endpoint: POST /v0/lock

Request Body:

{ "lockName": "string", "requester": "string" }
FieldTypeRequiredDescription
lockNamestringYesThe name/identifier of the lock to acquire
requesterstringYesIdentifier of the entity requesting the lock

Response: 200 OK

{ "locked": true, "leaseId": "uuid", "message": "string" }
FieldTypeRequiredDescription
lockedbooleanYesWhether the lock was successfully acquired
leaseIdstring (uuid)NoUnique identifier for this lock lease (returned if locked is true)
messagestringNoAdditional information about the lock attempt

Example:

curl -X POST https://www.synchronize.dev/api/v0/lock \ -H "Content-Type: application/json" \ -H "Authorization: Bearer <your-api-key>" \ -d '{ "lockName": "resource-123", "requester": "service-a" }'

Get Lock Information

Retrieves information about a specific lock.

Endpoint: GET /v0/lock

Query Parameters:

ParameterTypeRequiredDescription
lockNamestringYesThe name/identifier of the lock to query

Response: 200 OK

{ "lockName": "string", "locked": true, "leaseId": "uuid", "leasedBy": "string", "createdAt": "string", "updatedAt": "string" }
FieldTypeRequiredDescription
lockNamestringYesThe name/identifier of the lock
lockedbooleanYesWhether the lock is currently held
leaseIdstring (uuid)YesThe current lease identifier
leasedBystringYesIdentifier of the entity holding the lock
createdAtstringNoTimestamp when the lock was created
updatedAtstringNoTimestamp when the lock was last updated

Example:

curl -X GET "https://www.synchronize.dev/api/v0/lock?lockName=resource-123" \ -H "Authorization: Bearer <your-api-key>"

Unlock a Resource

Releases a previously acquired lock.

Endpoint: POST /v0/unlock

Request Body:

{ "lockName": "string", "leaseId": "string" }
FieldTypeRequiredDescription
lockNamestringYesThe name/identifier of the lock to release
leaseIdstringYesThe lease identifier obtained when the lock was acquired

Response: 200 OK

{ "unlocked": true }
FieldTypeDescription
unlockedbooleanWhether the lock was successfully released

Response: 404 Not Found

Lock identifier not found.

Example:

curl -X POST https://www.synchronize.dev/api/v0/unlock \ -H "Content-Type: application/json" \ -H "Authorization: Bearer <your-api-key>" \ -d '{ "lockName": "resource-123", "leaseId": "550e8400-e29b-41d4-a716-446655440000" }'

Get All Locks

Retrieves all locks for the authenticated user.

Endpoint: GET /v0/locks

Response: 200 OK

{ "locks": [ { "lockName": "string", "locked": true, "leaseId": "uuid", "leasedBy": "string", "createdAt": "string", "updatedAt": "string" } ] }
FieldTypeDescription
locksarrayArray of lock objects (same structure as Get Lock Information response)

Example:

curl -X GET https://www.synchronize.dev/api/v0/locks \ -H "Authorization: Bearer <your-api-key>"

Common Use Cases

Acquiring a Lock

  1. Create an anonymous user if you don’t have an API key
  2. Use the API key to authenticate
  3. Call the create lock endpoint with your lock name and requester identifier
  4. If successful, store the leaseId for later use

Releasing a Lock

  1. Call the unlock endpoint with the lock name and lease ID
  2. Verify the unlock was successful

Checking Lock Status

  1. Call the get lock information endpoint with the lock name
  2. Check the locked field to see if the lock is currently held
  3. Review leasedBy to see who holds the lock

Error Handling

  • 401 Unauthorized: Missing or invalid API key
  • 404 Not Found: Lock identifier not found (unlock endpoint)
  • 200 OK with locked: false: Lock acquisition failed because another entity holds the lock
Last updated on