How to use the Google chat /messages:search REST API endpoint?

Hi.

I’m trying to create an app that performs a simple search of the messages in one of my team’s Google Chat spaces using the following REST API:
https://developers.google.com/workspace/chat/api/reference/rest/v1/spaces.messages/search

(Note: The docs say this endpoint is part of the Google Workspace Developer Preview Program. I have an email confirming that the project I’m using the credentials from is associated with the preview program.)

Sample code below. Am I missing something obvious here?

Any help would be greatly appreciated!

The sample Node.js code below shows what I’ve tried so far:

  • - The call to the /messages endpoint successfully returns messages, so that implies the space ID is right and authentication works, yes?
  • - The call to /messages:search gets HTTP 400
import { authenticate } from "@google-cloud/local-auth";
import ax from "axios";

const auth = await authenticate({ 
  "keyfilePath" : "<where-I-downloaded-credentials-file>",
  "scopes"      : [ "https://www.googleapis.com/auth/chat.messages.readonly" ]
});
const token_response = await auth.getAccessToken();
const access_token = token_response.token;
const config  = { "headers" : { "Authorization" : "Bearer " + access_token } };
const body = { "filter" : "deadlines" };
const url = "https://chat.googleapis.com/v1/spaces/<space-ID>";
let res;

try
{
  //res = await ax.get(  url + "/messages?pageSize=2", config ); // <-- WORKS
  res = await ax.post( url + "/messages:search", body, config ); // <-- FAILS
  console.log( res );  
}
catch( err )
{
    console.log( err );
}

According to the following guide:

…your space id must be a “-” for that specific endpoint. So you’ll need to change the base url.