Error: The remote server returned an error: (401) Unauthorized

Before Creating a New Topic:

If you’re experiencing unexpected API/Zoom API Events (webhooks) behavior please search the forum with relevant keywords (e.x. error message) and follow the guidance outlined in those posts. Please also leverage the following support links:


Format Your New Topic as Follows:

API Endpoint(s) and/or Zoom API Event(s)
Link the API endpoint(s) and/orZoom API Event(s) you’re working with to help give context.

Description
Details on your question, workflow or the problem you’re trying to solve.

Error?
The full error message or issue you are running into, where applicable.

How To Reproduce
Steps to reproduce the behavior:
1. Request URL / Headers (without credentials or sensitive info like emails, uuid, etc.) / Body
2. Authentication method or app type
3. Any errors

When I am trying to get VC recording from API https://api.zoom.us/v2/meetings/" + MeetingId.ToString() + "/recordings

@scdlzoom.sisteam please see my replies in this thread:

After replacing client_credentials with account_credentials I was getting Bad request.

I’d recommend posting your actual code you’re using to generate token and the request itself, with your secret stuff like account ID and secret key edited out, so we can better assist you. Thanks!

Follow up: I’d just take a quick look at this doc and make sure your app has the required granular scopes. Also, I see that Error 400 (what you’re recieving) can in some cases have a Zoom error code, which indicates the owner of the recording isn’t part of your overall Zoom account. If that’s not the case then it’s likely your actual GET request is malformed in some way. Pasting your code and detailed error recieved is the best way to get a fix in place.

