Setting up the API for Importing

Before you can import data from an API and create posts in WordPress, you need to configure the API connection. This article walks you through setting up the API endpoint, HTTP method, authentication, and request details for importing data.

Overview

When setting up an API for importing, you are configuring how your WordPress site will retrieve data from external sources to convert into WordPress posts. This includes:

  • Where the data comes from (the API endpoint URL)
  • How to request it (HTTP method, usually GET)
  • Any credentials or authentication required
  • How to access the data within the API response
  • Additional parameters, headers, or filters

Unlike the “Displaying” workflow which only shows API data temporarily, the “Importing” workflow fetches data and permanently creates WordPress posts from it.

Basic Configuration

API Name

Give your API a descriptive name that indicates the source and purpose. This name appears in your WordPress admin and helps you identify which API to use.

Examples: “Import Blog Posts from Medium”, “Product Catalog from Shopify”, “News Feed from External Source”

Endpoint URL

Enter the complete URL of the API endpoint you want to import data from. This should be the full URL including the protocol (http:// or https://).

Example: https://api.example.com/v1/articles

The endpoint should return a list or array of items that you want to convert into posts. Check the API provider’s documentation for the correct URL.

HTTP Method

For importing data, you almost always use GET:

Method Use When Description
GET Retrieving data for import (nearly always) Used to fetch data from the API without modifying anything on the server.
POST Rare. API requires POST to fetch data Some APIs use POST for querying. Check documentation if GET does not work.

In almost all cases, use GET. If the API documentation says “retrieve” or “fetch”, use GET.

Request Details

Query Parameters

Query parameters are values appended to the URL to filter, sort, or customize the data returned. They appear after the ? symbol.

Example URL with parameters: https://api.example.com/articles?limit=50&sort=date&status=published

Use parameters to:

  • Limit the number of results returned (useful for testing before importing all items)
  • Filter data (only published items, specific categories, etc.)
  • Sort results (by date, title, relevance, etc.)
  • Specify the fields to return

Check the API documentation to see what parameters are available.

Headers

HTTP headers provide additional metadata for your request. Most import requests need only basic headers:

Header Purpose
Accept Tells API what format you want responses in (usually application/json)
User-Agent Identifies your application to the API
Authorization Authentication credentials if required

Most APIs set these automatically. Only add custom headers if the API documentation specifically requires them.

Authentication

Many APIs require authentication to verify that your import requests are legitimate. API Press supports multiple authentication methods:

No Authentication

Some APIs are public and do not require authentication. Leave the authentication settings empty.

Bearer Token

This is the most common authentication method for APIs. You receive a token from the API provider and include it with requests.

How to use:

  1. Select Bearer Token as the authentication type
  2. Paste your token into the Bearer Token field
  3. API Press automatically adds the header: Authorization: Bearer [your-token]

Where to find your token: Check your API provider’s account settings or documentation for API keys.

Basic Authentication (Username/Password)

Some APIs use traditional username and password authentication.

How to use:

  1. Select Basic Auth as the authentication type
  2. Enter your username and password
  3. API Press automatically encodes and sends these credentials
Important: Basic authentication is less secure than bearer tokens. Only use it if the API provider specifically requires it and the connection is over HTTPS (secure).

Custom Header Authentication

Some APIs use custom authentication schemes. For these cases:

  1. Add the required header in the Headers section
  2. Use the header name specified by your API provider (for example: X-API-Key)
  3. Set the value to your authentication credential

Advanced Settings

Response Format

Select how the API returns data:

  • JSON – Most common format. Nearly all modern APIs use this.
  • PHP Array – Less common; used for PHP serialized data.

Nearly all modern APIs use JSON. Check your API documentation if you are unsure.

Timeout

Set the maximum number of seconds to wait for the API to respond. If the API does not respond within this time, the import is cancelled.

Recommended value: 10-30 seconds. Set to 0 to use WordPress default timeout (usually 5 seconds).

Note: Importing large amounts of data may take time. Use a generous timeout if you are fetching hundreds or thousands of items.

Cache Duration

API Press can cache API responses to reduce repeated requests. However, caching is generally not recommended for imports since you want fresh data each time you run the importer.

Recommendation: Set to 0 (no cache) so you always get the latest data from the external API.

SSL Certificate Bypass (Advanced)

By default, API Press verifies SSL certificates when connecting to HTTPS URLs. In rare development scenarios, you may need to disable this verification (for example, with self-signed certificates).

Warning: Only enable SSL bypass for development or testing. Never enable it in production. This makes your connection less secure.

Understanding API Response Structure

For importing to work correctly, you need to understand how the API returns data. The importer looks for an array of items to convert into posts.

Simple Array Response

The simplest response is an array of items at the root level:

[ { “id”: 1, “title”: “First Article”, “content”: “Article content here…” }, { “id”: 2, “title”: “Second Article”, “content”: “More content…” } ]

For this structure, leave the Collection Path empty.

Nested Array Response

Some APIs nest the array inside an object:

{ “status”: “success”, “data”: { “items”: [ { “id”: 1, “title”: “First Article”, “content”: “Article content here…” }, { “id”: 2, “title”: “Second Article”, “content”: “More content…” } ] } }

For this structure, set the Collection Path to data.items to tell the importer where to find the list of items.

Single Level Nesting

Another common pattern:

{ “articles”: [ { “id”: 1, “title”: “First Article” } ] }

For this, set Collection Path to articles.

Testing Your Configuration

Before running a full import, test your API configuration:

Step 1: Verify the Endpoint

Test the endpoint URL directly in your browser or with a tool like Postman:

  1. Open the endpoint URL in your browser (if it’s a GET request)
  2. Verify you can access it and see data
  3. Check that the data is in the format you expect

Step 2: Test with API Press

In the API Press admin:

  1. Configure your API endpoint, method, and authentication
  2. Click “Test Request” to fetch a sample of the data
  3. Review the response to confirm it looks correct

Step 3: Identify the Collection Path

Look at the response and find where the array of items is located:

  • If items are at the root: leave Collection Path blank
  • If items are nested: use dot notation (e.g., data.items)

Step 4: Small Test Import

Before importing thousands of items:

  1. Add a limit parameter to fetch just a few items (e.g., &limit=5)
  2. Run the importer with this limited data
  3. Review the created posts to ensure they look correct
  4. Remove the limit and run a full import

Common API Examples

WordPress REST API

Endpoint: https://example-blog.com/wp-json/wp/v2/posts

Method: GET

Authentication: None (if blog is public)

Collection Path: (leave blank – response is already an array)

Medium Public API

Endpoint: https://api.medium.com/v1/users/@username/articles

Method: GET

Authentication: Bearer Token

Collection Path: data

RSS to JSON API

Endpoint: https://api.rss2json.com/v1/api.json?rss_url=https://example.com/feed

Method: GET

Authentication: None

Collection Path: items

Custom REST API

Endpoint: Depends on your service

Method: GET

Authentication: Bearer Token or API Key

Collection Path: Check API documentation

Troubleshooting Connection Issues

Cannot Connect to API

Check:

  • Endpoint URL is correct and starts with https:// or http://
  • External API is online and accessible
  • Your server can reach the external API (check firewall)
  • No typos in the URL

Authentication Failed / 401 Error

Check:

  • Authentication credentials (token, username/password) are correct
  • Token has not expired
  • Authentication method matches what the API expects
  • Try regenerating the token in the API provider’s account

Empty Response / No Data

Check:

  • Query parameters are correct (correct filter values, etc.)
  • The API actually contains data matching your filters
  • Collection Path is correct for your API response structure

Invalid JSON Response

Check:

  • Response format is set correctly to JSON
  • API actually returns JSON (not XML, HTML, or other format)
  • Endpoint URL is returning data, not an error page