> 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

## Resource: Elevate API Call Permissions with the Astro Integration

## Article: Elevate API Call Permissions with the Astro Integration

## Article Link: https://dev.wix.com/docs/go-headless/authentication/admin/elevate-api-call-permissions-with-the-astro-integration.md

## Article Content:

# Elevate API Call Permissions with the Astro Integration

Some SDK methods require [elevated permissions](https://dev.wix.com/docs/overview/auth-permissions/elevation.md) to access sensitive data or perform privileged operations. For example, retrieving site properties or accessing business data often requires app-level authorization that [certain identities](https://dev.wix.com/docs/overview/auth-permissions/identities.md) don't have. Without elevation, these calls return a 403 Forbidden error.

<blockquote class="important">

**Important:** Elevation is available only in projects built with [Wix's Astro integration](https://dev.wix.com/docs/go-headless/wix-managed-headless/full-integration-astro/about-the-astro-integration.md). It's provided by the [`auth`](https://dev.wix.com/docs/sdk/core-modules/essentials/auth.md) module of `@wix/essentials` and runs in your project's backend code. For any other setup, authorize admin calls with [client credentials](https://dev.wix.com/docs/go-headless/authentication/admin/make-admin-api-calls-with-client-credentials.md) instead.

</blockquote>

> **Note:** To determine whether a method requires elevation, check that method's [reference documentation](https://dev.wix.com/docs/api-reference?apiView=SDK.md).

To elevate API call permissions:

1. Set up your project's backend code to handle elevated requests.
2. Send a request from your frontend code to your project's backend.

> **Note:** For a complete walkthrough, including an elevated endpoint call from the frontend, see [Upload Images to CMS](https://dev.wix.com/docs/go-headless/wix-managed-headless/full-integration-astro/feature-guides/upload-images-to-cms.md).

<blockquote class="important">

**Important:** Exposed elevated API calls can create a security risk for [privilege escalation attacks](https://en.wikipedia.org/wiki/Privilege_escalation). Protect your exposed API calls with logic that validates who can call them and what operations they can perform.

</blockquote>

## Step 1 | Set up the endpoint in your project's backend

Set up your backend to handle requests for elevated API calls from your frontend.

To set up your backend:

1. Create an [HTTP endpoint](https://dev.wix.com/docs/go-headless/wix-managed-headless/full-integration-astro/extensions/backend/http-endpoints/add-http-endpoints-to-your-project.md). Do only **Step 1 | Create the endpoint file** from the linked article.

2. In the file that defines your endpoint, import `APIRoute` from `astro`, the [`auth`](https://dev.wix.com/docs/sdk/core-modules/essentials/auth.md) submodule from `@wix/essentials`, and the module containing the method you want to call with elevated permissions.

   ```ts
   import type { APIRoute } from "astro";
   import { auth } from "@wix/essentials";
   import { <module> } from "@wix/<package>";
   ```

3. Expose an endpoint that calls the API method you need. Wrap the method with [`auth.elevate()`](https://dev.wix.com/docs/sdk/core-modules/essentials/auth.md#elevate) before calling it.

   ```ts
   export const GET: APIRoute = async ({ request }) => {
     const elevatedFunction = auth.elevate(<module>.function);
     const response = await elevatedFunction();
     // ...
   };
   ```

## Step 2 | Call the endpoint from your frontend

Call your backend endpoint from your frontend code by using the standard `fetch()` API with this path: `/api/<your-endpoint-name>`.

```js
const result = await fetch("/api/<your-endpoint-name>");
```

## Examples

The following examples show common elevated API calls.

### Get site properties

#### Backend code

```ts
// src/pages/api/my-api.ts
import type { APIRoute } from "astro";
import { auth } from "@wix/essentials";
import { siteProperties } from "@wix/business-tools";

export const GET: APIRoute = async ({ request }) => {
  const elevatedGetSiteProperties = auth.elevate(siteProperties.getSiteProperties);
  const retrievedSiteProperties = await elevatedGetSiteProperties();
  return new Response(JSON.stringify(retrievedSiteProperties));
};
```

#### Frontend code

```astro
<!-- src/pages/index.astro -->
<script>
  async function getSiteProperties() {
    const result = await fetch("/api/my-api");
    const retrievedSiteProperties = await result.json();
    console.log("Site properties:", retrievedSiteProperties.properties);
  }

  getSiteProperties();
</script>
```

### Send a chat message as the visitor

The Inbox Messages API powers Wix Chat. It requires app-level permissions, so a call made with a visitor's or member's identity returns a 403 Forbidden error. To send a message on a visitor's behalf, elevate `messages.sendMessage()` and pass `sendAs: "PARTICIPANT"` so Wix attributes the message to the visitor's conversation instead of your app.

```ts
// src/pages/api/send-chat-message.ts
import type { APIRoute } from "astro";
import { auth } from "@wix/essentials";
import { messages } from "@wix/inbox";

export const POST: APIRoute = async ({ request }) => {
  const { conversationId, text } = await request.json();
  const elevatedSendMessage = auth.elevate(messages.sendMessage);
  const { message } = await elevatedSendMessage(conversationId, {
    content: { basic: { items: [{ text }] } },
    visibility: "BUSINESS_AND_PARTICIPANT",
    direction: "PARTICIPANT_TO_BUSINESS",
  }, { sendAs: "PARTICIPANT" });
  return new Response(JSON.stringify(message));
};
```

## See also

- [About Elevated Permissions](https://dev.wix.com/docs/overview/auth-permissions/elevation.md)
- [Fix 403 Errors](https://dev.wix.com/docs/go-headless/authentication/troubleshooting/fix-403-errors.md)