> 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

# 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 site page.

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.

Must be called with a [Wix user identity](https://dev.wix.com/docs/api-reference/articles/authentication/about-identities.md). Calls made with an API key fail.

---

## REST API

### Schema

```
 Method: triggerPageOptimization
 Description: Starts generating optimization suggestions for a site page.  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.  Must be called with a [Wix user identity](https://dev.wix.com/docs/api-reference/articles/authentication/about-identities.md). Calls made with an API key fail.
 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 site page to optimize. 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: 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: 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. Reserved for future metering and not currently returned.
   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's focus keyword must already be 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 site page.  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.  Must be called with a [Wix user identity](https://dev.wix.com/docs/api-reference/articles/authentication/about-identities.md). Calls made with an API key fail.
 # 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: 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
   param name: pageId | type: string | description: GUID of the site page to optimize. The page's focus keyword must be set. | 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: 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: 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. Reserved for future metering and not currently returned.
   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's focus keyword must already be 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-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 { 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);
};
```

---