> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> 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`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# Method name: createLocation(location: Location)

# Method package: wixBusinessToolsV2

# Method menu location: wixBusinessToolsV2 --> locations --> createLocation

# Method Link: https://dev.wix.com/docs/velo/apis/wix-business-tools-v2/locations/create-location.md

# Method Description:

Creates a location.



# Method Code Examples:

*** Note: do not assume any prop names or enum values other than the ones in the example.

## Create a new location (dashboard page code) 

```javascript
import { locations } from 'wix-business-tools.v2';
import { elevate } from 'wix-auth';

/* Sample location value:
 * {
 *   address: {
 *     formatted: '12 5th Street, New York'
 *   },
 *   name: 'New York Store',
 *   timeZone: 'America/New_York'
 * }
 */

export async function myCreateLocationFunction(location) {
  try {
    const elevatedCreateLocation = elevate(locations.createLocation);
    const newLocation = await elevatedCreateLocation(location);
    console.log('Created new location:', newLocation);
    
    return newLocation;
  } catch (error) {
    console.error(error);
    // Handle the error
  }
}

/* Promise resolves to:
 * {
 *   "_id": "125e9107-2d4b-4790-bb49-37e7983ff9b1",
 *   "address": {
 *     "formatted": "12 5th Street, New York"
 *   },
 *   "archived": false,
 *   "default": false,
 *   "name": "New York Store",
 *   "revision": "1",
 *   "status": "ACTIVE",
 *   "timeZone": "America/New_York"
 * }
 */

```

## Create a new location (export from backend code) 

```javascript
import { Permissions, webMethod } from 'wix-web-module';
import { locations } from 'wix-business-tools.v2';
import { elevate } from 'wix-auth';

/* Sample location value:
 * {
 *   address: {
 *     formatted: '12 5th Street, New York'
 *   },
 *   name: 'New York Store',
 *   timeZone: 'America/New_York'
 * }
 */

export const myCreateLocationFunction = webMethod(Permissions.Anyone, async (location) => {
  try {
    const elevatedCreateLocation = elevate(locations.createLocation);
    const newLocation = await elevatedCreateLocation(location);
    console.log('Created new location:', newLocation);

    return newLocation;
  } catch (error) {
    console.error(error);
    // Handle the error
  }
});

/* Promise resolves to:
 * {
 *   "_id": "125e9107-2d4b-4790-bb49-37e7983ff9b1",
 *   "address": {
 *     "formatted": "12 5th Street, New York"
 *   },
 *   "archived": false,
 *   "default": false,
 *   "name": "New York Store",
 *   "revision": "1",
 *   "status": "ACTIVE",
 *   "timeZone": "America/New_York"
 * }
 */

```

## Create a new location 

```javascript
import { Permissions, webMethod } from 'wix-web-module';
import { locations } from 'wix-business-tools.v2';
import { elevate } from 'wix-auth';

/* Sample location value:
 * {
 *   address: {
 *     city: 'London',
 *     country: 'GB',
 *     formatted: '123 London Street, London',
 *     location: {
 *       latitude: 51.505577,
 *       longitude: -0.068600
 *     },
 *     postalCode: 'N1 1AA',
 *     streetAddress: {
 *       apt: '',
 *       name: 'London Street',
 *       number: '123'
 *     },
 *     subdivision: 'GB-ENG'
 *   },
 *   businessSchedule: {
 *     periods: [
 *       {
 *         closeDay: 'MONDAY',
 *         closeTime: '18:00',
 *         openDay: 'MONDAY',
 *         openTime: '08:00'
 *       },
 *       {
 *         closeDay: 'TUESDAY',
 *         closeTime: '18:00',
 *         openDay: 'TUESDAY',
 *         openTime: '08:00'
 *       },
 *       {
 *         closeDay: 'WEDNESDAY',
 *         closeTime: '18:00',
 *         openDay: 'WEDNESDAY',
 *         openTime: '08:00'
 *       },
 *       {
 *         closeDay: 'THURSDAY',
 *         closeTime: '18:00',
 *         openDay: 'THURSDAY',
 *         openTime: '08:00'
 *       },
 *       {
 *         closeDay: 'FRIDAY',
 *         closeTime: '18:00',
 *         openDay: 'FRIDAY',
 *         openTime: '08:00'
 *       },
 *     ],
 *     specialHourPeriod: [
 *       {
 *         comment: 'Half price in the lead up to Christmas!',
 *         endDate: '2023-12-24T23:59:00Z',
 *         isClosed: false,
 *         startDate: '2023-12-01T00:00:00Z'
 *       }
 *     ]
 *   },
 *   description: 'Our brand new location in London City Center!',
 *   email: 'london@example.com',
 *   fax: '011-44-20-12345678',
 *   name: 'London Store',
 *   phone: '0208 123 4567',
 *   status: 'ACTIVE',
 *   timeZone: 'Europe/London'
 * }
 */

