huawei-developersappgallery-connect

Is it possible to use Huawei developer API via Google Apps Script?


1 According to this guide I created API Client;

2 I try to run this Apps Script to get access token and get error 502.

var url = "https://connect-api.cloud.huawei.com/api/oauth2/v1/token";

  var options =
  {
    "method" : "POST",
    "contentType" : "application/json",    
    "payload" : {
      "grant_type" : "client_credentials",
      "client_id" : "700000000000000000",
      "client_secret" : "4*********************A"
    }
  };

  var response = UrlFetchApp.fetch( url, options);
  Logger.log(response);

Is anybody can test this small code? Have you propositions?


Solution

  • Fixed!

    var url = "https://connect-api.cloud.huawei.com/api/oauth2/v1/token";  
      var options =
        {
          method : "POST",
          contentType : "application/json",
          payload:JSON.stringify({
            "grant_type":"client_credentials",
            "client_id":"000000000000000000",            
            "client_secret":"LONG_STRING"
          })      
        };
    
      var response = UrlFetchApp.fetch( url, options);
      var access_token = JSON.parse(response.getContentText()).access_token;