Querying the custom member fields

Hi all,
I have custom fields for members as outlined in the post below:
https://support.wix.com/en/article/customizing-your-member-profile-fields-7805119

I can see the data on the forms, I can edit it works like a charm. However, when I want to query this data, I cannot find it in both Members/PrivateMembersData and Members/PublicData

I tried to look for it in all the collections but no chance. How can I query the custom member field data using wix-query?

Best,

The member profile information is saved in a different collection from the PrivateMembersData . To have acces to it, you should use WIX CRM Backend API .

So, you need to create a backend file (you can call it anything you want, for ex: members.jsw ), and in there you are going to create a simple function to be exported to your frontend code, like this:

//This imports the contacts object from the API
import { contacts } from 'wix-crm-backend'

//This options allows you to access the data
let options = {
    "suppressAuth": true,
    "suppressHooks": true
}

//This is the function you need to get all contacts
export async function queryAllContacts() {
    const query = await contacts.queryContacts().find(options)
    return query.items
}

After that, you create a code in your frontend (the page you are trying to access the data) that imports this functions and calls it. Like this:

//Importing the function you create in the backend
import { queryAllContacts } from 'backend/member'

//This functions runs after page is loaded
$w.onReady(async () => {
    //You create a variable to store the retrieved data
    const allMembers = await queryAllContacts()
    //Just console.log it.
    console.log(allMembers)
})

And the result is going to be an array with all the members in the site, as objects, and you can access the properties you want, even the extended fields that you created, like this Test custom field that I created:

"extendedFields": {
    "contacts.displayByLastName": "Prado Bruno",
    "emailSubscriptions.deliverabilityStatus": "NOT_SET",
    "members.membershipStatus": "APPROVED",
    "emailSubscriptions.subscriptionStatus": "NOT_SET",
    "custom.test": "Amazing",
    "members.mobile": false,
    "emailSubscriptions.effectiveEmail": "bwprado@gmail.com",
    "contacts.displayByFirstName": "Bruno Prado"
  },

Best regards, and let me know how it went.

Dear Bruno,
Thanks for the information. It worked for me thanks. I was trying to get the details of the loggedin user. I managed to it by querying with email. I got it done.
Thanks,
Cem

Hi, @cematacik , I am having the same problem. Is it possible you share your code for my help …! Actually I am not able to retrieve data as per above code. Please help : )

Hi Bruno Prado, Thanks for this code and comment. I would like to know if it is possible that you can post a complete code retreiving extendedFields as you mentioned above. It will be a big help for me. I have read more that hundreds of pages, I don’t wanna give up. I think this could help me. Thank you : )

@onlinesanawad Dou you use your PROFILE-NOTIFICATION-SECTION?

  1. https://www.wix.com/velo/forum/coding-with-velo/wix-crm-api-not-allowing-me-to-update-contact-information/p-1/dl-61a7af3d72db1700168cf1dc

  2. https://www.wix.com/velo/forum/coding-with-velo/wix-crm-backend-update-giving-errors/p-1/dl-61a7ae0a180f39001860e85f

  3. And there was a third post, i can’t find anymore, where i posted you and got no answer. :roll_eyes:

You should take more often a look onto → PROFILE-NOTIFICATION-SECTION in your ACCOUNT.

@onlinesanawad
You my suggestion would be to open your own post, where you describe your existing issue as most detailed as possible.

  1. How do look like your PROJECT-SETUP?
  2. How do look like your DATABASE(s), related to the issue?
  3. Which ELEMENTS are used?
  4. What are you trying to achieve exactly?
  5. What is the exact problem?
  6. Some screenshots?

The more information you give about your whole issued project, the more help you will get.

Bumping-up old post, won’t help you at all, why?

  1. Poster of old posts, in most cases are not active anymore, and wont’t be able to give you any reasonable answers.
  2. Old post acting with maybe depricated coding stuff from second world-war, who knows! —> NOT UPTODATE ANYMORE.
  3. A helper you recognices that it is an already old and known post may just ignore your help-request, because the helper isn’t realy interested to read old posts.

And there are surely more reasons why you → SHOULDN’T BUMP-UP OLD POST ← - and instead open your own ones.

Oh and just right now, there is another reason which comes into my mind, why it’s better to open own posts.

  1. Once you open your own post, you will always find this post immediately inside your profile if you need to refresh your knowledge.

You won’t find the post that fast again, if you are just commenting on an foreign post.

So → Open your post and let us know about your problem!

You don’t get any answer after days and your post is completely lost in the list?
Now it’s time to bump-up your post again, with the hope → some-body will see your cry for help!

This is how this forum works.

And by the way:
Never forget to give some → LIKES or even a mark for → BEST-ANSWER ← which will encourage your helper maybe to help you again!

There is an updated version for this.

In your backend:

import { contacts } from ‘wix-crm-backend’ ;

export function myGetContactFunction ( id ) {
const contactId = id ;
const options = {
suppressAuth : true
};

return contacts . getContact ( contactId , options )
. then (( contact ) => {
return contact ;
})
. catch (( error ) => {
console . error ( error );
});
}

In the frontend:

import { myGetContactFunction } from ‘backend/contacts.jsw’ ;

//First you need the ID of the user then use this:

let userInfo = await myGetContactFunction ( user . _id );

//Then the custom fields are saved under “extendedFields”:
let extendedFields = userInfo . info . extendedFields ;

If the user is already a member you can use the function " currentMember()".

member = await currentMember . getMember ();

And then the custom fields are saved under:

member . contactDetails . customFields