> 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

# GetPageOptimizationResults

# Package: seo

# Namespace: PageOptimizationService

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

## Permission Scopes:
View SEO Settings: SCOPE.PROMOTE.VIEW-SEO

## Introduction

Retrieves the optimization suggestions generated for a page.

Poll this method after a trigger call. The response's `status` reports
where the job stands: while generation is still in progress the
suggestions are empty and `status` is `IN_PROGRESS`; when it completes,
the response carries the full suggestion set with `status` `COMPLETED`.
A job that failed reports `FAILED`. Trigger again to retry. Suggestions
are stored per page, so a later trigger for the same page replaces them,
and a replaced job's lookup reports `NOT_FOUND`.

Look up by `predictionId` (from the trigger call), or by `pageId`. A
`predictionId` can be looked up for 2 hours after the trigger call; after
that, look up by `pageId`, which returns the page's latest generation.

---

## REST API

### Schema

```
 Method: getPageOptimizationResults
 Description: Retrieves the optimization suggestions generated for a page.  Poll this method after a trigger call. The response's `status` reports where the job stands: while generation is still in progress the suggestions are empty and `status` is `IN_PROGRESS`; when it completes, the response carries the full suggestion set with `status` `COMPLETED`. A job that failed reports `FAILED`. Trigger again to retry. Suggestions are stored per page, so a later trigger for the same page replaces them, and a replaced job's lookup reports `NOT_FOUND`.  Look up by `predictionId` (from the trigger call), or by `pageId`. A `predictionId` can be looked up for 2 hours after the trigger call; after that, look up by `pageId`, which returns the page's latest generation.
 URL: https://www.wixapis.com/seo/suggestions/v1/page-optimization/results
 Method: GET
 Method parameters:
   query param name: pageId | type: pageId | description: GUID of the page to retrieve suggestions for. An alternative to `predictionId` that returns the page's latest generation.  | validation: maxLength 1000
   query param name: predictionId | type: predictionId | description: GUID of the generation job, from the trigger call. Can be looked up for 2 hours after the trigger call.  | validation: maxLength 200
 Return type: GetPageOptimizationResultsResponse
  - name: pageOptimization | type: PageOptimization | description: The generated suggestions. Returned only when `status` is `COMPLETED`.  
     - name: id | type: string | description: GUID of this suggestion set.  | read-only: true | validation: format GUID
     - name: metaTitle | type: TextSuggestion | description: Suggested title tag.  | read-only: true 
        - name: before | type: string | description: The page's current text. Empty when the page has no text in this slot, for example, a missing meta description.  | read-only: true | validation: maxLength 1000
        - name: after | type: string | description: The suggested text.  | read-only: true | validation: maxLength 1000
     - name: metaDescription | type: TextSuggestion | description: Suggested description tag.  | read-only: true 
     - name: h1 | type: TextSuggestion | description: Suggested H1 heading.  | read-only: true 
     - name: h2OrH3 | type: TextSuggestion | description: Suggested subheading, for an H2 or H3 element of the page.  | read-only: true 
     - name: content | type: array<TextSuggestion> | description: Suggested rewrites of the page's body text, one per text element.  | read-only: true | validation: maxItems 100
  - name: status | type: OptimizationStatus | description: Status of the generation job the lookup matched.  | read-only: true 
     - enum:
     -     UNKNOWN_OPTIMIZATION_STATUS: Unknown status.
     -     NOT_FOUND: No generation job matches the lookup. It never existed, or a later trigger for the same page replaced it.
     -     IN_PROGRESS: Generation is still running. Poll again.
     -     COMPLETED: Generation finished; the response carries the suggestions.
     -     FAILED: Generation failed. Trigger again to retry.

 Possible Errors:
   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: Reading the stored result failed. Retry the call.


```

### Examples

### Retrieve a finished optimization by its prediction ID
Poll until `status` is `COMPLETED`. While the job runs, the response carries only `"status": "IN_PROGRESS"`.

