For the complete documentation index, see llms.txt. This page is also available as Markdown.

Using the Admin API with Locks

Locks can be created via our Admin API using the following endpoint:

POST /lock

This guide covers information specific to creating locks. See our general Admin API guide for more general information on forming these requests (including headers and authentication):

Locksmith Admin API

Body Parameters

A lock can protect one or more resources of the same type. Set the lock's type with the top-level resource_type, and list the resources it protects in the resources array — each entry an object with its own resource_type, resource_id, and optional resource_options. Every resource on a lock must be the same type (the three collection flavors — manual custom_collection, automated smart_collection, and the all-products liquid:collection-all — count as one type and can be combined).

A shop lock is the exception: pass resource_type: "shop" with no resources array, since it protects the entire storefront.

After creation, a lock's resources can also be managed individually using the dedicated resource endpoints (see Managing a lock's resources below).

Note that resource_type and keys are required. If left blank, the rest will use their defaults as noted.

Parameter
Type
Description
Required

resource_type

string

The lock's resource type — product, custom_collection, smart_collection, page, blog, or shop. Determines how the lock is enforced; every entry in resources must be this same type. Other types of locks unsupported.

Required

resources

array

The resources this lock protects. Each entry is an object with resource_type, resource_id, and an optional resource_options object. The resource_id is the Shopify resource ID, found at the end of the resource URL in your Shopify Admin. All entries must be the same type as the lock. Omit for a shop lock. Note: a resource can belong to only one lock. Attaching one that's already locked elsewhere is rejected — to add a resource to an existing lock, use the resource endpoints below rather than re-posting.

Required, except for shop locks

name

string

An optional, human-friendly label for the lock, shown in the lock list. Has no effect on what the lock protects.

Optional Default: none

keys

array

List of key definitions that grant access; can be an empty array on creation.

Required

enabled

boolean

Whether the lock is active.

Optional Default: true

options

object

Lock behavior options. See below.

Optional

options.hide_links_to_resource

boolean

Hide navigation links pointing to the resource on storefront. See documentation.

Optional Default: false

options.hide_resource

boolean

Hide the resource from product grids. See documentation.

Optional

Default: false

options.hide_resource_from_sitemaps

boolean

Remove resource from sitemap generation. See documentation.

Optional

Default: false

options.manual

boolean

Indicates a manual lock. See documentation.

Optional Default: false

options.noindex

boolean

Add noindex meta tag to the storefreont rendering to prevent search engine indexing. See documentation.

Optional Default: true

Optional query parameters

Add these to the end of the /lock endpoint. For example:

https://uselocksmith.com/api/unstable/lock?dryrun=true

Name
Type
Description
Extra info

install

boolean

If true, a theme install on your published theme is performed (if request is successful).

Recommended unless you are manually triggering an install later! See POST /install endpoint.

dryrun

boolean

If true, changes are not persisted, but a success/error response is still returned.

Useful for testing/debugging.

Keys

Locksmith has a large variety of key conditions types and their corresponding options. The easiest way to create a valid key config is doing it right inside the Locksmith app on a lock page. Once created, the key config can be copy-pasted directly from the Locksmith app:

If using multiple keys, make sure to create a valid JSON array and use it as the "keys" parameter in your request. Once you've created valid key configs, you can reuse them wherever you are using this API. Check the examples below.

Responses

  • 200 Success - the response body will contain the json representation of the newly created lock

  • 400 Error - Post payload incorrectly formed

  • 404 Error - Post URL incorrectly formed

Notes

  • On success, the returned json object will contain fields you did not explicitly add. Note that fields prefixed with _ are automatically generated by the backend and should not be included in request bodies.

  • After creation, you can use the GET /locks/:lock_id endpoint to verify.

Example cURL requests

Managing a lock's resources

Once a lock exists, you can attach, update, or detach individual resources without re-posting the whole lock. Every resource on a lock must be the same type (the three collection flavors — manual custom_collection, automated smart_collection, and the all-products liquid:collection-all — count as one type and can be combined). A resource can belong to only one lock; attaching one that's already locked elsewhere is rejected.

  • POST /locks/:lock_id/resources Attaches a resource to the lock. Body: an object with resource_type, resource_id, and optional resource_options.

  • PATCH /locks/:lock_id/resources/:lock_resource_id Updates an attached resource.

  • DELETE /locks/:lock_id/resources/:lock_resource_id Detaches a resource from the lock. A lock with no resources is inactive (its keys are preserved) until one is re-added.

Last updated

Was this helpful?