> 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

# TriggerPageOptimization

# Package: seo

# Namespace: PageOptimizationService

# Method link: https://dev.wix.com/docs/api-reference/business-management/seo/page-optimization-v1/trigger-page-optimization.md

## Permission Scopes:
Manage SEO Settings: SCOPE.PROMOTE.MANAGE-SEO

## Introduction

Starts generating optimization suggestions for a static page.

Other site items, such as blog posts, store products, bookings services,
and events, return a `PAGE_NOT_SUPPORTED` error.

The suggestions target the page's focus keyword, so set it first: run
keyword research, set the chosen keyword as the page's focus keyword,
then trigger. Returns a `predictionId` to poll Get Page Optimization
Results with.

Triggering is idempotent per page: while a generation for the page is in
progress, calling again returns the same `predictionId` instead of
starting a new job, unless the page's focus keyword changed since the
job started, which returns a `SUGGESTIONS_ALREADY_IN_PROGRESS` error.

---

## REST API

### Schema

```
 Method: triggerPageOptimization
 Description: Starts generating optimization suggestions for a static page.  Other site items, such as blog posts, store products, bookings services, and events, return a `PAGE_NOT_SUPPORTED` error.  The suggestions target the page's focus keyword, so set it first: run keyword research, set the chosen keyword as the page's focus keyword, then trigger. Returns a `predictionId` to poll Get Page Optimization Results with.  Triggering is idempotent per page: while a generation for the page is in progress, calling again returns the same `predictionId` instead of starting a new job, unless the page's focus keyword changed since the job started, which returns a `SUGGESTIONS_ALREADY_IN_PROGRESS` error.
 URL: https://www.wixapis.com/seo/suggestions/v1/page-optimization/trigger
 Method: POST
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  pageId, pagePath
 Method parameters: 
   param name: pageId | type: pageId | description: GUID of the static page to optimize. This is the item GUID the Item SEO Tags API uses for item type `STATIC_PAGE`. The page's focus keyword must be set. | required: true | validation: minLength 1, maxLength 1000
   param name: pagePath | type: pagePath | description: URL path of the page, relative to the site's domain. For example, `/about`. | required: true | validation: minLength 1, maxLength 1000
 Return type: TriggerPageOptimizationResponse
  - name: predictionId | type: string | description: GUID of the generation job. Pass to Get Page Optimization Results.  | read-only: true | validation: maxLength 200

 Possible Errors:
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: SUGGESTIONS_ALREADY_IN_PROGRESS | Description: A generation job for this page is already in progress with a different focus keyword. Wait for it to finish, or poll its results.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: PAGE_SCAN_UNAVAILABLE | Description: The page could not be scanned. Check that the published page URL is accessible, then try again.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: CONTENT_TOO_SHORT | Description: The page doesn't have enough text content to optimize.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: FOCUS_KEYWORD_NOT_SET | Description: The page has no focus keyword set. Run keyword research, set the page's focus keyword, then trigger.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: PAGE_NOT_SUPPORTED | Description: No static page with this GUID exists on the site. Only static pages are supported, not other site items such as blog posts or store products.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: SITE_NOT_SUPPORTED | Description: The site can't be optimized, for example, a headless project with no Wix-rendered site.
   HTTP Code: 429 | Status Code: RESOURCE_EXHAUSTED | Application Code: QUOTA_LIMIT_REACHED | Description: The caller's generation quota is exhausted. Not currently returned: calls over the rate limit are rejected with HTTP 429 before they reach the service.
   HTTP Code: 500 | Status Code: INTERNAL | Application Code: GENERATION_FAILED | Description: The AI generation pipeline failed. Retry the call.


```

### Examples

### Start optimizing a page for its focus keyword
The page must be a static page with a focus keyword already set in its SEO settings. Poll Get Page Optimization Results with the returned `predictionId`.

