google-api-nodejs-client icon indicating copy to clipboard operation
google-api-nodejs-client copied to clipboard

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

Open ebitogu opened this issue 3 years ago • 1 comments

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?

ebitogu avatar Jun 19 '22 08:06 ebitogu

try changing "topicType": "OFFER" to "topicType": "STANDARD"

fontno avatar Jul 03 '24 17:07 fontno