301 error with wordpress

## Describe the problem/error/question
I am trying to set up the Wordpress API in N8N but the API returns a 301 error (which implies there is a redirect). I followed the instructions laid out in here;

URL is correct and it works
Username is not the one I log into the site with it is the one under profile.
I created an app and used the generated password from Wordpress.

## What is the error message (if any)?

301 Moved Permanently nginx

## Please share your workflow

## Share the output returned by the last node
I expect the article that gets generated to be posted. Instead I just get the error when setting up the API.

Information on your n8n setup

Running N8N from the N8N site

1 Like

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hey @Gary_Luton Welcome to community! To properly put your workflow in a post use </> sign and then put your code inside.
Like this

1 Like

Doh! Thanks…I will update

1 Like

This sign you can see on post edit panel, simply push it and then insert the code inside

type or paste code here

Firstly, your Markdown node and Wordpress node both directly connected to AI Agent.
Secondary,

Verify URL Protocol (HTTP vs. HTTPS):

  • Consistency: Ensure that the URL you’re using in n8n matches the protocol (HTTP or HTTPS) configured in your WordPress settings. A mismatch can lead to redirection issues.
  • WordPress Settings: Navigate to your WordPress dashboard, go to Settings > General, and confirm that both the “WordPress Address (URL)” and “Site Address (URL)” fields match the protocol of the URL you’re using in n8n. For instance, if your site is set to use HTTPS, ensure your n8n URL also starts with https://

Trailing Slash:

  • Sometimes, the presence or absence of a trailing slash in your API URL can matter. Try both versions:
    • https://yourdomain.com/wp-json/wp/v2/
    • https://yourdomain.com/wp-json/wp/v2

1. Verify the API Endpoint URL

  • Correct Format: Use the full REST API URL: https://yourdomain.com/wp-json/.
    • Ensure the URL includes https:// (not http://) if your site uses SSL.
    • Include the trailing slash (/) at the end.
  • Test in Browser/Postman: Navigate to https://yourdomain.com/wp-json/ directly. If it shows JSON data, the URL is correct. If it redirects, check for typos or missing path segments.

2. Check WordPress Settings

  • WordPress & Site Address: Go to Settings > General and ensure both addresses use https://.
  • Force SSL: If your server enforces HTTPS, ensure n8n uses the HTTPS URL.

3. Server Configuration

  • Nginx/Apache Rules: Ensure no redirect rules (e.g., www to non-www or vice versa) conflict with the URL used in n8n.
  • Reverse Proxy: If behind a proxy, confirm the URL matches the proxy’s public-facing domain.

4. Authentication Details

  • Username: Use your WordPress login username (from Users > Profile), not the display name.
  • Application Password: Regenerate it in Users > Profile > Application Passwords if unsure.

5. Troubleshoot Plugins/Themes

  • Temporarily disable security/redirect plugins (e.g., Wordfence) to rule out conflicts.

Example Workflow Fix

In n8n’s WordPress credentials:

  • URL: https://yourdomain.com/wp-json/ (with HTTPS and trailing slash).
  • Username: Your actual login username.
  • Password: The generated application password.

Still stuck? Test the API externally using:

bash

Copy

curl -I https://yourdomain.com/wp-json/

Look for HTTP/2 200 (success) or adjust the URL based on redirects shown.

Thanks @Chris_Gates . I tried what you suggested…

  1. Neither site WordPress Address (URL) or Site Address (URL) uses https both are just http.
  2. I am using the username not the display name or the email address. I have also tried all of them just to make sure.
  3. I tried creating a new application password.
  4. I am not using any plugins.
  5. https://ccoadvisor.com/wp-json/
    http://ccoadvisor.com/wp-json/
    http://ccoadvisor.com/wp-json/wp/v2/
    http://ccoadvisor.com/wp-json/wp/v2/

…all show page not found.

6I tried curl on several addresses. I only got a HTTP/2 200 on https://ccoadvisor.com. See below.

Thanks for your suggestions. @Ruslan_Yanyshyn . I tried changing from https to http (which is the format in WP) to no avail.

Also tried those API URLs with or without trailing slashes and neither work.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.