400 Bad Request error in c#

Hi i am having an issue when trying to get an access token in my program. i am using Visual Studio 2022 and this is the code i have so far:
i have blanked out the client id and client secret just for security purposes.

        HttpClient Authclient = _httpClientFactory.CreateClient();
        Authclient.BaseAddress = new Uri("https://zoom.us/oauth/authorize?response_type=code&client_id=********&redirect_uri=");

        var Authparameters = new Dictionary<string, string> { };
        var AuthencodedContent = new FormUrlEncodedContent(Authparameters);

        var Authresponse = await Authclient.PostAsync(Authclient.BaseAddress, AuthencodedContent);
        HttpResponseMessage? AuthRes = await Authclient!.PostAsync(Authclient.BaseAddress, AuthencodedContent);

        var grant_type = "Authorization Code";
        var client_id = "*********";
        var client_secret = "*******";
        var scope = "";

        var AccessToken = "";

        HttpClient client = _httpClientFactory.CreateClient();
        client.BaseAddress = new Uri("https://zoom.us/oauth/token");

        var parameters = new Dictionary<string, string> { { "grant_type", grant_type }, { "client_id", client_id }, { "client_secret", client_secret }, { "scope", scope } };
        var encodedContent = new FormUrlEncodedContent(parameters);

        var response = await client.PostAsync(client.BaseAddress, encodedContent);
        HttpResponseMessage? Res = await client!.PostAsync(client.BaseAddress, encodedContent);

i am getting an error with the final final as i am getting an error 400 Bad request.

im not sure whats wrong as i have tested all this in postman and managed to get it to work so not sure ehats causing the issue.

any help would be appreciated.

Thanks

For one thing, try grant_type = "authorization_code" instead of "Authorization Code"

Something about POSTing your client id and secret without encoding it seems very wrong to me; take a look at the C# example (2nd tab) on this documentation.

1 Like

@cletham You should have a look at ZoomNet (disclaimer: I’m the author). It’s a .NET client for Zoom’s API. The authentication process is built-in.

1 Like

Hi Alex

Thanks for the reply i made that change but still getting the same error unfortunately

Hi Jericho thanks for the reply, i had a look at your documentation and confused as i didn’t get a authorization code when i created my app if this is something you know where to find please let me know.

my app currently is just a general app not a server to server app which i think your documentation focuses on. if there’s a version that looks at general app I’m happy to use that

Thanks,
Connor

i didn’t get a authorization code when i created my app

When you created the app you were asked to provide the OAuth redirect URL like so:

When someone adds the app to their account, they get redirected to the URL you configured like so:

The code is right there in the URL.

in your documentation i don’t see a bit to get that code so are you authenticating before that code or just copying in the code into the code?

1 Like

That’s really up to you how you want to do it.

Presumably your redirect URL sends people to a web page that is under your control, where you can write your own code, where you can get the value from the querystring and act appropriately.