> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # CreateAndRedirectToCheckout # Package: checkout # Namespace: CheckoutTemplateService # Method link: https://dev.wix.com/docs/api-reference/business-solutions/e-commerce/purchase-flow/checkout/checkout-templates/create-and-redirect-to-checkout.md ## Introduction Creates a new checkout based on the checkout template and redirects to the new checkout page. Before using this method, you must have a checkout template available. Create a checkout template with Create Checkout Template. To build a URL that uses this method, follow this format: `https://www.wixapis.com/ecom/v1/checkout-templates/{checkoutTemplateId}/create-and-redirect-to-checkout?siteId={siteId}` To create a checkout but not automatically redirect to the checkout page, use Create Checkout From Template. --- ## REST API ### Schema ``` Method: createAndRedirectToCheckout Description: Creates a new checkout based on the checkout template and redirects to the new checkout page. Before using this method, you must have a checkout template available. Create a checkout template with Create Checkout Template. To build a URL that uses this method, follow this format: `https://www.wixapis.com/ecom/v1/checkout-templates/{checkoutTemplateId}/create-and-redirect-to-checkout?siteId={siteId}` To create a checkout but not automatically redirect to the checkout page, use Create Checkout From Template. URL: https://www.wixapis.com/ecom/v1/checkout-templates/{checkoutTemplateId}/create-and-redirect-to-checkout Method: GET # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present. Required parameters: checkoutTemplateId, siteId Method parameters: param name: checkoutTemplateId | type: none | required: true query param name: siteId | type: siteId | description: GUID of the site associated with the checkout template. | required: true Return type: RawHttpResponse - name: body | type: bytes | description: - name: statusCode | type: integer | description: - name: headers | type: array | description: - name: key | type: string | description: - name: value | type: string | description: Possible Errors: HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: CANNOT_CREATE_CHECKOUT_FROM_INACTIVE_TEMPLATE | Description: Checkout template is inactive. ``` ### Examples ### Create And Redirect To Checkout From Template ```curl curl -X GET \ 'https://www.wixapis.com/ecom/v1/checkout-templates/d447475f-34ed-4be5-b199-b120c6938c39/create-and-redirect-to-checkout' \ -H 'Authorization: ' \ -H 'Content-Type: application/json' \ -d '{ "siteId": "811d8a67-3bd7-46a5-8cd9-843bb77b2a7d" }' ``` --- ## JavaScript SDK ### Schema ``` Method: wixClientAdmin.checkout.CheckoutTemplateService.createAndRedirectToCheckout(checkoutTemplateId, siteId) Description: Creates a new checkout based on the checkout template and redirects to the new checkout page. Before using this method, you must have a checkout template available. Create a checkout template with Create Checkout Template. To build a URL that uses this method, follow this format: `https://www.wixapis.com/ecom/v1/checkout-templates/{checkoutTemplateId}/create-and-redirect-to-checkout?siteId={siteId}` To create a checkout but not automatically redirect to the checkout page, use Create Checkout From Template. # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present. Required parameters: checkoutTemplateId, siteId Method parameters: param name: checkoutTemplateId | type: string | description: GUID of the checkout template to use to create a checkout. | required: true param name: siteId | type: string | description: GUID of the site associated with the checkout template. | required: true Return type: PROMISE - name: body | type: bytes | description: - name: statusCode | type: integer | description: - name: headers | type: array | description: - name: key | type: string | description: - name: value | type: string | description: Possible Errors: HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: CANNOT_CREATE_CHECKOUT_FROM_INACTIVE_TEMPLATE | Description: Checkout template is inactive. ``` ### Examples ### createAndRedirectToCheckout ```javascript import { checkoutTemplates } from '@wix/ecom'; async function createAndRedirectToCheckout(checkoutTemplateId,siteId) { const response = await checkoutTemplates.createAndRedirectToCheckout(checkoutTemplateId,siteId); }; ``` ### createAndRedirectToCheckout (with elevated permissions) ```javascript import { checkoutTemplates } from '@wix/ecom'; import { auth } from '@wix/essentials'; async function myCreateAndRedirectToCheckoutMethod(checkoutTemplateId,siteId) { const elevatedCreateAndRedirectToCheckout = auth.elevate(checkoutTemplates.createAndRedirectToCheckout); const response = await elevatedCreateAndRedirectToCheckout(checkoutTemplateId,siteId); } ``` ### createAndRedirectToCheckout (self-hosted) Self-hosted SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md). ```javascript import { createClient } from '@wix/sdk'; import { checkoutTemplates } from '@wix/ecom'; // Import the auth strategy for the relevant access type // Import the relevant host module if needed const myWixClient = createClient ({ modules: { checkoutTemplates }, // Include the auth strategy and host as relevant }); async function createAndRedirectToCheckout(checkoutTemplateId,siteId) { const response = await myWixClient.checkoutTemplates.createAndRedirectToCheckout(checkoutTemplateId,siteId); }; ``` ---