Reputation: 2610
I'm trying to create a contact from my application and documentation is hideous!
i build a contact object from data i receive by form
var contact = {
names: [
{
displayName: body.name
}
],
phoneNumbers: [
{
value: body.phone
}
],
biographies: [
{
value: body.notes
}
],
userDefined: [
{
value: body.snif
},
{
value: body.position
},
{
value: body.sms
},
{
value: body.whatsapp
}
]
};
and try to make the request but i can't figure out what's wrong
const service = google.people({version: 'v1', auth});
service.people.createContact({
parent: 'people/me',
resource: contact
}, {}, function(err, res) {
console.log(err)
});
and i get 400 INVALID_ARGUMENTS
errors:
[ { message: 'Request contains an invalid argument.',
domain: 'global',
reason: 'badRequest' } ] };
Nodejs, ExpressJs
please what am i doing wrong?
Upvotes: 1
Views: 411
Reputation: 201378
How about this modification?
userDefined
, please add a property of key
.
Please modify userDefined
as follows. These are sample keys. So please modify them for your situation.
userDefined: [
{
value: body.snif,
key: "snif", // Added
},
{
value: body.position,
key: "position", // Added
},
{
value: body.sms,
key: "sms", // Added
},
{
value: body.whatsapp,
key: "whatsapp", // Added
},
],
Also if you want to retrieve the response from API, how about modifying as follows?
service.people.createContact({
parent: 'people/me',
resource: contact,
}, {}, function(err, res) {
if (err) {
console.log(err.errors);
return;
}
console.log(res.data);
});
If I misunderstand your question, please tell me. I would like to modify it.
Upvotes: 2