Thank you for your reply. Now I am getting error ‘Error: The remote server returned an error: (404) Not Found.’ Sample code attached.

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace ZoomRecording
{
public partial class Recordings : System.Web.UI.Page
{

private readonly string _clientId = “”;
private readonly string _clientSecret = “”;

    private readonly string _accountid = "";
    private readonly string _zoomApiUrl1 = "https://api.zoom.us/v2";

    private readonly string _zoomApiUrl = "https://api.zoom.us";
    private readonly string _connectionString = "Initial Catalog=SAE;Data Source=1.1.1.1;User Id=sa;Password=123456789;Connection Timeout=60"; // Database connection string
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected async void btnProcessRecordings_Click(object sender, EventArgs e)
    {
        try
        {
            string accessToken = await GetZoomAccessToken();
            if (string.IsNullOrEmpty(accessToken))
            {
                lblStatus.Text = "Failed to retrieve token.";
                return;
            }

            List<string> zoomIds = GetZoomIdsFromDatabase(); // Retrieve Zoom IDs from the database
            if (zoomIds.Count == 0)
            {
                lblStatus.Text = "No Zoom IDs found in the database.";
                return;
            }

            foreach (string zoomId in zoomIds)
            {
                //await ProcessRecording(zoomId, accessToken);
                ProcessRecording(zoomId, accessToken);
            }

            lblStatus.Text = "Recording processing completed.";
        }
        catch (Exception ex)
        {
            lblStatus.Text = "Error: " + ex.Message;
        }
    }
    private void ProcessRecording(string zoomId, string accessToken)
    {
        HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create("https://api.zoom.us/v2/meetings/" + zoomId.ToString() + "/recordings");
        httpWReq.Method = "GET";
        httpWReq.ContentType = "application/json";
        httpWReq.Headers.Add("Authorization", String.Format("Bearer {0}", accessToken));
        HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();
        HttpStatusCode statusCode = response.StatusCode;
        int numericStatusCode = (int)statusCode;

        string s = response.ToString();
        StreamReader reader = new StreamReader(response.GetResponseStream());
        String jsonresponse = "";
        String temp = null;
        while ((temp = reader.ReadLine()) != null)
        {
            jsonresponse += temp;
        }

        var jsonObject = JObject.Parse(jsonresponse);
        string responce = "";


        JsonResponse_RecordingVC clsobj = jsonObject.ToObject<JsonResponse_RecordingVC>();
        int cnt = 0;
        foreach (clsJsonRecording_files recordOj in clsobj.recording_files)
        {
            if (cnt == 0)
            {
                if (recordOj.play_url != "")
                {
                    if (recordOj.recording_type == "shared_screen_with_speaker_view" || recordOj.recording_type == "shared_screen_with_speaker_view(CC)")
                    {
                        responce = recordOj.play_url;
                        UpdateDatabaseWithDownloadUrl(zoomId, responce);
                        cnt = 1;
                    }
                }
            }
        }

        //return responce;
    }
    private async Task<string> GetZoomAccessToken()
    {
        using (var httpClient = new HttpClient())
        {
            var authString = $"{_clientId}:{_clientSecret}";
            var encodedAuth = Convert.ToBase64String(Encoding.UTF8.GetBytes(authString));

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", encodedAuth);

            

            var content = new FormUrlEncodedContent(new[]

                  {

                new KeyValuePair<string, string>("grant_type", "account_credentials"),

                new KeyValuePair<string, string>("client_id", _clientId),

                new KeyValuePair<string, string>("client_secret", _clientSecret),

             new KeyValuePair<string, string>("account_id", _accountid)

            });

            try
            {
                var response = await httpClient.PostAsync($"{_zoomApiUrl}/oauth/token", content);
                response.EnsureSuccessStatusCode();

                var responseContent = await response.Content.ReadAsStringAsync();
                dynamic tokenData = JsonConvert.DeserializeObject(responseContent);

                return tokenData.access_token;
            }
            catch (HttpRequestException ex)
            {
                lblStatus.Text = $"<br>Token retrieval error: {ex.Message}";
                return null;
            }
        }
    }
    private List<string> GetZoomIdsFromDatabase()
    {
        List<string> zoomIds = new List<string>();

        using (SqlConnection connection = new SqlConnection(_connectionString))
        {
         
            string query = "SELECT  ZoomId,VCID FROM table WHERE RecordedURL IS NULL and   ZoomId is not NULL and Isnull(VCCancel,0)=0  and Year(date)=2025 and date<='2025-03-10'"; // Replace with your table and column names
            SqlCommand command = new SqlCommand(query, connection);

            connection.Open();
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                zoomIds.Add(reader["ZoomId"].ToString());
            }

            reader.Close();
        }

        return zoomIds;
    }

    private void UpdateDatabaseWithDownloadUrl(string zoomId, string downloadUrl)
    {
        using (SqlConnection connection = new SqlConnection(_connectionString))
        {
           
            string query = "UPDATE table SET NWDownloadURL = @DownloadUrl WHERE ZoomId = @ZoomId"; // Replace with your table and column names

            SqlCommand command = new SqlCommand(query, connection);
            command.Parameters.AddWithValue("@DownloadUrl", downloadUrl);
            command.Parameters.AddWithValue("@ZoomId", zoomId);

            connection.Open();
            command.ExecuteNonQuery();
        }
    }
}

}
class JsonResponse_RecordingVC1
{
public string uuid { get; set; }
public string id { get; set; }
public string account_id { get; set; }
public string host_id { get; set; }
public string topic { get; set; }
public Int16 type { get; set; }
public string start_time { get; set; }
public string timezone { get; set; }

    public string host_email { get; set; }
    public Int16 duration { get; set; }
    public Int64 total_size { get; set; }
    public Int16 recording_count { get; set; }

    public string share_url { get; set; }

    public List<clsJsonRecording_files1> recording_files { get; set; }

    public string password { get; set; }
}
public class clsJsonRecording_files1
{
    public string id { get; set; }
    public string meeting_id { get; set; }
    public string recording_start { get; set; }
    public string recording_end { get; set; }
    public string file_type { get; set; }
    public string file_extension { get; set; }
    public Int64 file_size { get; set; }
    public string play_url { get; set; }
    public string download_url { get; set; }
    public string status { get; set; }
    public string recording_type { get; set; }

    
}