```curl
curl -X POST \
'https://www.wixapis.com/seo/suggestions/v1/page-optimization/trigger' \
-H 'Authorization: <AUTH>' \
-H 'Content-Type: application/json' \
-d '{
  "pageId": "k7f2c",
  "pagePath": "/services"
}'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.seo.pageOptimization.triggerPageOptimization(pageId, options)
 Description: Starts generating optimization suggestions for a static page.  Other site items, such as blog posts, store products, bookings services, and events, return a `PAGE_NOT_SUPPORTED` error.  The suggestions target the page's focus keyword, so set it first: run keyword research, set the chosen keyword as the page's focus keyword, then trigger. Returns a `predictionId` to poll Get Page Optimization Results with.  Triggering is idempotent per page: while a generation for the page is in progress, calling again returns the same `predictionId` instead of starting a new job, unless the page's focus keyword changed since the job started, which returns a `SUGGESTIONS_ALREADY_IN_PROGRESS` error.
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  pageId, options.pagePath, options
 Method parameters: 
   param name: pageId | type: string | description: GUID of the static page to optimize. This is the item GUID the Item SEO Tags API uses for item type `STATIC_PAGE`. The page's focus keyword must be set. | required: true | validation: minLength 1, maxLength 1000
   param name: options | type: TriggerPageOptimizationOptions  none | required: true 
        - name: pagePath | type: string | description: URL path of the page, relative to the site's domain. For example, `/about`. | required: true | validation: minLength 1, maxLength 1000
 Return type: PROMISE<TriggerPageOptimizationResponse>
  - name: predictionId | type: string | description: GUID of the generation job. Pass to Get Page Optimization Results.  | read-only: true | validation: maxLength 200

 Possible Errors:
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: SUGGESTIONS_ALREADY_IN_PROGRESS | Description: A generation job for this page is already in progress with a different focus keyword. Wait for it to finish, or poll its results.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: PAGE_SCAN_UNAVAILABLE | Description: The page could not be scanned. Check that the published page URL is accessible, then try again.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: CONTENT_TOO_SHORT | Description: The page doesn't have enough text content to optimize.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: FOCUS_KEYWORD_NOT_SET | Description: The page has no focus keyword set. Run keyword research, set the page's focus keyword, then trigger.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: PAGE_NOT_SUPPORTED | Description: No static page with this GUID exists on the site. Only static pages are supported, not other site items such as blog posts or store products.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: SITE_NOT_SUPPORTED | Description: The site can't be optimized, for example, a headless project with no Wix-rendered site.
   HTTP Code: 429 | Status Code: RESOURCE_EXHAUSTED | Application Code: QUOTA_LIMIT_REACHED | Description: The caller's generation quota is exhausted. Not currently returned: calls over the rate limit are rejected with HTTP 429 before they reach the service.
   HTTP Code: 500 | Status Code: INTERNAL | Application Code: GENERATION_FAILED | Description: The AI generation pipeline failed. Retry the call.


```

### Examples

### Start optimizing a page for its focus keyword
The page must be a static page with a focus keyword already set in its SEO settings. Poll Get Page Optimization Results with the returned `predictionId`.

```javascript
import { pageOptimization } from "@wix/seo";

async function triggerPageOptimization() {
  const response = await pageOptimization.triggerPageOptimization("k7f2c", {
    pagePath: "/services",
  });
}

/* Promise resolves to:
 * {
 *   "predictionId": "3f9c1b2e-8a4d-4c6e-9b7a-2d5e8f1c4a6b"
 * }
 */

```

### triggerPageOptimization (self-managed)
Self-managed 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 { pageOptimization } from '@wix/seo';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed

const myWixClient = createClient ({
  modules: { pageOptimization },
  // Include the auth strategy and host as relevant
});


async function triggerPageOptimization(pageId,options) {
  const response = await myWixClient.pageOptimization.triggerPageOptimization(pageId,options);
};
```

---