```curl
curl -X GET \
'https://www.wixapis.com/seo/suggestions/v1/page-optimization/results?predictionId=3f9c1b2e-8a4d-4c6e-9b7a-2d5e8f1c4a6b' \
-H 'Authorization: <AUTH>'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.seo.pageOptimization.getPageOptimizationResults(options)
 Description: Retrieves the optimization suggestions generated for a page.  Poll this method after a trigger call. The response's `status` reports where the job stands: while generation is still in progress the suggestions are empty and `status` is `IN_PROGRESS`; when it completes, the response carries the full suggestion set with `status` `COMPLETED`. A job that failed reports `FAILED`. Trigger again to retry. Suggestions are stored per page, so a later trigger for the same page replaces them, and a replaced job's lookup reports `NOT_FOUND`.  Look up by `predictionId` (from the trigger call), or by `pageId`. A `predictionId` can be looked up for 2 hours after the trigger call; after that, look up by `pageId`, which returns the page's latest generation.
 Method parameters:
   param name: options | type: GetPageOptimizationResultsOptions  none  
        - name: predictionId | type: string | description: GUID of the generation job, from the trigger call. Can be looked up for 2 hours after the trigger call.  | validation: maxLength 200
        - name: pageId | type: string | description: GUID of the page to retrieve suggestions for. An alternative to `predictionId` that returns the page's latest generation.  | validation: maxLength 1000
 Return type: PROMISE<GetPageOptimizationResultsResponse>
  - name: pageOptimization | type: PageOptimization | description: The generated suggestions. Returned only when `status` is `COMPLETED`.  
     - name: _id | type: string | description: GUID of this suggestion set.  | read-only: true | validation: format GUID
     - name: metaTitle | type: TextSuggestion | description: Suggested title tag.  | read-only: true 
        - name: before | type: string | description: The page's current text. Empty when the page has no text in this slot, for example, a missing meta description.  | read-only: true | validation: maxLength 1000
        - name: after | type: string | description: The suggested text.  | read-only: true | validation: maxLength 1000
     - name: metaDescription | type: TextSuggestion | description: Suggested description tag.  | read-only: true 
     - name: h1 | type: TextSuggestion | description: Suggested H1 heading.  | read-only: true 
     - name: h2OrH3 | type: TextSuggestion | description: Suggested subheading, for an H2 or H3 element of the page.  | read-only: true 
     - name: content | type: array<TextSuggestion> | description: Suggested rewrites of the page's body text, one per text element.  | read-only: true | validation: maxItems 100
  - name: status | type: OptimizationStatus | description: Status of the generation job the lookup matched.  | read-only: true 
     - enum:
     -     UNKNOWN_OPTIMIZATION_STATUS: Unknown status.
     -     NOT_FOUND: No generation job matches the lookup. It never existed, or a later trigger for the same page replaced it.
     -     IN_PROGRESS: Generation is still running. Poll again.
     -     COMPLETED: Generation finished; the response carries the suggestions.
     -     FAILED: Generation failed. Trigger again to retry.

 Possible Errors:
   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: Reading the stored result failed. Retry the call.


```

### Examples

### Retrieve a finished optimization by its prediction ID
Poll until `status` is `COMPLETED`. While the job runs, the response carries only `"status": "IN_PROGRESS"`.

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

async function getPageOptimizationResults() {
  const response = await pageOptimization.getPageOptimizationResults({
    predictionId: "3f9c1b2e-8a4d-4c6e-9b7a-2d5e8f1c4a6b",
  });
}

/* Promise resolves to:
 * {
 *   "pageOptimization": {
 *     "_id": "3f9c1b2e-8a4d-4c6e-9b7a-2d5e8f1c4a6b",
 *     "metaTitle": {
 *       "before": "Services | Portland Pottery Studio",
 *       "after": "Pottery Classes in Portland | Portland Pottery Studio"
 *     },
 *     "metaDescription": {
 *       "before": "",
 *       "after": "Join hands-on pottery classes in Portland for beginners and experienced makers. Wheel-throwing, hand-building, and glazing workshops every week."
 *     },
 *     "h1": {
 *       "before": "Our services",
 *       "after": "Pottery classes in Portland for every skill level"
 *     },
 *     "h2OrH3": {
 *       "before": "Wheel-throwing classes",
 *       "after": "Beginner and advanced wheel-throwing classes"
 *     },
 *     "content": [
 *       {
 *         "before": "We offer classes for all levels.",
 *         "after": "Our Portland pottery classes welcome complete beginners and experienced potters alike, with small groups and all materials included."
 *       },
 *       {
 *         "before": "Book a spot online or call us.",
 *         "after": "Book your pottery class in Portland online in under a minute, or call the studio to reserve a spot for a group."
 *       }
 *     ]
 *   },
 *   "status": "COMPLETED"
 * }
 */

```

### getPageOptimizationResults (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 getPageOptimizationResults(options) {
  const response = await myWixClient.pageOptimization.getPageOptimizationResults(options);
};
```

---