Trying to pull Meta Data from Woo Commerce and inserting it into sheets

:bullseye: What is your goal?

Hi, I want to pull the metadata from my WooCommerce website > specifically the _alg_wc_cog_order_cost value and insert it into my Google sheet.

:thinking: What is the problem?

My scenario runs, and the order ID runs back as the correct order ID, but the COGS either comes back blank or says false.

:test_tube: What have you tried so far?

I have tried using ChatGPT and Gemini, but I have been stuck on the same thing for the past 2 days. I tried copying and pasting the codes that ChatGPT and Gemini generated directly into Make, but Make does not recognize them. I have tried creating my own code using the get and map functoins but I still don’t have any success. Please, if someone can help me map the COGS I would be forever grateful!

:camera_with_flash: Screenshots: scenario setup, module configuration, errors


1 Like

@Kyrie_Irving HAve you been able to fix this or you still have an issue?

1 Like

Hey there,

As a first step can you hover over value and key and make sure you are matching the same raw names of the variables inside the formula?

@Kyrie_Irving

Indeed, working with nested arrays can sometimes be very cumbersome. Here is a guide how to solve this using the map and the first functions.

In brief:

  • your map function is correct
  • remove the get function usage
  • check if the key you are referencing in the map is available in the result - in the screenshots we see keys that are named differently and the one you are using _alg_wc_cog_cost may be not the right one.

Some in-depth review of the whole case, for other users that may encounter similar issues.

Here is a sample metadata in raw format as coming from WooCommerce (we need to provide the raw value names as you are already doing and the previous commenter suggested):

"metaData":[
   {
      "id":92233,
      "key":"_short_description",
      "value":"default"
   },
   {
      "id":92244,
      "key":"_reserved_quantity",
      "value":"500"
   },
   {
      "id":92255,
      "key":"_payback_price",
      "value":"10.00"
   }
]

The map function that can be used on arrays has a specific signature:

map(complex array; key;[key for filtering];[possible values for filtering])
  1. complex array - the data with which we are working: Meta Data []
  2. key - the key in the complex’s array which we are interested in: “value”
  3. key for filtering (optional) - the key which will be filtered: “key”
  4. possible values for filtering (optional) - the value of the “key for filtering” which we are interested in: “_some_meta_field_name”

For your usage a possible filter that will return the value of the _some_meta_field_name is:

{{map(1.metaData; "value"; "key"; "_some_meta_field_name")}}

The map function always returns an array so we need to fetch the first item from it (assuming that there will be only one item with this key in the order metadata, this is very important), we can use first :

{{first(map(1.metaData; "value"; "key"; "_some_meta_field_name"))}}

LMK if this helps.

1 Like

Nope, not yet. Still figuring it out.

1 Like

Yes I can do that, thanks for helping.

1 Like

Can you give me a step by step because when I click on the ‘map’ and ‘first’ function buttons my formula doesn’t have as many brackets as your does. I noticed when I type in the functions it doesn’t work so I have been clicking the buttons for all my formulas.

1 Like

There is no need for a step-by-step as this is some general information, the confusion comes from the snippets that are with double brackets - actually this is the internal format which Make is using and they are copied directly from my workflow. If you copy and paste them in yours - they will appear as the usual “pill” design. Essentially the snippet I provided is the same as yours, just with first instead of get

So you may:

  • try first with `map` and check if it detects the field correctly
  • check the key name you are using - in your first message there were other key names, another one in the first screenshot, now screenshots with _woo_ml_suscribe
  • remove the get usage and replace it with first for testing my snippet into your snippet provided in the first message (after also checking the key name)

It will help much to try how get , map, first work and observe the structure of the schema returned from WooCommerce. In Make Academy there is a foundational course that explains many of these concepts.

I hope this helps.

1 Like

Here.

You can find a lot more here as well.