Trigger API on password protected site

By: Dan Maby | Asked: 06/04/2023
ForumsCategory: Code HelpTrigger API on password protected site
Dan MabyDan Maby asked 1 year ago

Hey all,

I am working on a staging site that is password protected via basic authentication. I want to send API data on a form submission to the same site. If I disable the password protection on the site, the API request functions as expected, but when the site is protected, the request fails with a `401 Authorization Required` status. I have tried customizing the API request header with the following function:

/**
  * REMOVE FROM PRODUCTION
  *
  * Set Basic Auth credentials for Formidable Forms
  *
  **/
  function ps_frm_api_request_header($arg_array, $args)
  {
  $username = "USERNAME";
  $password = "PASSWORD";
   
  if ($args["url"] == "https://staging.example.com") {
  // the full url where the request is being sent
  $arg_array["headers"]["Authorization"] =
  "Basic " . base64_encode($username . ":" . $password);
  }
   
  return $arg_array;
  }
   
  add_filter("frm_api_request_args", "ps_frm_api_request_header", 10, 2);

However, the status of the API request still fails. Can anyone help me understand how to send API requests with a site password protected?

Question Tags:

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right