I have the following code to create a new Call-To-Action post for a Google My Business Location as shown below:
const { google } = require('googleapis');
let locationURL = `https://mybusiness.googleapis.com/v4/accounts/${accountId}/locations/${locationId}/localPosts`
let requestBody = {
"languageCode": "en-US",
"summary": "Test Call to action Post",
"callToAction": {
"actionType": "SIGN_UP",
"url": "http://www.example.com",
},
"topicType": "OFFER"
}
let googleOAUTH2Client = new google.auth.OAuth2(process.env.GOOGLE_APP_CLIENT_ID,
process.env.GOOGLE_APP_CLIENT_SECRET);
googleOAUTH2Client.setCredentials(credentials); //Credentials code redacted
try {
let locationRes = await googleOAUTH2Client.request({
url: locationUrl,
method: 'POST',
body: JSON.stringify(requestBody)
});
let { data } = locationRes;
console.log(`ResponseData=${data, null, 2}`);
} catch (e) {
let err = e?.response?.data
console.log(JSON.stringify(err, null, 2));
}
But all I keep getting back is the error message below:
{
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"errors": [
{
"message": "Request contains an invalid argument.",
"domain": "global",
"reason": "badRequest"
}
],
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.mybusiness.v4.ValidationError",
"errorDetails": [
{
"code": 2,
"field": "event",
"message": "event is required"
}
]
}
]
}
}
Which got me wondering. Why is event required for a Call to Action Post?. The Docs never made any mention of that in the sample codes.
How do I resolve this?
Add an event
(see event
) for topic types EVENT
and OFFER
.
The Docs that you reference appear incomplete.
Google APIs Explorer is (always) your friend.
Search "my business" to get to Business Profile APIs.
Then localPost
is the method that you're using to see definitive documentation.
The request body is type LocalPost
and this describes event
with the requirement mentioned above:
Event information. Required for topic types EVENT and OFFER.
Google provides SDKs (called "libraries") for all its services in several languages including Node.js. For Business Profile APIs, you'll want to use Node.js API Client Library