Requesting Access Token through Jquery AJAX

Hi following is my code through which i am using to try to get the access toke but i am getting error
"Access to XMLHttpRequest at ‘https://zoom.us/oauth/token’ from origin ‘https://zoomintegration20200625133511.azurewebsites.net’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: It does not have HTTP ok status.

AquiredCode.html?code=hupsBKg4H2_ILzNuuO2QhCiTOvJlmEXog:92 {readyState: 0, getResponseHeader: ƒ, getAllResponseHeaders: ƒ, setRequestHeader: ƒ, overrideMimeType: ƒ, …}
jquery.min.js:2 POST https://zoom.us/oauth/token net::ERR_FAILED’

(Document).ready(function () { var code = getUrlParameter('code'); if (code.length > 0 && code != undefined) { (’#codeheading’).text(code);
GetToken(code);
}

    });
    function GetToken(code) {
        var clientID = 'xxxxxxxxxxxxxx6Q';
        var clientSecret = 'xxxxxxxxxxxxxxxxxxxxUr0'; 
        $.ajax({
            type: 'POST',
            url: 'https://zoom.us/oauth/token',
            crossDomin: true,
            headers: {
                'Authorization': 'Basic ' + btoa(clientID +':'+ clientSecret)
            },
            data: {
                'grant_type': 'authorization_code',
                'code': code,
                'redirect_uri': '..../AquiredCode.html'
            },
            success: function (data) {
                $('#codeheading').text(JSON.stringify(data));
            },
            error: function (error) {
                console.log(error);
            }
        });
    }
1 Like

Hey @umarzaman_1,

As our OAuth docs state, you cannot call the Zoom API from the client side. You can use server side code like Node.js to make calls to the Zoom API.

Thanks,
Tommy

1 Like

Thanks for your reply Tommy. I was able to achieve it using RestSharp client in Webapi 2.0.

2 Likes

You are welcome! Happy to hear you got it working! :slight_smile:

Thanks,
Tommy

Hi Understand zoom API couldn’t be called from client side like xhr or jquery .

But Why ? Like what If i still want to use it… i have simple html , Js static page & wan’t to get files using the list files api but getting this preflight cross origin error :frowning:

Hey @ofd.aws96,

The majority of APIs require server side or else you will get CORs errors.

Please educate here on the topic:

Thanks,
Tommy