Adding/modifying JSON with Make? Answered

Post author
Charles Lewis

Hi, 

I'm just getting started with Memberstack but I think I've established I'll need to use JSON to store some additional complex bits of member data. 

There will be occasions where updating something in Airtable would then prompt adding or modifying a member's JSON in Memberstack. I'm using Make from some other things – is there a way of using Make for this as well? And if not, what are my other options? 

Any help or guidance would be really really appreciated!

Comments

18 comments

  • Comment author
    Duncan Hamra
    • Edited
    • Official comment

    Hi Charles Lewis 👋

    First off, welcome! Glad you hear and excited to see what you build. 

    UPDATED May '24 :
    I can confirm it's possible to update JSON using Make.

    1. First you will need to add some JSON to a member and then run your scenario in Make. Once Make is aware of the JSON, it will display in the Make UI.
    2. If you want to edit the JSON without overriding, you'll need to save the JSON in make, manipulate the saved JSON, and then re-upload to Memberstack. 
  • Comment author
    Charles Lewis

    Thanks Duncan-Hamra! Are you able to point me in the direction of a couple in particular that use Make to update Member JSON?

    I was looking for something in Make similar to the custom fields and metadata fields, but I'm guessing it's a bit more complex than that then? 

     

    2
  • Comment author
    John Matias

    Hey Duncan-Hamra I'm also trying to work on something similar and it would be helpful to see the specific set up for how to update the member JSON in Make. What I'm stuck on right now is how to add something using make to the JSON object without overwriting the whole thing. Hopefully I can figure it out soon. 

    1
  • Comment author
    Dean Gray

    I too would appreciate seeing an example of how to cleanly make changes to the JSON with something like Make.com Duncan-Hamra as I'm currently looking into a way of using Memberstack for an MVP without having to lean on something like Xano/Wized just yet by using the member JSON as a light way of storing data on use profiles.

    1
  • Comment author
    Duncan Hamra

    Josh-Lopez Julian Galluzzo

    I'd love to hear what you guys think about this one.

    I just remembered that most of the MemberScripts are using the DOM package (not Make, as I thought). I'll keep looking for an example...

    I did use Make + Metadata for this Credit System Tutorial.

    And this documentation might help as well... but I'm not sure. https://docs.memberstack.com/hc/en-us/articles/15731922023451 

    0
  • Comment author
    Nicholas Platt

    Hey Duncan Hamra

    I'm also looking for a solution to this. I've started to write out some script that you can run in Airtable scripts but I'm a long way off from getting it to work. 


    Best,
    Nicholas

    0
  • Comment author
    Mohammed Mukhtar

    Hi, did you guys find any solution to this? In order to only update some json within make and not have to rewrite the whole thing?

    0
  • Comment author
    Duncan Hamra

    Josh-Lopez I wonder if we could create a short tutorial video or article that would explain best practices when updating JSON? I know we usually recommend grabbing the JSON, manipulating it, and then updating it - but it's easier said than done. 

    1
  • Comment author
    Josh Lopez

    We have a lot of examples here https://docs.memberstack.com/hc/en-us/articles/15731922023451-Advanced-JSON-Data-Usage-With-The-Memberstack-Dom-Package

    1
  • Comment author
    Josh Lopez

    I'll make a new doc that will show how to do it in make and zapier.

    2
  • Comment author
    Duncan Hamra

    Josh-Lopez that would be awesome!! Being able to manipulate JSON via Make has stumped me and others in the past - so a new doc would be greatly appreciated 🎉

    1
  • Comment author
    Josh Lopez

    Update on this. We are trying to figure out how we can add additional functionality in the make and zapier apps that will help with updating member JSON data! Keep an eye in the announcements channel in our slack community for additional updates.

    1
  • Comment author
    Mohammed Mukhtar

    Thank you!

    1
  • Comment author
    Axel Zouebi

    +1

    0
  • Comment author
    Josh Dean

    Duncan-Hamra 

    Please can you explain in a bit more detail how to not overwrite existing member JSON in Make?

    I am trying to create an image upload feature for each user that sends the uploaded images to Google Drive - then turns the images into JSON - and then sends that JSON back to the member (using the unique Memberstack ID) - then to be displayed back into the web app in the user's dashboard (by accessing the member JSON).

    I can't figure out how to NOT overwrite the existing member JSON.  I simply want to add to it.

    0
  • Comment author
    Josh Lopez

    Hey Josh Dean

    I dont think this is possible at the moment. What we recommend is to get the json, add or update it, then send the whole json object back. 

    0
  • Comment author
    Josh Dean

    Hey Josh-Lopez , thank you for letting me know.

    But 2 questions: -

    1. Is there any other way to get the user's uploaded images to be displayed back in their dashboard other than using JSON?

    2. If not, how do I get the JSON and then add or update it?

    0
  • Comment author
    Josh Lopez

    Josh Dean Here is some additional info that should help. If this doesnt make sense or you cant get it working I suggest reaching out to one of the experts here to help with your custom code.

    To use JSON with Memberstack 2.0, you can leverage the Memberstack DOM Package and the Memberstack Admin API to retrieve, update, and save JSON data for members. Here’s a step-by-step guide:

    1. Retrieve Member JSON Data

    First, you need to get the current member's JSON data. You can use the getMemberJSON function from the Memberstack DOM Package:

    const memberstack = window.$memberstackDom;

    document.addEventListener("DOMContentLoaded", async function() {

      const member = await memberstack.getCurrentMember();

      if (member) {

        let memberJson = await memberstack.getMemberJSON();

        console.log(memberJson);

      }

    });

     

    2. Update Member JSON Data

    After retrieving the JSON data, you can modify it as needed. For example, you can add a new field or update an existing one:

    document.addEventListener("DOMContentLoaded", async function() {

      const member = await memberstack.getCurrentMember();

      if (member) {

        let memberJson = await memberstack.getMemberJSON();

        // Add or update data

        memberJson.avatarURL = "https://www.media.com/buckets/josh/avatar.jpg";

        memberJson.skills.push("nodejs");

        // Update member JSON

        await memberstack.updateMemberJSON({ json: memberJson });

        console.log(await memberstack.getMemberJSON());

      }

    });

     

    3. Send Updated JSON Data Back to Memberstack

    Use the updateMemberJSON function to save the updated JSON data:

    await memberstack.updateMemberJSON({ json: memberJson });

    Example: Complete Script

    Here’s a full example that gets the member JSON data, updates it, and saves it back to Memberstack:

    <script>

    document.addEventListener("DOMContentLoaded", async function() {

      const memberstack = window.$memberstackDom;

      const member = await memberstack.getCurrentMember();

      if (member) {

        let memberJson = await memberstack.getMemberJSON();

        // Modify or add new data

        memberJson.avatarURL = "https://www.media.com/buckets/josh/avatar.jpg";

        memberJson.skills.push("nodejs");

        // Update member JSON

        await memberstack.updateMemberJSON({ json: memberJson });

        console.log(await memberstack.getMemberJSON());

      }

    });

    </script>

     

    Using Memberstack Admin API (for server-side operations)

    For more advanced operations or server-side handling, you can use the Memberstack Admin API. Here’s how you can update a member's JSON data using the REST API:

    const axios = require('axios');

    const apiKey = 'your_memberstack_api_key';

    const headers = { "X-API-KEY": apiKey };

    const memberId = 'member_id_here';

    const updateMemberData = async () => {

      try {

        // Get member data

        const response = await axios.get(\`https://admin.memberstack.com/members/\${memberId}\`, { headers });

        let memberData = response.data;

        // Update JSON data

        memberData.json.avatarURL = "https://www.media.com/buckets/josh/avatar.jpg";

        // Send updated data back to Memberstack

        await axios.patch(\`https://admin.memberstack.com/members/\${memberId}\`, { json: memberData.json }, { headers });

        console.log("Member JSON updated successfully.");

      } catch (error) {

        console.error("Error updating member JSON:", error);

      }

    };

    updateMemberData();
    0

Please sign in to leave a comment.