Good morning,
In Contact module form I have a custom field called “PartitaIVA”.
I need to retrieve this field reading Orders collection in http-functions.
Since the contact ID is clear in the Orders collection, i get the custom field “PartitaIva” using
wixCrm.getContactById, but it doesn’t work. I can’t read any field, not only the custom one.
The same code works good in any front-end call, but not in the backend section.
Here is my code:
export function get_OrderContactInfo(request) {
let options = {
"headers": {
"Content-Type": "application/json"
}
};
let opzioni = {
"suppressAuth": true,
"suppressHooks": true
};
let orderslist = wixData.query("Stores/Orders");
// query a collection to find matching items
return orderslist
.find(opzioni)
.then( (results) => {
// matching items were found
let contactinfo = [];
if(results.items.length > 0) {
for (var i = 0; i < results.items.length; i++) {
let idx = results.items[i].buyerInfo.id;
//contactinfo[i] = idx; IF I RETURN IDX, THE VALUE IS DISPLAYED
wixCrm.getContactById(idx).then((res) => {
contactinfo[i] = res.PartitaIVA;
});
}
options.body = {
"Contacts Partita Iva ": contactinfo
};
return ok(options);
}
options.body = {
"Errore": '-2; Nessun ordine trovato'
};
return notFound(options);
} )
// something went wrong
.catch( (error) => {
options.body = {
"Errore": error
};
return serverError(options);
} );
}
This is the execution result:
{"Contacts Partita Iva ":[]}
What it’s wrong? Any suggestion?
And in general how to manage Contacts in backend section?
Thank you in advance.