Can't access member custom fields in code

I added custom fields to my members via the wix dashboard, but they’re not loading with the API.

I have several custom fields that I added in the dashboard:
“Subscribed To Announcements”, “Subscribed to Newsletter”.

Since wix doesn’t allow boolean custom fields, I’m creating my own UI with checkboxes to update these custom member fields.

When I try to load the fields with this code, the customFields object is just empty.

let response = await members.getCurrentMember({fieldsets: ['FULL']});
console.log(Object.keys(response.member.contact.customFields));
console.log("----");
console.log(response.member.contact);

Result:
[]
----
{
  "contactId": "redacted",
  "firstName": "redacted",
  "lastName": "redacted",
  "phones": [],
  "emails": [
    "redacted"
  ],
  "addresses": [],
  "customFields": {}
}

How do I access my custom fields?

Product:
Wix Editor

What are you trying to achieve:
I am trying to access and update my member’s custom fields with code.

What have you already tried:
I’ve looked at some forum posts, but none of them have this issue. Other user’s custom fields are returned in the javascript object.

I have tried using the wix-members-frontend and wix-members.v2 libraries to access the current user, I can’t load the custom fields.

I figured out the problem. I had these fields “hidden” so they were not loading by the API.

But I have them hidden because I don’t want them to appear in wix’s default member profile editor.

I figured out this can be done through the wix-crm API. Not the wix-members API.

This code works. The wix-crm only works on the backend, so this code has to be in a backend module.

import { Permissions, webMethod } from "wix-web-module";
import { members } from "wix-members.v2";
import { elevate } from "wix-auth";
import { contacts } from 'wix-crm.v2';

export const getContact = webMethod(
  Permissions.SiteMember,
  async () => {
    let getUserDetails = elevate(async () => {
      let response = await members.getCurrentMember({fieldsets: ['PUBLIC']});
      let member = response.member;
      return await contacts.getContact(member.contactId, {fieldsets: ['FULL']});
    });
    return await getUserDetails();
  }
);

Then on the front-end

import { getContact } from "backend/subscription.web";

$w.onReady(async function () {
	console.log(await getContact());
});

---------------
Result:
{
  "revision": 12,
  "info": {
    "extendedFields": {
      "items": {
        "custom.yourcustomfield1": 1,
        "custom.yourcustomfield2": 1,
      }
    }
  }
}

The CRM API returns a lot more information, in the above example I left most of the info out to just show the custom fields.