Home > Blockchain >  Google Chat API. Can’t create space. Method not found
Google Chat API. Can’t create space. Method not found

Time:06-28

I'm trying to create a google chat space via making a post request to https://chat.googleapis.com/v1/spaces with Guzzle.

        $scopes = [
            'https://www.googleapis.com/auth/chat.spaces.create',
            'https://www.googleapis.com/auth/chat.bot'
        ];

// create middleware
        $middleware = ApplicationDefaultCredentials::getMiddleware($scopes);
        $stack = HandlerStack::create();
        $stack->push($middleware);



// create the HTTP client
        $client = new Client([
            'headers' => ['Content-Type' => 'application/json'],
            'handler' => $stack,
            'base_uri' => 'https://www.googleapis.com',
            'auth' => 'google_auth'  // authorize all requests
        ]);


// make the request
       $response = $client->post( 'https://chat.googleapis.com/v1/spaces', [
            RequestOptions::JSON => [
                'name' => 'ABCDEFG',
                'spaceType' => 'DIRECT_MESSAGE',
                'threaded' => false,
                'displayName' => 'TestSpace'
            ],
        ]);

In response I'm getting:

Client error: `POST https://chat.googleapis.com/v1/spaces` resulted in a `404 Not Found` response:
{
  "error": {
    "code": 404,
    "message": "Method not found.",
    "status": "NOT_FOUND"
  }
}

But if I change the body of the request and add some new invalid fields like this:

       $response = $client->post( 'https://chat.googleapis.com/v1/spaces', [
            RequestOptions::JSON => [
                'name' => 'ABCDEFG',
                'spaceType' => 'DIRECT_MESSAGE',
                'threaded' => false,
                'displayName' => 'TestSpace',
                'foo' => 'bar',    //added invalid field 
            ],
        ]);

I'm getting the next response:

Client error: `POST https://chat.googleapis.com/v1/spaces` resulted in a `400 Bad Request` response:
{
  "error": {
    "code": 400,
    "message": "Invalid JSON payload received. Unknown name \"foo\" at 'space': Cannot find field.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "field": "space",
            "description": "Invalid JSON payload received. Unknown name \"foo\" at 'space': Cannot find field."
          }
        ]
      }
    ]
  }
}

docs: https://developers.google.com/chat/api/reference/rest/v1/spaces/create

What’s wrong with my original request? Thanks.

CodePudding user response:

The API method which accepts the POST is spaces.create and not spaces.

CodePudding user response:

The spaces.create documentation explains this at the top of the page:

Developer Preview: Available as part of the Google Workspace Developer Preview Program, which grants early access to certain features.

This means that the method is only available for users in Google's Developer Preview Program, which seems kind of like a closed beta for some developer features. The link above has a form that you can fill out to join this program, though do note that you also need to be part of the Google Cloud Partner Advantage program to apply.

In short, the method was released not long ago, and is not currently available for everyone. There's also an official blog post explaining this. It may become public in the future, so you'll have to either wait or fill out the applications to become a partner and then join the developer preview.

If you happen to be part of the program already and are still having issues you probably won't find answers among us commoners. You'd want to check out the Partner Advantage support to make sure that the features were enabled for your domain. The developer program documentation above also has a link to the issue tracker to send feedback about this API. You'll only be able to do this as a member, of course.

  • Related