> 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 # CreateBranch # Package: branches # Namespace: BranchesService # Method link: https://dev.wix.com/docs/api-reference/business-management/branches/create-branch.md ## Permission Scopes: Manage Site Branches: SCOPE.DC-DOCUMENT-MANAGEMENT.MANAGE-BRANCHES ## Introduction Creates a branch. If a source branch isn't provided, the branch will include a blank website. > **Important:** Align the `sourceType` field with its corresponding source properties: > - When `sourceType` is `SOURCE_BRANCH`, provide `sourceBranchProperties`. > - When `sourceType` is `SOURCE_TEMPLATE`, provide `sourceTemplateProperties`. > > Using `UNKNOWN_SOURCE_TYPE` or mismatched properties results in an `ILLEGAL_SOURCE_TYPE` error. --- ## REST API ### Schema ``` Method: createBranch Description: Creates a branch. If a source branch isn't provided, the branch will include a blank website. > **Important:** Align the `sourceType` field with its corresponding source properties: > - When `sourceType` is `SOURCE_BRANCH`, provide `sourceBranchProperties`. > - When `sourceType` is `SOURCE_TEMPLATE`, provide `sourceTemplateProperties`. > > Using `UNKNOWN_SOURCE_TYPE` or mismatched properties results in an `ILLEGAL_SOURCE_TYPE` error. URL: https://www.wixapis.com/branches/v1/branches Method: POST # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present. Required parameters: branch Method parameters: param name: branch | type: Branch | description: A branch is a version of draft site content that can be edited independently. Also known as a test site. Branches let site owners and developers create isolated versions of a site for testing changes without affecting the live site. Each branch maintains its own content, design, and settings while sharing the same site infrastructure. Learn more about [branches](https://support.wix.com/en/article/about-test-sites). | required: true - ONE-OF: - required: true - name: sourceBranchProperties | type: SourceBranch | description: Source branch properties. Use when `sourceType` = `SOURCE_BRANCH`. - name: branchId | type: string | description: Source branch GUID. - name: branchRevision | type: string | description: Revision number of the source branch when this branch was created. To prevent conflicting changes, the current revision must be passed when updating the branch. - name: sourceTemplateProperties | type: SourceTemplate | description: Source template properties. Use when `sourceType` = `SOURCE_TEMPLATE`. - name: templateId | type: string | description: Source template GUID. - name: type | type: Type | description: Branch type. - enum: - USER: A branch created by a site owner that can be accessed for editing and publishing in the editor. - TECHNICAL: A branch created for technical purposes, unrelated to site owners. For internal use, can't be accessed in the editor. - ORIGINAL_BRANCH: The original branch of the site, created when the site is created. Can be accessed for editing and publishing in the editor. - name: name | type: string | description: Branch name. - name: sourceType | type: SourceType | description: Source type for this branch's content. Must be aligned with the corresponding source properties below. - enum: - SOURCE_BRANCH: This branch's source was another branch. Must be used with `sourceBranchProperties`. - name: extendedFields | type: ExtendedFields | description: Custom field data for the branch. [Extended fields](https://dev.wix.com/docs/rest/articles/getting-started/extended-fields.md) must be configured in the app dashboard before they can be accessed with API calls. - name: namespaces | type: object | description: Extended field data. Each key corresponds to the namespace of the app that created the extended fields. The value of each key is structured according to the schema defined when the extended fields were configured. You can only access fields for which you have the appropriate permissions. Learn more about [extended fields](https://dev.wix.com/docs/rest/articles/getting-started/extended-fields.md). - name: tags | type: PublicTags | description: Public tags assigned to the branch. - name: tags | type: TagList | description: Tags that are exposed to anyone who has access to the labeled entity itself, including site members and visitors. - name: tagIds | type: array | description: List of tag GUIDs. Return type: CreateBranchResponse - name: branch | type: Branch | description: Created branch. - ONE-OF: - name: sourceBranchProperties | type: SourceBranch | description: Source branch properties. Use when `sourceType` = `SOURCE_BRANCH`. - name: branchId | type: string | description: Source branch GUID. - name: branchRevision | type: string | description: Revision number of the source branch when this branch was created. To prevent conflicting changes, the current revision must be passed when updating the branch. - name: sourceTemplateProperties | type: SourceTemplate | description: Source template properties. Use when `sourceType` = `SOURCE_TEMPLATE`. - name: templateId | type: string | description: Source template GUID. - name: id | type: string | description: Branch GUID. - name: revision | type: string | description: Revision number, which increments by 1 each time the branch is updated. To prevent conflicting changes, the current revision must be passed when updating the branch. - name: type | type: Type | description: Branch type. - enum: - USER: A branch created by a site owner that can be accessed for editing and publishing in the editor. - TECHNICAL: A branch created for technical purposes, unrelated to site owners. For internal use, can't be accessed in the editor. - ORIGINAL_BRANCH: The original branch of the site, created when the site is created. Can be accessed for editing and publishing in the editor. - name: name | type: string | description: Branch name. - name: sourceType | type: SourceType | description: Source type for this branch's content. Must be aligned with the corresponding source properties below. - enum: - SOURCE_BRANCH: This branch's source was another branch. Must be used with `sourceBranchProperties`. - name: lastPublishDate | type: string | description: Date and time the branch was last published. - name: editorType | type: EditorType | description: Wix editor type. - name: editorTypeOptions | type: EditorTypeOptions | description: Wix editor types. - enum: - STUDIO: Wix Studio Editor. - CLASSIC: Wix's Classic Editor. - name: default | type: boolean | description: Whether this branch is the default branch. The default branch is used for API operations when no branch GUID is specified. - name: createdDate | type: string | description: Date and time the branch was created. - name: updatedDate | type: string | description: Date and time the branch was last updated. - name: extendedFields | type: ExtendedFields | description: Custom field data for the branch. [Extended fields](https://dev.wix.com/docs/rest/articles/getting-started/extended-fields.md) must be configured in the app dashboard before they can be accessed with API calls. - name: namespaces | type: object | description: Extended field data. Each key corresponds to the namespace of the app that created the extended fields. The value of each key is structured according to the schema defined when the extended fields were configured. You can only access fields for which you have the appropriate permissions. Learn more about [extended fields](https://dev.wix.com/docs/rest/articles/getting-started/extended-fields.md). - name: tags | type: PublicTags | description: Public tags assigned to the branch. - name: tags | type: TagList | description: Tags that are exposed to anyone who has access to the labeled entity itself, including site members and visitors. - name: tagIds | type: array | description: List of tag GUIDs. Possible Errors: HTTP Code: 404 | Status Code: NOT_FOUND | Application Code: SOURCE_USER_BRANCH_DOES_NOT_EXIST | Description: Couldn't find the source user branch. HTTP Code: 404 | Status Code: NOT_FOUND | Application Code: SOURCE_BRANCH_NOT_FOUND | Description: Couldn't find the source branch. HTTP Code: 409 | Status Code: ALREADY_EXISTS | Application Code: TARGET_BRANCH_SITE_HEADER_ALREADY_EXISTS | Description: A site header representing the full immutable state of the site already exists for the specified branch. Each branch can only have 1 site header. HTTP Code: 409 | Status Code: ALREADY_EXISTS | Application Code: ORIGINAL_BRANCH_ALREADY_EXISTS | Description: Original branch already exists. HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: ILLEGAL_SOURCE_TYPE | Description: The `sourceType` field doesn't match its corresponding source properties. Use `sourceBranchProperties` for `SOURCE_BRANCH` or `sourceTemplateProperties` for `SOURCE_TEMPLATE`. HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: TEMPLATE_ID_NOT_SUPPORTED | Description: The specified template isn't supported for branch creation. ``` ### Examples ### Create Branch From Source Template Creates a Branch with basic info, sourced from a template ```curl curl -X POST \ 'https://www.wixapis.com/branches/v1/branches' \ -H 'Authorization: ' \ -H 'Content-Type: application/json' \ -d '{"branch":{ "type":"TECHNICAL", "sourceType":"SOURCE_TEMPLATE", "sourceTemplateProperties": {"templateId": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"} } }' ``` ### Create Branch From Source Branch Creates a Branch with basic info, sourced from the origin branch ```curl curl -X POST \ 'https://www.wixapis.com/branches/v1/branches' \ -H 'Authorization: ' \ -H 'Content-Type: application/json' \ -d '{"branch":{ "type":"USER", "sourceType":"SOURCE_BRANCH", "sourceBranchProperties": {"branchId": "00000000-0000-0000-0000-000000000000"} } }' ``` --- ## JavaScript SDK ### Schema ``` Method: wixClientAdmin.branches.BranchesService.createBranch(branch) Description: Creates a branch. If a source branch isn't provided, the branch will include a blank website. > **Important:** Align the `sourceType` field with its corresponding source properties: > - When `sourceType` is `SOURCE_BRANCH`, provide `sourceBranchProperties`. > - When `sourceType` is `SOURCE_TEMPLATE`, provide `sourceTemplateProperties`. > > Using `UNKNOWN_SOURCE_TYPE` or mismatched properties results in an `ILLEGAL_SOURCE_TYPE` error. # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present. Required parameters: branch Method parameters: param name: branch | type: Branch | description: A branch is a version of draft site content that can be edited independently. Also known as a test site. Branches let site owners and developers create isolated versions of a site for testing changes without affecting the live site. Each branch maintains its own content, design, and settings while sharing the same site infrastructure. Learn more about [branches](https://support.wix.com/en/article/about-test-sites). | required: true - ONE-OF: - required: true - name: sourceBranchProperties | type: SourceBranch | description: Source branch properties. Use when `sourceType` = `SOURCE_BRANCH`. - name: branchId | type: string | description: Source branch GUID. - name: branchRevision | type: string | description: Revision number of the source branch when this branch was created. To prevent conflicting changes, the current revision must be passed when updating the branch. - name: sourceTemplateProperties | type: SourceTemplate | description: Source template properties. Use when `sourceType` = `SOURCE_TEMPLATE`. - name: templateId | type: string | description: Source template GUID. - name: type | type: Type | description: Branch type. - enum: - USER: A branch created by a site owner that can be accessed for editing and publishing in the editor. - TECHNICAL: A branch created for technical purposes, unrelated to site owners. For internal use, can't be accessed in the editor. - ORIGINAL_BRANCH: The original branch of the site, created when the site is created. Can be accessed for editing and publishing in the editor. - name: name | type: string | description: Branch name. - name: sourceType | type: SourceType | description: Source type for this branch's content. Must be aligned with the corresponding source properties below. - enum: - SOURCE_BRANCH: This branch's source was another branch. Must be used with `sourceBranchProperties`. - name: extendedFields | type: ExtendedFields | description: Custom field data for the branch. [Extended fields](https://dev.wix.com/docs/rest/articles/getting-started/extended-fields.md) must be configured in the app dashboard before they can be accessed with API calls. - name: namespaces | type: object | description: Extended field data. Each key corresponds to the namespace of the app that created the extended fields. The value of each key is structured according to the schema defined when the extended fields were configured. You can only access fields for which you have the appropriate permissions. Learn more about [extended fields](https://dev.wix.com/docs/rest/articles/getting-started/extended-fields.md). - name: tags | type: PublicTags | description: Public tags assigned to the branch. - name: tags | type: TagList | description: Tags that are exposed to anyone who has access to the labeled entity itself, including site members and visitors. - name: tagIds | type: array | description: List of tag GUIDs. Return type: PROMISE - ONE-OF: - name: sourceBranchProperties | type: SourceBranch | description: Source branch properties. Use when `sourceType` = `SOURCE_BRANCH`. - name: branchId | type: string | description: Source branch GUID. - name: branchRevision | type: string | description: Revision number of the source branch when this branch was created. To prevent conflicting changes, the current revision must be passed when updating the branch. - name: sourceTemplateProperties | type: SourceTemplate | description: Source template properties. Use when `sourceType` = `SOURCE_TEMPLATE`. - name: templateId | type: string | description: Source template GUID. - name: _id | type: string | description: Branch GUID. - name: revision | type: string | description: Revision number, which increments by 1 each time the branch is updated. To prevent conflicting changes, the current revision must be passed when updating the branch. - name: type | type: Type | description: Branch type. - enum: - USER: A branch created by a site owner that can be accessed for editing and publishing in the editor. - TECHNICAL: A branch created for technical purposes, unrelated to site owners. For internal use, can't be accessed in the editor. - ORIGINAL_BRANCH: The original branch of the site, created when the site is created. Can be accessed for editing and publishing in the editor. - name: name | type: string | description: Branch name. - name: sourceType | type: SourceType | description: Source type for this branch's content. Must be aligned with the corresponding source properties below. - enum: - SOURCE_BRANCH: This branch's source was another branch. Must be used with `sourceBranchProperties`. - name: lastPublishDate | type: string | description: Date and time the branch was last published. - name: editorType | type: EditorType | description: Wix editor type. - name: editorTypeOptions | type: EditorTypeOptions | description: Wix editor types. - enum: - STUDIO: Wix Studio Editor. - CLASSIC: Wix's Classic Editor. - name: default | type: boolean | description: Whether this branch is the default branch. The default branch is used for API operations when no branch GUID is specified. - name: _createdDate | type: Date | description: Date and time the branch was created. - name: _updatedDate | type: Date | description: Date and time the branch was last updated. - name: extendedFields | type: ExtendedFields | description: Custom field data for the branch. [Extended fields](https://dev.wix.com/docs/rest/articles/getting-started/extended-fields.md) must be configured in the app dashboard before they can be accessed with API calls. - name: namespaces | type: object | description: Extended field data. Each key corresponds to the namespace of the app that created the extended fields. The value of each key is structured according to the schema defined when the extended fields were configured. You can only access fields for which you have the appropriate permissions. Learn more about [extended fields](https://dev.wix.com/docs/rest/articles/getting-started/extended-fields.md). - name: tags | type: PublicTags | description: Public tags assigned to the branch. - name: tags | type: TagList | description: Tags that are exposed to anyone who has access to the labeled entity itself, including site members and visitors. - name: tagIds | type: array | description: List of tag GUIDs. Possible Errors: HTTP Code: 404 | Status Code: NOT_FOUND | Application Code: SOURCE_USER_BRANCH_DOES_NOT_EXIST | Description: Couldn't find the source user branch. HTTP Code: 404 | Status Code: NOT_FOUND | Application Code: SOURCE_BRANCH_NOT_FOUND | Description: Couldn't find the source branch. HTTP Code: 409 | Status Code: ALREADY_EXISTS | Application Code: TARGET_BRANCH_SITE_HEADER_ALREADY_EXISTS | Description: A site header representing the full immutable state of the site already exists for the specified branch. Each branch can only have 1 site header. HTTP Code: 409 | Status Code: ALREADY_EXISTS | Application Code: ORIGINAL_BRANCH_ALREADY_EXISTS | Description: Original branch already exists. HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: ILLEGAL_SOURCE_TYPE | Description: The `sourceType` field doesn't match its corresponding source properties. Use `sourceBranchProperties` for `SOURCE_BRANCH` or `sourceTemplateProperties` for `SOURCE_TEMPLATE`. HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: TEMPLATE_ID_NOT_SUPPORTED | Description: The specified template isn't supported for branch creation. ``` ### Examples ### createBranch ```javascript import { branches } from '@wix/editor-branches'; async function createBranch(branch) { const response = await branches.createBranch(branch); }; ``` ### createBranch (with elevated permissions) ```javascript import { branches } from '@wix/editor-branches'; import { auth } from '@wix/essentials'; async function myCreateBranchMethod(branch) { const elevatedCreateBranch = auth.elevate(branches.createBranch); const response = await elevatedCreateBranch(branch); } ``` ### createBranch (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 { branches } from '@wix/editor-branches'; // Import the auth strategy for the relevant access type // Import the relevant host module if needed const myWixClient = createClient ({ modules: { branches }, // Include the auth strategy and host as relevant }); async function createBranch(branch) { const response = await myWixClient.branches.createBranch(branch); }; ``` ---