APIs & Integrations

TSpooner5
Membre

Marketing Events API Methods Not Working

I'm using the "Get a marketing event" endpoint in the Marketing Events API but the method shown in the documentation isn't working, paritcuarly the following part of the example: 

 

 

const apiResponse = await hubspotClient.marketing.events.marketingEventsExternalApi.getById(externalEventId, externalAccountId);
console.log(JSON.stringify(apiResponse, null, 2));

 

 

 The call throws the following error: 

 

 

Error: TypeError: hubspotClient.marketing.events.marketingEventsExternalApi.getById is not a function

 

 

 If you look at the prototypes for marketingEventsApi, using the following, getById() isn't listed: 

 

 

console.log(Objects.getOwnPropertyNames(Object.getPrototypeOf(hubspotClient.marketing.events.marketingEventsExternalApi)));

 

 

Instead, the following is returned in the logs: 

 

 

INFO [ 'constructor', 'completeWithHttpInfo', 'complete' ]

 

 

Is this is an error in the documentation or am I doing something wrong? I already verified that the right scopes are enabled in the private app. I also couldn't find anything online saying the method was deprecated. Please help!  

0 Votes
3 Réponses
dsmarion
Contributeur de premier rang | Partenaire solutions Gold
Contributeur de premier rang | Partenaire solutions Gold

Marketing Events API Methods Not Working

dsmarion_0-1713445084167.png

https://developers.hubspot.com/docs/api/marketing/marketing-events

Scott Marion
Senior Developer @ Thread Connected Marketing
EddBrisley
Contributeur

Marketing Events API Methods Not Working

Hi @TSpooner5 

 

Interesting one! 

 

Have you tried the search endpoint instead?

 

Generally the way I've found around the "is not a function" error is by structuring my request a bit differently. So if this code below doesn't work immediately (with the search endpoint), I'd try using the original GET endpoint you're using, then adding in the externalAccountId using the same structure as below. 

 

const axios = require('axios');

exports.main = async (event, callback) => {
    const queryParam = '01010101010101010'; // Just the eventId, not the externalAccountId

    const hubspotApiKey = "Your secret";
    const options = {
        method: 'GET',
        url: `https://api.hubapi.com/marketing/v3/marketing-events/events/search?q=${queryParam}`,
        headers: {
            Authorization: `Bearer ${hubspotApiKey}` 
        }
    };

    let responseData = null;

    try {
        const response = await axios(options);
        responseData = response.data;
        console.log(responseData);
        
    } catch (error) {
        console.error('Error:', error);
        throw error;
    }

    callback({
        outputFields: {
            responseData: JSON.stringify(responseData)
        }
    });
};

 

Let me know if it works, got everything crossed for you! 🤞

Edd

TSpooner5
Membre

Marketing Events API Methods Not Working

Thanks, Edd! I tried this, and it's successful; however, it's not returning the JSON for the Marketing Event that I'm querying with the queryParam constant. Here's the log: 

 

INFO { results: [] }

 

Also, can you provide a little clarity to this remark?

  • "I'd try using the original GET endpoint you're using, then adding in the externalAccountId using the same structure as below."

What would the syntax be for using the getById() method? Or perhaps I'm misunderstanding you. Thanks again for your response!