Setting up the API

Before you can display API data on your WordPress site, you need to configure the API connection. This article walks you through configuring the API endpoint, HTTP method, authentication, and request details.

Overview

When you create a new API, you are essentially setting up a connection profile that defines:

  • Where the data comes from (the API endpoint URL)
  • How to request it (HTTP method like GET or POST)
  • Any credentials or authentication required
  • Additional parameters, headers, or request body data
  • How to format the response from the API – this is the display part

Basic Configuration

API Name

Give your API a short, but descriptive name that helps you remember what this API does. Examples: “Weather Data API”, “Product Listings”, “Blog Posts from External Source”. This name appears in your WordPress admin and helps you identify which API to use when displaying data.

Endpoint URL

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

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

The endpoint URL is where your WordPress site will send requests to retrieve data. Make sure you have the correct URL from the API provider’s documentation.

HTTP Method

Select the appropriate HTTP method for your API request.

For displaying API data on your site, you will typically use GET. If the API documentation says “fetch” or “retrieve”, use GET.

Method Use When Description
GET Retrieving data (most common) Used to fetch data from the API. Does not modify anything on the server.
POST Sending data or creating records Used when you need to send data in the request body.
PUT Updating existing records Used to modify existing data on the server.
DELETE Deleting records Used to remove data from the server.
PATCH Partial updates Similar to PUT but typically for partial modifications.

 

Request Details

Query Parameters

Query parameters are values appended to the URL to filter or customize the API response. They appear after the ? symbol in a URL.

Example URL with parameters: https://api.example.com/products?limit=10&category=electronics&sort=price

In API Press, you can add parameters in key-value pairs:

  • limit = 10
  • category = electronics
  • sort = price

Check the API documentation to see what parameters are available. Common parameters include:

  • limit or per_page – Maximum number of results
  • offset or page – Which page of results to retrieve
  • sort or orderby – How to sort the results
  • filter or search – Filter results

Headers

HTTP headers provide additional metadata for your request. They allow you to specify the format of data you are sending/receiving and can include API keys or other important information.

Common headers include:

Header Purpose
Content-Type Specifies the format of data in the request body (usually application/json)
Accept Tells the API what format you want the response in (usually application/json)
User-Agent Identifies your application to the API server
X-Custom-Header API-specific headers that the provider may require

Most APIs use standard headers by default, but some may require custom headers. Check the API documentation for specific requirements.

Request Body (POST/PUT/PATCH)

If you are using POST, PUT, or PATCH methods, you may need to send data in the request body. The body contains the actual data you want to send to the API.

Body Type: Choose how you want to format the request body:

  • form-data – Traditional form submission format (key-value pairs)
  • raw JSON – Send data as JSON (useful for APIs that expect JSON)

Add your body parameters as key-value pairs. The format depends on the API documentation and your selected body type.

Authentication

Many APIs require authentication to verify that your 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. You receive a token from the API provider and include it in your 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]
Security Tip: Always keep your API tokens secret. Never share them in comments or forums. If a token is exposed, regenerate it in your API provider’s dashboard.

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 with your request
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 may use custom authentication schemes. For these cases:

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

OAuth 2.0

This is available in the PRO plugin.

Advanced Settings

Response Format

Select how the API returns data:

  • JSON – Most common format. API Press automatically parses this.
  • PHP Array – Less common; used when API returns PHP serialized data.

Nearly all modern APIs use JSON format. 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 request is cancelled.

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

Note: Very short timeouts may cause requests to fail if the API is slow. Very long timeouts may cause your page to load slowly if the API is unresponsive.

Cache Duration

Tell API Press to cache the API response for a specified number of seconds. This improves page load speed and reduces the number of requests to the API.

How it works:

  • Set to 0 (default) to fetch fresh data on every request
  • Set to 3600 to cache results for 1 hour
  • Set to 86400 to cache results for 1 day

When to use caching:

  • Data does not change frequently (use longer cache durations)
  • The API charges $$ per request (use longer cache durations)
  • You want to reduce server load

When not to use caching:

  • Data changes very frequently (stock prices, weather, real-time data)
  • You are testing the API integration

SSL Certificate Bypass (Advanced)

By default, API Press verifies SSL certificates when connecting to HTTPS URLs. This ensures secure communication. In rare cases, you may need to disable this verification (for example, if the API uses a self-signed certificate in a development environment).

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

Next Steps

Once your API is configured:

  1. Test the connection by clicking the Test button to preview the API response
  2. Move to the next step: Choosing a Display Template to decide how to present the data
  3. Set up field mapping to connect API response fields to display elements
  4. Add the API data to your pages using shortcode or template tags

Common Issues and Troubleshooting

Connection Failed

Solution: Check that the endpoint URL is correct, the API is online, and your server can access the internet. Test the URL directly in your browser.

Authentication Failed / 401 Error

Solution: Verify your authentication credentials (token, username/password). Make sure they are correct and not expired. Regenerate the token if needed.

Empty Response / No Data

Solution: Check that your query parameters are correct. The API may be returning an empty result set. Verify parameters match the API documentation.

Invalid JSON Response

Solution: Ensure the response format is set correctly. Some APIs may return XML or other formats that require different handling.