# Using the Admin API with Locks

{% hint style="warning" %}
**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.
{% endhint %}

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

<mark style="color:green;">`POST`</mark> `/lock`&#x20;

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):

{% content-ref url="../developer-tools/locksmith-admin-api" %}
[locksmith-admin-api](https://www.locksmith.guide/developer-tools/locksmith-admin-api)
{% endcontent-ref %}

## Body Parameters

Note that only the top 3 parameters are required. If left blank, the rest will use their defaults as noted.

| Parameter                             | Type    | Description                                                                                                                                                                                         | Required                                                                                                                                                                                                                                                                                                 |
| ------------------------------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `resource_id`                         | integer | Shopify resource ID. This number can be found at the end of the resource URL in your **Shopify Admin.**                                                                                             | <p><mark style="color:red;">Required</mark>. Unless creating a shop lock, in which case it can be left out.<br><br><strong>Warning</strong>: Each resource can only have one lock. Using a resource\_id for a lock that already exists will overwrite the previous lock and can result in data loss.</p> |
| `resource_type`                       | string  | Required. Type of resource - `product`, `custom_collection`, `smart_collection` `page`, `blog` , or `shop` . Other types of locks unsupported.                                                      | <mark style="color:red;">Required</mark>                                                                                                                                                                                                                                                                 |
| `keys`                                | array   | List of key definitions that grant access; can be an empty array on creation.                                                                                                                       | <mark style="color:red;">Required</mark>                                                                                                                                                                                                                                                                 |
| `enabled`                             | boolean | Whether the lock is active.                                                                                                                                                                         | <p>Optional<br>Default: true</p>                                                                                                                                                                                                                                                                         |
| `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](https://www.locksmith.guide/tutorials/more/hiding-navigation-links-for-locked-resources).                         | <p>Optional<br>Default: false</p>                                                                                                                                                                                                                                                                        |
| `options.hide_resource`               | boolean | Hide the resource from product grids. [See documentation](https://www.locksmith.guide/tutorials/more/hiding-products-and-other-content-from-lists-in-your-online-store).                            | <p>Optional</p><p>Default: false</p>                                                                                                                                                                                                                                                                     |
| `options.hide_resource_from_sitemaps` | boolean | Remove resource from sitemap generation. [See documentation](https://www.locksmith.guide/tutorials/more/automatically-hide-from-sitemaps-and-manage-seo-metafield).                                 | <p>Optional</p><p>Default: false</p>                                                                                                                                                                                                                                                                     |
| `options.manual`                      | boolean | Indicates a manual lock. [See documentation.](https://www.locksmith.guide/tutorials/more/manual-mode)                                                                                               | <p>Optional<br>Default: false</p>                                                                                                                                                                                                                                                                        |
| `options.noindex`                     | boolean | Add `noindex` meta tag to the storefreont rendering to prevent search engine indexing. [See documentation](https://www.locksmith.guide/faqs/more/how-does-locksmith-affect-search-engines-and-seo). | <p>Optional<br>Default: true</p>                                                                                                                                                                                                                                                                         |

## 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:

<figure><img src="https://277214568-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MUeGWHuijBPr8Og1Gta%2Fuploads%2FoottlVnlMjtMXpwACwb9%2FScreenshot%202025-05-07%20at%2015.01.50.png?alt=media&#x26;token=faf7988a-3849-4d07-b591-c5a057fefc7d" alt=""><figcaption></figcaption></figure>

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

{% hint style="danger" %}
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.
{% endhint %}

## 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

```bash
# Create a minimal product-level lock with required fields only
curl -X POST https://uselocksmith.com/api/unstable/lock \
  -H "x-shopify-shop-domain: example-store.myshopify.com" \
  -H "x-locksmith-access-token: abcd1234" \
  -H "Content-Type: application/json" \
  -d '{
    "resource_id": 1234567890,
    "resource_type": "product",
    "keys": []
  }'
```

```bash
# Create a shop-level lock that applies to the entire storefront
curl -X POST https://uselocksmith.com/api/unstable/lock \
  -H "x-shopify-shop-domain: example-store.myshopify.com" \
  -H "x-locksmith-access-token: abcd1234" \
  -H "Content-Type: application/json" \
  -d '{
    "resource_type": "shop",
    "keys": []
  }'
```

```bash
# Create a product-level lock. Optional parameters included. without keys.
curl -X POST https://uselocksmith.com/api/unstable/lock \
  -H "x-shopify-shop-domain: example-store.myshopify.com" \
  -H "x-locksmith-access-token: abcd1234" \
  -H "Content-Type: application/json" \
  -d '{
    "resource_id": 1234567890,
    "resource_type": "product",
    "enabled": true,
    "options": {
      "hide_links_to_resource": true,
      "hide_resource": true,
      "hide_resource_from_sitemaps": true,
      "manual": false,
      "noindex": true
    },
    "keys": []
  }'
```

```bash
# minimal product level lock. WITH keys
curl -X POST "https://uselocksmith.com/api/unstable/lock" \
  -H "x-shopify-shop-domain: example-store.myshopify.com" \
  -H "x-locksmith-access-token: abcd1234" \
  -H "Content-Type: application/json" \
  -d '{
    "resource_id": 1234567890,
    "resource_type": "product",
    "keys": [
      {
        "options": {
          "customer_autotag": "",
          "force_open": false,
          "redirect_url": "",
          "inverse": false
        },
        "conditions": [
          {
            "type": "customer_tag",
            "inverse": false,
            "options": {
              "customer_tag": "approved"
            }
          }
        ]
      },
      {
        "options": {
          "customer_autotag": "",
          "force_open": false,
          "redirect_url": "",
          "inverse": false
        },
        "conditions": [
          {
            "type": "passcodes",
            "inverse": false,
            "options": {
              "passcodes": ["letmein"],
              "case_sensitive": true,
              "customer_remember": true
            }
          }
        ]
      }
    ]
  }'
```

##


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.locksmith.guide/more-developer-docs/using-the-admin-api-with-locks.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
