Creating a meeting in Jquery

Thanks @gokul,

First of all, calling Zoom APIs via the frontend (jQuery) is not supported. I suggest creating a Node.js server to make http requests to the Zoom API.

What is your full use case so I can provide advice on what type of Zoom App to create (JWT vs. OAuth)?

Nevertheless, I have fixed your code, and now you can get an access_token, but when you call the create meeting endpoint you will get a Invalid CORS request error because we do not support https://cors-anywhere.herokuapp.com/

(function() {

  document.getElementById('join_meeting').addEventListener('click', function(e){
  e.preventDefault();

  const proxyurl = 'https://cors-anywhere.herokuapp.com/';

  var jsonURL = proxyurl + 'https://zoom.us/oauth/token?grant_type=authorization_code&code={{ AUTH CODE FROM URL }}&redirect_uri=https://zoom.us';

  $.ajax({
    url: jsonURL,
    headers: {
      'content-type': 'application/json',
      'Authorization': 'Basic ' + btoa('CLIENT ID' + ':' + 'CLIENT SECRET')
    },
    type: 'POST',
    success: function(data, textStatus, xhr) {
      console.log('Received data is' + data.access_token);

      if (data.access_token) {
        const url = proxyurl + 'https://api.zoom.us/v2/users/me/meetings';

        $.ajax({
          url: url,
          headers: {
            'content-type': 'application/json',
            'X-Requested-With': 'XMLHttpRequest',
            'Authorization': 'Bearer ' + data.access_token
          },
          type: 'POST',
          dataType: 'json',
          data: JSON.stringify({
            topic: 'New Meeting at 2',
            type: 1,
            start_time: '2019-08-22T14:00:00Z',
            duration: 45
          }),
          success: function(data, textStatus, xhr) {
            console.log(data);
          },
          error: function(xhr, textStatus, errorThrown) {
            console.log(xhr);

            console.log('Error in Operation');
          }
        });
      }
    },
    error: function(xhr, textStatus, errorThrown) {
      console.log('Error in Operation');
    }
  });


  });

})();

NOTE: This will only work once right after you “Install” your app via the install button on your Zoom App Dashboard and paste the code you get (in the redirect url after you click the “Authroize” button) to the {{ AUTH CODE FROM URL }} because each time you request a new access_token with the same auth code it will invalidate the access_token. The OAuth flow is meant to be hosted on a server side application and store the access_token and refresh_tokens in a database.

Also, I would not recommend using the https://cors-anywhere.herokuapp.com/ trick to call our APIs on the frontend. Our APIs are meant to be called from server side applications, to ensure security. For example, anyone will be able to see your client id and client secret if you deploy this code.

Let me know if you have any other questions.

Thanks,
Tommy