> ## Documentation Index
> Fetch the complete documentation index at: https://docs.supercycle.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Intent

> Create an intent for a rental option.

Returns the form attributes required to turn a line item into a Cycle when added to the cart.

Each rental method (subscription, membership, calendar, resale) stores its options in a product metafield. Every option has a `global_id` that is passed to this endpoint.

| Metafield                                                  | Method       |
| ---------------------------------------------------------- | ------------ |
| `product.metafields.supercycle.calendar_configuration`     | Calendar     |
| `product.metafields.supercycle.subscription_configuration` | Subscription |
| `product.metafields.supercycle.membership_configuration`   | Membership   |
| `product.metafields.supercycle.resale_configuration`       | Resale       |

The options array within each metafield contains a `global_id` for each option:

```json theme={null}
{
  "rental_periods": [
    { "global_id": "gid://supercycle/CalendarRental::RentalPeriod/1" },
    { "global_id": "gid://supercycle/CalendarRental::RentalPeriod/2" }
  ]
}
```

Once you have the variant ID and option `global_id`, call this endpoint to get the attributes that need to be attached to the line item so Supercycle processes it as a Cycle.

The response `attributes` object contains key-value pairs that must be included when submitting the add-to-cart form. Each entry should be added as a hidden input on the product form, or included in the request body when submitting via AJAX. See [Cycle line item property](/developers/line-items/cycle-line-item-properties) and [Validations line item property](/developers/line-items/validations-line-item-property) for the full schema.

**Hidden inputs:**

```js theme={null}
Object.entries(intent.attributes).forEach(([name, value]) => {
  const input = document.createElement("input");
  input.type = "hidden";
  input.name = name;
  input.value = value;
  addToCartForm.appendChild(input);
});
```

**AJAX (fetch):**

```js theme={null}
const formData = new FormData(addToCartForm);

Object.entries(intent.attributes).forEach(([name, value]) => {
  formData.set(name, value);
});

await fetch("/cart/add.js", { method: "POST", body: formData });
```

## Add-ons

`add_ons` are additional variants that must be submitted in the same request using Shopify's [multiple items cart API](https://shopify.dev/docs/api/ajax/reference/cart#post-locale-cart-add-js) format. Each add-on property (except `cart_quantity`) should be included as `items[n][property]`:

```js theme={null}
// Example for a single add-on
// items[0][id] = 4321
// items[0][quantity] = 1
// items[0][selling_plan] = 1234
intent.add_ons.forEach(({ cart_quantity, ...addOnAttributes }, index) => {
  Object.entries(addOnAttributes).forEach(([key, value]) => {
    formData.set(`items[${index}][${key}]`, value);
  });
});
```

`cart_quantity` is not submitted — it is the maximum total quantity of that variant that should be present in the cart. Before adding the add-on, check the current cart to see if the variant is already there and skip if the quantity would exceed `cart_quantity`.


## OpenAPI

````yaml POST /{proxy_path_prefix}/intents
openapi: 3.0.3
info:
  title: Product Availability and Rental Intent API
  version: 1.0.0
  description: >-
    API for checking product availability and managing rental intents in a
    customer portal via Shopify proxy
