"HTTP Request Block Failing with 401 Unauthorized Error"

“I have a workflow that uses the HTTP Request block to make a POST call to an external WordPress API. The call is failing with a 401 Unauthorized error (rest_cannot_create).”

Troubleshooting Steps Taken

"To troubleshoot this, I performed the following tests, which have ruled out all issues on my end:

  1. Tested the API and Credentials directly: I used a separate API client (Postman) to make the exact same POSTrequest to the WordPress API. This test succeeded with a 201 Created response. This confirms that the API endpoint is working, my credentials are correct, and there are no server-side firewall or plugin conflicts.

  2. Confirmed the generated JSON: I verified that the Generate Text block is producing a correctly formatted JSON payload.

  3. Removed all variables from the HTTP Request: I created a new workflow with a hardcoded Authorizationheader and a hardcoded JSON body (pasted directly from the successful Postman test). This test failed with the same 401 Unauthorized error. This proves that the issue is not related to dynamic variables or how the AI is generating the content.

Conclusion

“Based on these results, it appears there is an issue with how the MindStudio HTTP Request block is sending the request, possibly due to a bug where it’s adding unseen parameters or headers that are causing the request to be rejected by the server.”

There is the full run with password removed

Can you please share a link to the agent and I can take a look?

Hi Sean

Here it is https://app.mindstudio.ai/agents/test-run-5005170f/run/cdda67aa-956b-47a0-81ab-05e9f83f4061

Run Details

Run ID

7d8ebe1b-a9c7-4523-a97b-d7e961322d43

Source

Manually run by user

User ID

b21dd327

Hmm, I can verify everything looks fine here. Could you share the code snippet generated by Postman? On the right side there should be a little </> icon that you can click and it will show something like this:

Hi Sean there it is

curl --location ‘https://wpfoodieschool.com/wp-json/wp/v2/wprm_recipe’ \

--header ‘Content-Type: application/json’ \

--header ‘Authorization: ••••••’ \

--data '{

“status”: “publish”,

“wprm_recipe”: {

“name”: “API Test Recipe”,

“summary”: “This recipe was created via a direct API call.”

}

}’

Hi @ramelton,

Here’s a quick guide on how to get the WP Recipe Maker working with MindStudio’s HTTP Request block:

1. Prep WordPress

  1. Install & activate WP Recipe Maker
  2. Go to Users → Profile → Application Passwords
  3. Generate a new one (e.g. “MindStudio”) and copy it exactly (spaces included)
  4. Copy your username (e.g. “3xte3dr6abq5”)

2. Configure HTTP Request block

  1. Method: POST
  2. URL: https://yourdomain.com/wp-json/wp/v2/wprm_recipe
  3. Headers:
    Accept: application/json
    User-Agent: Mozilla/5.0
    Content-Type: application/json
    Authorization: Basic <your_base64_string>

Alternatively, you can create a Custom Function to generate the Authorization header value:

Code:

// Validate required inputs
if (!ai.config.wordpressUsername?.trim()) {
  throw new Error('WordPress username is required');
}

if (!ai.config.wordpressPassword?.trim()) {
  throw new Error('WordPress application password is required');
}

// Generate Basic auth header
const username = ai.config.wordpressUsername.trim();
const password = ai.config.wordpressPassword.trim();
const credentials = `${username}:${password}`;

// Base64 encode the credentials
const encodedCredentials = btoa(credentials);
const authHeader = `Basic ${encodedCredentials}`;

// Log the generated headers
console.log('Generated Authorization header');

// Set output variables
ai.vars[ai.config.authHeader] = authHeader;

Configuration:

config = {
  transitionType: 'controlled',
  metadata: {
    name: 'Generate WordPress API Headers',
    description: 'Generates authentication headers for WordPress API requests',
  },
  blockStyle: {
    label: 'Generate WP Headers',
  },
  configurationSections: [
    {
      title: 'WordPress Authentication',
      items: [
        {
          label: 'WordPress Username',
          type: 'text',
          variable: 'wordpressUsername',
          helpText: 'Your WordPress API username',
          placeholder: 'e.g., 3xte6da4abq2',
        },
        {
          label: 'WordPress Application Password',
          type: 'text',
          variable: 'wordpressPassword',
          helpText: 'Your WordPress application password (spaces allowed)',
          placeholder: 'e.g., 4c8A eBnX ALMw QXk8 1NF7 3dQy',
        },
      ],
    },
    {
      title: 'Output Variable Names',
      items: [
        {
          label: 'Authorization Header Variable',
          type: 'outputVariableName',
          variable: 'authHeader',
          helpText: 'The variable name for the Basic authentication header',
        }
      ],
    },
  ],
}
  1. Content Type: application/json
  2. Body:
{
  "status": "publish",
  "title": "Best Banana Bread",
  "content": "This recipe was created via MindStudio REST API.",
  "wprm_recipe": {
  "name": "Best Banana Bread"
  }
}

Hi Alex, thanks very much I got it working.

Thanks very much Alex I got it working.

@ramelton Glad to hear you got in working! Can you briefly share what the issue was and how you fixed it? Just for anyone else who might be browsing and running into the same sort of issue!