Using the Admin API with Locks
Important: Locksmith support cannot help write or troubleshoot these requests for you. However, if there is anything unclear in our documentation, please feel free to contact us with questions.
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 APIBody 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.
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.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
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
200Success - the response body will contain the json representation of the newly created lock400Error - Post payload incorrectly formed404Error - Post URL incorrectly formed
Creating locks using invalid input may occasionally create malfunctioning locks. It is important that you test your storefront and delete any locks that aren't working as expected.
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_idendpoint 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/resourcesAttaches a resource to the lock. Body: an object withresource_type,resource_id, and optionalresource_options.PATCH/locks/:lock_id/resources/:lock_resource_idUpdates an attached resource.DELETE/locks/:lock_id/resources/:lock_resource_idDetaches 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?