servers: []
security: []
paths:
  /{proxy_path_prefix}/intents:
    parameters:
      - name: proxy_path_prefix
        in: path
        required: true
        schema:
          type: string
        description: >-
          The Shopify proxy path prefix configured for the app (e.g.,
          'customer_portal')
    post:
      tags:
        - Rental Intent
      summary: Create an intent
      description: >-
        Creates an intent for a rental option. Returns attributes to be
        submitted with the Shopify cart form and any add-on variants that should
        also be added to the cart.
      operationId: createIntent
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                variant_id:
                  type: integer
                  description: Shopify ID of the variant to create an intent for
                option:
                  type: object
                  properties:
                    global_id:
                      type: string
                      description: >-
                        Global ID of the rental option (e.g.,
                        'gid://supercycle/CalendarRental::RentalPeriod/1')
                    params:
                      type: object
                      properties:
                        rental_start:
                          type: string
                          format: date
                          description: >-
                            Date when the customer wants to receive the item
                            (required for Calendar, optional for Subscription)
                        location_id:
                          type: integer
                          description: >-
                            Optional Shopify location ID to filter available
                            items by location
                        delivery_method_type:
                          type: string
                          description: Delivery method type (defaults to 'shipping')
                      additionalProperties: true
                  required:
                    - global_id
              required:
                - variant_id
                - option
            examples:
              calendar:
                summary: Calendar intent
                value:
                  variant_id: 123456789
                  option:
                    global_id: gid://supercycle/CalendarRental::RentalPeriod/1
                    params:
                      rental_start: '2025-01-01'
              subscription:
                summary: Subscription intent
                value:
                  variant_id: 123456789
                  option:
                    global_id: gid://supercycle/SubscriptionRental::PricingGroup/1
                    params:
                      rental_start: '2025-01-01'
              membership:
                summary: Membership intent
                value:
                  variant_id: 123456789
                  option:
                    global_id: gid://supercycle/MembershipRental::VariantConfig/1
              resale:
                summary: Resale intent
                value:
                  variant_id: 123456789
                  option:
                    global_id: gid://supercycle/ResaleRental::ResaleOption/1
      responses:
        '200':
          description: Successful response with intent attributes and add-ons
          content:
            application/json:
              schema:
                type: object
                properties:
                  attributes:
                    type: object
                    description: >-
                      Key-value pairs to be submitted with the Shopify
                      add-to-cart form. Includes line item properties (keys
                      prefixed with `properties[...]`) and a `selling_plan` ID
                      where applicable.
                    properties:
                      properties[_cycle]:
                        type: string
                        description: >-
                          JSON-encoded cycle blueprint to be submitted as a line
                          item property
                      properties[_validations]:
                        type: string
                        description: >-
                          JSON-encoded validations to be submitted as a line
                          item property
                      selling_plan:
                        type: integer
                        nullable: true
                        description: >-
                          Shopify selling plan ID (present for Calendar,
                          Subscription, and Membership options)
                    additionalProperties: true
                  add_ons:
                    type: array
                    description: >-
                      Additional variants that must be added to the cart as
                      separate line items (e.g. deposits, card authorisations)
                    items:
                      type: object
                      properties:
                        id:
                          type: integer
                          description: Shopify variant ID of the add-on
                        cart_quantity:
                          type: integer
                          description: >-
                            Maximum quantity of this add-on that should be
                            present in the cart
                        selling_plan:
                          type: integer
                          nullable: true
                          description: Selling plan ID for the add-on, if applicable
                      additionalProperties: true
                  available_item_count:
                    type: integer
                    description: >-
                      Number of available inventory items for the variant within
                      the requested schedule
                required:
                  - attributes
                  - add_ons
                  - available_item_count
              examples:
                calendar:
                  summary: Calendar intent response
                  value:
                    attributes:
                      properties[_cycle]: '{...}'
                      properties[_validations]: '{...}'
                      selling_plan: 1234
                    add_ons: []
                    available_item_count: 3
                subscription:
                  summary: Subscription intent response (with deposit add-on)
                  value:
                    attributes:
                      properties[_cycle]: '{...}'
                      properties[_validations]: '{...}'
                      selling_plan: 1234
                    add_ons:
                      - id: 4321
                        quantity: 1
                        selling_plan: 1234
                        cart_quantity: 1
                    available_item_count: 3
                membership:
                  summary: Membership intent response
                  value:
                    attributes:
                      properties[_cycle]: '{...}'
                      properties[_validations]: '{...}'
                      properties[_credit_cost]: '5'
                      selling_plan: 1234
                    add_ons: []
                    available_item_count: 3
        '422':
          description: >-
            Unprocessable entity - variant not found, option not found, or
            method not enabled
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                required:
                  - error
              examples:
                variant_not_found:
                  summary: Variant not found
                  value:
                    error: Cannot find variant with ID 123456789
                option_not_found:
                  summary: Option not found
                  value:
                    error: >-
                      Cannot find option
                      gid://supercycle/CalendarRental::RentalPeriod/1
                method_not_enabled:
                  summary: Method not enabled
                  value:
                    error: Method is not enabled
        '500':
          description: Server error

````