Using request from helper-plugin giving 401 error

System Information
  • Strapi Version: 4.3.4
  • Operating System: macOS
  • Database: postgres
  • Node Version: v14.20.0
  • NPM Version: 6.14.17
  • Yarn Version: 1.22.19

Hello Community,

I am developing a local plugin, within the plugin I want to make requests to a content type api.
I am using request from @strapi/helper-plugin to handle requests to the desired api.

Each time the request is made I am logged out from the admin dashboard, on the server I am having a 401 error.

Even with this api set to public I still got the 401 errror.

Am I missing something here ?

Here is the function used to make the request.

const loadOptions = (inputValue) => {
  if (!inputValue) {
    return []
  };
  const params = qs.stringify({
    filters: {
      name: {
        $contains: inputValue,
      },
    },
    pagination: {
      limit: -1
    }
  }, {
    encodeValuesOnly: true
  });

  return request('/api/mediums', { params }).then(({ data }) => {
    if (data.length > 0) {
      return data.map(item => ({
        value: item.id,
        label: item.attributes.name
      }))
    }

  }).catch((error) => {
    console.log('ERROR', error)
  });

How can I request apis from a local plugin otherwise ?
Thank you for your help

Sorry pretty new to this also not sure if this helps but have you tried adding auth:false to your route?

 {
    method: 'GET',
    path: '/example',
    handler: 'example.find',
    config: {
      auth: false
    },
  },

I’m in the same boat. Getting 401. Obviously don’t want to disable auth…