Use a Function to turn a confirmed selection into a Shopify cart link. This recipe needs no Shopify connector credentials. Generating the link does not create an order or charge the shopper.
For WooCommerce, use its approved product/variation add-to-cart Function; opening that link changes the browser cart. For Wix Stores and Squarespace Commerce, continue through the verified returned product page. The Shopify permalink implementation below is specific to its contract.
Before you begin
- A store supporting Shopify’s Cart and Checkout Permalinks for one-time products. Selling-plan items need another workflow.
- A merchant administrator who can supply the advertised endpoint/version and approved variant map below.
- An editable test project and a test store where you can inspect the resulting cart.
Studio
Open the test project in Agent studio.
Code
Use a Voiceflow bearer credential with access to your test project and Environment. Keep it on your backend or development machine. Set:
The API examples use the Environment’s saved Draft. Standalone execution does not attach a tool, compile an agent or publish a release.
Configure the merchant selection
Have the merchant administrator supply these values before creating the Function:
Get products returns product IDs, not variant IDs. Keep this map administrator-owned.
Download build-shopping-link.mjs and replace its fictional settings, or copy the source below. The Function takes string inputs variant_key and quantity and returns shopping_url and result.
Studio
- In Tools, create a Function named Build shopping link.
- Paste the edited source. Declare Input variables
variant_keyandquantity, and Output variablesshopping_urlandresult. - Save and test a permitted key and quantity.
Code
Use Node 22+ on your development machine. Save create-function.mjs and build-shopping-link.mjs in the same directory. Inspect the downloaded source and apply your approved merchant settings before creating it.
The helper needs Function create/update permissions and uses the stable Function API:
- Creates the Function, then adds its input/output declarations through
function-variable/batchin the selected Environment’s Draft. - Leaves agent attachment and publication as separate steps.
- Is not idempotent: inspect the project before rerunning after a failed request.
The saved functionID is the ID produced by creation, not a name or a guessed identifier.
Shopping-link Function source
Copy the complete implementation after replacing the merchant settings.
Produce and verify the shopping link
Confirm the variant and quantity
Present the product and its exact options from the merchant-approved map. Ask the buyer to confirm the selection and quantity. If the desired option is absent, send them to the verified product page rather than inventing a variant ID.
Build the link
Studio
Attach Build shopping link through Agent → Global tools → + → Function or call it from a Workflow. Set its Trigger to run only after selection confirmation. Supply the approved key and quantity. Share shopping_url only when result is link_ready; needs_selection requires another selection, not an empty link.
Code
Require success: true, error: null and truncated: false, then inspect output.outputVars. Every declared input must be present as a string. This is standalone execution of the saved Draft; agent attachment and compilation are separate if your application needs the agent to invoke it.
Check the buyer's result
For the fictional settings, the expected link is:
Open your actual test link after replacing those settings. Verify the variant, quantity and cart destination; a homepage or empty cart is not success.
Shopify can reduce or omit unavailable items. The shopper reviews the actual cart and finishes the purchase in the store.
Test invalid selections
Test an unknown key, __proto__, an empty quantity, zero, a decimal and a quantity above the example’s limit. Each must return needs_selection and an empty link.
Also test an unavailable variant in the store. The Function does not return cart totals or reserve stock; the buyer must inspect the actual cart.