Skip to content

routes/wp-importer

function POST(context: APIContext<Record<string, any>, Record<string, undefined | string>>): Response | Promise<Response>

Defined in: studiocms/packages/studiocms_devapps/src/routes/wp-importer.ts:33

Handles the POST request for importing data from a WordPress site.

APIContext<Record<string, any>, Record<string, undefined | string>>

The context of the API request.

Response | Promise<Response>

The response object indicating the result of the import operation.

The function expects the request to contain form data with the following fields:

  • url: The URL of the WordPress site to import data from.
  • type: The type of data to import (e.g., ‘pages’, ‘posts’, ‘settings’).
  • useBlogPlugin (optional): A boolean value indicating whether to use the blog plugin for importing posts.

The function performs the following steps:

  1. Extracts the form data from the request.
  2. Validates the presence and types of the url and type fields.
  3. Logs the import operation details.
  4. Based on the type field, calls the appropriate import function:
    • importPagesFromWPAPI for importing pages.
    • importPostsFromWPAPI for importing posts, optionally using the blog plugin.
    • importSettingsFromWPAPI for importing settings.
  5. Returns a response indicating success or failure.

If the type field contains an invalid value.