googleapis / googleapis/google-api-nodejs-client

Event is required Error for Call-To-Action Post in Google My Business API

Open
#3,007 1 comment 0 reactions 0 assignees View on GitHub
priority: p3 type: question
Dominant language
TypeScript
Stars
12.2k
Forks
2k
Avg merge
1d 9h
Merged PRs (30d)
24

Description

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][1] never made any mention of that in the sample codes.

How do I resolve this?

[1]: https://developers.google.com/my-business/content/posts-data#call_to_action_posts

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.