Closed justinbalaguer closed 2 years ago
Hey @justinbalaguer
Visit this API Guides - Contact Management page which provides detailed information, step by step, on how need to work with Contacts, Contact properties, Contact lists and many other useful things.
I reproduced this error and I'm getting the same error message when I pass the contactsListID
which does not exist.
You receive this error because you pass the incorrect id (contactListId
- <id-here-eg-1234567>
) in the request.
Before sending a request you should be sure that you use the correct id and this code snippet should help you to do it:
const mailjet = new Mailjet(
process.env.MJ_APIKEY_PUBLIC,
process.env.MJ_APIKEY_PRIVATE
)
const request = mailjet
.get("contactslist", { version: 'v3' })
.request()
.then((result) => {
console.dir(result.body, { depth: 10 })
})
// response
/*
[Object: null prototype] {
Count: 2,
Data: [
[Object: null prototype] {
Address: 't932ebgje',
CreatedAt: '2022-04-12T16:12:47Z',
ID: 13328,
IsDeleted: false,
Name: 'MyFirstTest',
SubscriberCount: 2
},
[Object: null prototype] {
Address: 't4ydo1hwu',
CreatedAt: '2022-04-12T16:45:03Z',
ID: 13569,
IsDeleted: false,
Name: 'Test list',
SubscriberCount: 2
}
],
Total: 2
}
*/
The other important things:
On the API Reference page, which is the API documentation for the resource which you use /contactslist/{list_ID or list_address}/managecontact
, you can see this description:
Manage the presence and subscription status of a contact to a specific contact list. The API will internally create the new contact if it does not exist, as well as add or update the name and properties.
And this means that you can provide any an email, even if contact with this email does not exist in your contacts. For this reason, the following code snippet works without any errors (I haven't contact with the following email):
const mailjet = new Mailjet(
process.env.MJ_APIKEY_PUBLIC,
process.env.MJ_APIKEY_PRIVATE
)
const response = await mailjet
.post('contactslist', { version: 'v3' })
.id(13328) // ID that is equal to 'MyFirstTest' contact list
.action('managecontact')
.request({
Name: 'John Smith',
Action: 'addnoforce',
Email: 'passenger@mailjet.com',
});
// response
/*
[Object: null prototype] {
Count: 1,
Data: [
[Object: null prototype] {
ContactID: 74690846,
Email: 'passenger@mailjet.com',
Action: 'addnoforce',
Name: 'John Smith',
Properties: [Object: null prototype] {}
}
],
Total: 1
}
*/
@scroll17 doing this, its just an empty array for my other account im using (old account), however using my new account shows an array in data.
const request = mailjet
.get("contactslist", { version: 'v3' })
.request()
.then((result) => {
console.dir(result.body, { depth: 10 })
})
I think I figured it out, sub-account api key doesn't allow it right?
Hello @justinbalaguer
I'm not sure about the Sub-account opportunity to do it but you can ask about it to Support Team (link below).
And about "empty array": I think that you could actually have an empty contacts list array in the old account but in the new account, you already have a not empty because on the page Get Started Mailjet
team provide a step by step useful example for Send your first email where you send your first email and the same time you create new contacts and contact list too.
You can use a web version for control Contacts, Contact properties, Contact lists and etc. by this links:
And you should explore the Mailjet
web version where you can find different features which you can use via browser
or directly via API
, fox example:
Helpful materials about Sub-account
:
And in this article "Simplified Collaboration Using Sub-accounts With Mailjet" from Mailjet
blog said that:
That’s where sub-accounts come in handy. They let you manage multiple different accounts (or API keys) under one master account. If you’re an agency, you can separate clients. If you send both marketing and transactional emails, you can separate lists and templates.
Work together more easily with your colleagues or your clients by giving them access to your sub-accounts, while keeping an eye on their campaigns.
In general, you can contact our Support Team for more detailed information and troubleshooting.
{ "ErrorInfo" : "", "ErrorMessage" : "Object not found", "StatusCode" : 404 }
however when I tested this on my newly created account and using the id e.g
.id('12345')
if perfectly works. p.s: also tried using the mailjet address - didn't work