API Error: You are not permitted to view the requested resource

Is anyone else experiencing this problem at the moment? I’ve been trying for two days to use the API, but I get similar errors every time. I’m not sure if I’m missing a step or if something changed.

I created a new API key for the system user. I also tried creating an API key for all users and then using my admin account.

Using the discourse_api Ruby gem:

DiscourseApi::UnauthenticatedError ({"errors"=>["You are not permitted to view the requested resource. The API username or key is invalid."], "error_type"=>"invalid_access"})

I also tried with this code from another post:

require 'net/http'
require 'uri'

INSTANCE_URL = 'https://forum.example.com/admin/users/list/all.json?email=user@example.com'
API_USERNAME = 'system'
API_KEY = 'a_new_api_key_here'

def send_request
  url = URI.parse(INSTANCE_URL)
  request = Net::HTTP::Get.new(url.path)
  request.set_form_data({'api_username' => API_USERNAME, 'api_key' => API_KEY})
  http = Net::HTTP.new(url.host, url.port)
  response = http.request(request)

  if response.code == '200'
    puts "Success!"
  else
    puts "Error"
    puts response.code
  end
end

send_request # 400

I also tried using the API by putting the api_username and api_key in form data along with a raw request, but I get a 404 error.

I’m trying to write a script that reads in a list of email addresses, gets the usernames, and then unsubscribes them from all Discourse emails.