0

I am new with Google API and I'm trying to connect my web site which is in another google cloud server, running on Django to my Google DataProc Cluster. All but errors until now. Here is my code:

   <script src="https://apis.google.com/js/api.js"></script>
   <script>
   var parameters={
   "projectId": "product-994",
   "job": {
   "placement": {
   "clusterName": "cluster-s1"
    },
    "reference": {
    "jobId": "7d77a545-b523-4694-b971-3d17dc0ae4f1"
     },
    "pysparkJob": {
    "mainPythonFileUri": "gs://my-directory/list-tables.py"
     }}};
     function start() {
     gapi.client.init({
     'apiKey': 'my_api_key',
     'clientId':'myIDohmemne7hanb2d8.apps.googleusercontent.com',
     'scope':['https://www.googleapis.com/auth/cloud-platform'],
      }).then(function() {
      return gapi.client.request({
      'path':'https://dataproc.googleapis.com/v1beta2/projects/produc-994/regions/global/jobs:submit/',
      'method':'POST',
      'body':parameters,
    })
  }).then(function(response) {
    console.log(response.result);
    alert(response.result);
  }, function(reason) {
    console.log('Error: ' + reason.result.error.message);
  });
  };
  gapi.load('client', start);
  </script>

But I get this error:

   Uncaught TypeError: a.split is not a function
at pZ (https://apis.google.com/_/scs/apps-static/_/js/k=oz.gapi.es.v_tOK2w_1HY.O/m…1/ed=1/am=AQ/rs=AGLTcCM1W2y9cMgCwSVCS8oWU4_pdItscw/cb=gapi.loaded_1:87:396)    

Until now I have used: https://developers.google.com/api-client-library/javascript/reference/referencedocs; https://cloud.google.com/dataproc/docs/quickstarts/quickstart-explorer-submit; https://developers.google.com/api-client-library/javascript/start/start-js; https://developers.google.com/analytics/devguides/reporting/core/v3/quickstart/web-js?hl=fr. But non of this has worked

1 Answers1

0

I'd recommend validating your basic flow through Google's Cloud Console first, using the official UI to submit jobs to your cluster. On the Job submission page, there's a link near the bottom left that says "Equivalent REST"; if you click that, it will pop up the low-level HTTP path, method, and body that you would need to post to make sure you have the right syntax.

You should also incrementally start with getting something more simple like a "list" call to work before trying to submit a job from javascript.

Also, it appears you're posting to "v1beta2", you should probably post to "/v1/" instead; I'm curious where you found the "v1beta2" reference if any, since that version very well may be broken at the moment, and shouldn't have really been advertised for non-testing usage.

You also have a typo in your example code, /projects/produc-994 instead of product-994, but maybe that was just a typo in translating to an SO question.

Dennis Huo
  • 10,517
  • 27
  • 43
  • Thanks Dennis the typo error was in typing the question... the V1beta2 I get it from the official page of Dataproc API but I could change it. But could you please explain to me what is "list" call? – Abel Buriticá Jul 18 '17 at 14:23
  • A basic GET on something like `https://dataproc.googleapis.com/v1/projects/product-994/regions/global/clusters` (with your valid auth headers) should return a list of clusters, or `/jobs` for a list of jobs. – Dennis Huo Jul 18 '17 at 18:15