Wix contacts extended fields are not saved

Hi there.

I am working on a site where we save the members as contacts also. We have some custom fields (tax username and tax password). However, somehow the code to save them does not work. I am a full stack developer, but I am new to Wix Velo.

Here is the function that is supposed to save the fields, in the backend code:

import { contacts } from 'wix-crm-backend';
import { members } from 'wix-members-backend';

export async function addCredentialsToContact(userId, revision, taxUsername, taxPassword) {
    try {
        // Saving the contact tax auth infos
        const contactIdentifiers = {
            contactId: userId,
            revision: revision
        };

        const contactInfo = {
            extendedFields: {
                "Tax Authority Username": taxUsername,
                "Tax Authority Password": taxPassword
            }
        };

        const options = {
            allowDuplicates: false,
            suppressAuth: true
        };

        const updatedContact = await contacts.updateContact(contactIdentifiers, contactInfo, options);

        return updatedContact;

        // I also tried with members API
        // const memberInfo = {
        //     contactDetails: {
        //         customFields: {
        //             "custom.taxAuthorityUsername": taxUsername,
        //             "custom.taxAuthorityPassword": taxPassword,
        //             "Tax Authority Username": taxUsername,
        //             "Tax Authority Password": taxPassword
        //         }
        //     }
        // };

        // const updatedContact = await members.updateMember(userId, memberInfo);

        // return updatedContact;
    } catch (error) {
        console.log(error);

        throw error;
    }
}

Here is the function on the frontend that send the data

import { addCredentialsToContact, getContact } from 'backend/users';

export async function submitButton_click(event) {
    try {
        // Form validation: 
        if (!$w('#usernameInput').valid ||
            !$w('#passwordInput').valid ||
            !$w('#captcha3').token ||
            !$w('#checkbox1286').checked ||
            !$w('#tosCheckbox').checked) {
            return false;
        }

        // Preserve our values as dataset.save() will reset them
        const username = $w("#usernameInput").value;
        const password = $w("#passwordInput").value;

        $w('#submitButton').disable();

        $w("#dataset3").onAfterSave(async () => {
            /*
             * Update contact by adding tax credentials
             */
            let userData = await wixMembers.currentMember.getMember();
            
            let contact = await getContact(userData.contactId);

            // Save the credentials to the user's contact
            const updatedContact = await addCredentialsToContact(userData.contactId,
                contact.revision,
                username,
                password);

            // redirecting after 10sec
            setTimeout(function () {
                wixLocation.to("/account/tax-forms")
            }, 10000);

        });

        $w("#dataset3").save();
    } catch (error) {
        console.log("submitButton click error:", error);
    }
}

Thank you for your assistance. I am certain I am making something wrong here, but I cannot find what exactly.

Stephane

// I also tried with members API // const memberInfo = {// contactDetails: {// customFields: {// “custom.taxAuthorityUsername”: taxUsername,// “custom.taxAuthorityPassword”: taxPassword,// “Tax Authority Username”: taxUsername,// “Tax Authority Password”: taxPassword// }// }// };

I have the same issue using the API. It just gives me the error " Extended fields not found" did you find a solution?

Turns out that the keys to be lower case only. e.g. “custom.taxauthorityusername” not “custom.taxAuthorityUsername”