export const myCreateLocationFunction = webMethod(Permissions.Anyone, async (location) => {
  try {
    const elevatedCreateLocation = elevate(locations.createLocation);
    const newLocation = await elevatedCreateLocation(location);
    console.log('Created new location:', newLocation);

    return newLocation;
  } catch (error) {
    console.error(error);
    // Handle the error
  }
});

/* Promise resolves to:
 * {
 *   "_id": "4ae3bbc8-fb78-4eb7-8bc5-1fec19c7dbfc",
 *   "address": {
 *     "city": "London",
 *     "country": "GB",
 *     "formatted": "123 London Street, London",
 *     "location": {
 *       "latitude": 51.505577,
 *       "longitude": -0.0686
 *     },
 *     "postalCode": "N1 1AA",
 *     "streetAddress": {
 *       "apt": "",
 *       "name": "London Street",
 *       "number": "123"
 *     },
 *     "subdivision": "GB-ENG"
 *   },
 *   "archived": false,
 *   "businessSchedule": {
 *     "periods": [
 *       {
 *         "closeDay": "MONDAY",
 *         "closeTime": "18:00",
 *         "openDay": "MONDAY",
 *         "openTime": "08:00"
 *       },
 *       {
 *         "closeDay": "TUESDAY",
 *         "closeTime": "18:00",
 *         "openDay": "TUESDAY",
 *         "openTime": "08:00"
 *       },
 *       {
 *         "closeDay": "WEDNESDAY",
 *         "closeTime": "18:00",
 *         "openDay": "WEDNESDAY",
 *         "openTime": "08:00"
 *       },
 *       {
 *         "closeDay": "THURSDAY",
 *         "closeTime": "18:00",
 *         "openDay": "THURSDAY",
 *         "openTime": "08:00"
 *       },
 *       {
 *         "closeDay": "FRIDAY ",
 *         "closeTime": "18:00",
 *         "openDay": "FRIDAY",
 *         "openTime": "08:00"
 *       }
 *     ],
 *     "specialHourPeriod": [
 *       {
 *         "comment": "Half price in the lead up to Christmas!",
 *         "endDate": "2023-12-24T23:59:00Z",
 *         "isClosed": false,
 *         "startDate": "2023-12-01T00:00:00Z"
 *       }
 *     ]
 *   },
 *   "description": "Our brand new location in London City Center!",
 *   "default": false,
 *   "email": "london@example.com",
 *   "fax": "011-44-20-12345678",
 *   "name": "London Store",
 *   "phone": "0208 123 4567",
 *   "revision": "1",
 *   "status": "ACTIVE",
 *   "timeZone": "Europe/London"
 * }
 */

```

## Create a new location from input on the site's page 

```javascript
/*****************************************
 * Backend code - create-location.web.js *
 ****************************************/

import { Permissions, webMethod } from 'wix-web-module';
import { locations } from 'wix-business-tools.v2';
import { elevate } from 'wix-auth';

export const createNewLocation = webMethod(Permissions.Anyone, async (location) => {
  try {
    const elevatedCreateLocation = elevate(locations.createLocation);
    const newLocation = await elevatedCreateLocation(location);

    return newLocation;
  } catch (error) {
    console.error(error);
    throw new Error(error);
  }
});


/*************
 * Page code *
 ************/

import { createNewLocation } from 'backend/create-location.web';

$w.onReady(() => {
  $w('#createLocationBtn').onClick(async () => {
    const location = {
      address: {
        streetAddress: {
            number: $w('#streetNumber').value,
            name: $w('#streetName').value
        },
        city: $w('#city').value,
        postalCode: $w('#postalCode').value,
      },
      description: $w('#description').value,
      email: $w('#email').value,
      name: $w('#name').value,
      phone: $w('#phone').value,
      timeZone: $w('#timeZone').value
    };

    const newLocation = await createNewLocation(location);
    console.log('You have successfully created a new location.\n', newLocation);
    $w('#newLocationSuccessMsg').show();
  });
});

```

---