Help! Trying to update Account Module via website in Javascript, and its creating a new entry

Help! Trying to update Account Module via website in Javascript, and its creating a new entry

Hi there,

We are using Javascript on our website and trying to update a record in the Account module when someone updates their  business details. Our code is as follows:

const updateZohoAccountForClientUser = tryCatchWrapper(
  async (userId: string) => {
    const user = await User.findById(userId);
    if (!user) return;

    const zohoAccountId = user?.zohoAccountId;

    const zohoAccessToken = await generateAccessTokenFromRefreshTokenForZoho();
    const url = ${zohoModuleUrl}/crm/v2/Accounts/upsert;

    const requestBody = {
      data: [
        {
          id: zohoAccountId,
          Account_Name: user.businessName,
          Business_Industry: user.businessIndustry,
          I_am: user.businessRole,
          Last_Name: user.lastName,
          First_Name: user.firstName,
          Email: user.email,
          Phone: user.phone.startsWith("+1")
            ? user.phone.substring(2)
            : user.phone,
          Country: user.businessCountry,
          Unit_no: user.businessUnitNumber,
          Street: user.businessAddress,
          City: user.businessCity,
          Province: user.businessProvince,
          Postal_Code: user.businessPostalCode,
          Record_Image: getUrlForBrand({
            businessName: user.businessName,
            fileName: user.logoUrl ?? "",
          }),
          Account_Status: user.isEmploymentVerified
            ? "Verified"
            : user.employmentDocs.length > 0
            ? "Review Required"
            : "Verification Required",
          Estimated_amount_of_checks_per_year: user.reportsRequired,
        },
      ],
      trigger: ["approval", "workflow", "blueprint"],
      duplicate_check_fields: ["id"],
    };

    const { data } = await axios({
      url,
      method: "post",
      data: JSON.stringify(requestBody),
      headers: {
        Authorization: Zoho-oauthtoken ${zohoAccessToken},
      },
    });

    console.log(JSON.stringify(data));

    return data;
  }
);


We are getting a success result in our log

{"data":[{"code":"SUCCESS","action":"update","details":{"Modified_Time":"2023-12-15T10:39:12-08:00","Modified_By":{"name":"ME","id":"IDNUMBER"},"Created_Time":"2023-12-14T22:54:25-08:00","id":"IDNUMBER","Created_By":{"name":"ME","id":"IDNUMBER"}},"message":"record updated","status":"success"}]}

(I have edited my name/id numbers in the success message)

The problem is, it is updating the current record, however it is also creating a duplicate of the record Account name (but no other account details such as first name, etc). Only the account name is being populated in the new record.

Have spent a considerable amount of time trying to debug this - any help would be greatly appreciated!

Thank you

    Access your files securely from anywhere

        Zoho Developer Community




                                  Zoho Desk Resources

                                  • Desk Community Learning Series


                                  • Digest


                                  • Functions


                                  • Meetups


                                  • Kbase


                                  • Resources


                                  • Glossary


                                  • Desk Marketplace


                                  • MVP Corner


                                  • Word of the Day



                                      Zoho Marketing Automation


                                              Manage your brands on social media



                                                    Zoho TeamInbox Resources

                                                      Zoho DataPrep Resources



                                                        Zoho CRM Plus Resources

                                                          Zoho Books Resources


                                                            Zoho Subscriptions Resources

                                                              Zoho Projects Resources


                                                                Zoho Sprints Resources


                                                                  Qntrl Resources


                                                                    Zoho Creator Resources



                                                                        Zoho Campaigns Resources


                                                                          Zoho CRM Resources

                                                                          • CRM Community Learning Series

                                                                            CRM Community Learning Series


                                                                          • Kaizen

                                                                            Kaizen

                                                                          • Functions

                                                                            Functions

                                                                          • Meetups

                                                                            Meetups

                                                                          • Kbase

                                                                            Kbase

                                                                          • Resources

                                                                            Resources

                                                                          • Digest

                                                                            Digest

                                                                          • CRM Marketplace

                                                                            CRM Marketplace

                                                                          • MVP Corner

                                                                            MVP Corner





                                                                              Design. Discuss. Deliver.

                                                                              Create visually engaging stories with Zoho Show.

                                                                              Get Started Now