Failed login credential validation in Zapier

I’m experiencing an issue in my authentication.js file. When attempting to create an account in the action block, it allows any string input for both the username and password, leading to unsuccessful validation. Here’s a code snippet that illustrates the setup:

const requestLib = require('request');

const authenticateUser = (z, bundle) => {
  return z.request({
      url: 'https://abc.xyz.com/api/login.json',
      method: 'POST',
      body: JSON.stringify({
        'ms_request': {
          'user': {
            'api_key': 'ABCD',
            'username': bundle.authData.username,
            'password': bundle.authData.password
          }
        }
      })
    }).then((response) => {
      if (response.status === 401) {
        throw new Error('Invalid credentials');
      }
      return response.content;
    });
};

module.exports = {
  type: 'custom',
  fields: [
    { key: 'username', label: 'User', required: true, type: 'string' },
    { key: 'password', label: 'Passcode', required: true, type: 'password' }
  ],
  test: authenticateUser,
  connectionLabel: '{{bundle.authData.username}}'
};

In the user interface, the action block currently accepts any arbitrary strings for username and password when attempting to link an account.

One potential issue to investigate is that the authentication endpoint might not be validating credentials on its side properly, leading to the acceptance of any arbitrary string. Double check to ensure that the API actually throws a 401 error when authentication fails. Additionally, verify that the endpoint URL is correct and that the request headers are set properly, in case any headers are being stripped or malformed in transit. Also, consider logging the responses from the server to debug more effectively. Nor any server logs can give you additional clues if available.

I’ve encountered a similar issue before and it turned out to be related to how data was being handled between Zapier and the API. You might want to review the ‘body’ of your request to ensure names align perfectly with what the API expects. Sometimes even a slight mismatch in the JSON structure can cause authentication to fail silently. Also, double-check the API documentation to ensure there aren’t additional required fields or endpoints that have been updated since you last worked on it. “Debug” in Zapier might not highlight it explicitly, but using Postman to manually test responses could provide more insight into what’s going wrong.

yo! it could also be smthing with ur api_key. if it’s not valid anymore, that might mess with the whole auth process. Try updating or re-grabbing it from ur api provider. check they’re aware that ABCD’s the right key. some provider change security structures often. Good luck! :rocket: