brevo-node icon indicating copy to clipboard operation
brevo-node copied to clipboard

TypeError: Cannot read properties of undefined (reading 'AccountApi')

Open pullmann4rent opened this issue 1 year ago • 1 comments

Hello,

I get error:

TypeError: Cannot read properties of undefined (reading 'AccountApi')

Why I am getting this error ?

import { ActionArgs, json } from "@remix-run/node";
import SibApiV3Sdk from '@getbrevo/brevo';

let apiInstance = new SibApiV3Sdk.AccountApi();

apiInstance.setApiKey(SibApiV3Sdk.AccountApiApiKeys.apiKey, 'xxxx')

export const action = async ({ request, params }: ActionArgs) => {
  try {
    const formData = await request.formData();

    let c1 = new SibApiV3Sdk.ContactsApi();

    const c2 = new SibApiV3Sdk.CreateContact();

    c2.email = formData.get('email');
    c2.listIds = [2];

    const d = await c1.createContact(c2);

    console.log(d);

  } catch(e) {
    console.log(e);
    return json({err: 'err'});
  }
};

pullmann4rent avatar Apr 02 '24 02:04 pullmann4rent

You need to change your ES module import to:

import * as SibApiV3Sdk from "@getbrevo/brevo";

And you should no longer face this error.

ryanschiang avatar Apr 17 '24 16:04 ryanschiang

Hello @pullmann4rent You can see our example here: https://github.com/getbrevo/brevo-node?tab=readme-ov-file#get-account-api-example I have updated it recently.

shubhamUpadhyayInBlue avatar Jun 11 '24 14:06 shubhamUpadhyayInBlue