Create a string from an items list

Hi everyone!

I’m currently working on a project that involves notifications coming in from a Shopify store, to get the created checkouts and send them back to Airtable.

When a new checkout is created, it usually has several items added to the cart and the information is sent as a list of items.

I would like to retrieve only the names of the items, to display them as: “Item_1, Item_2, Item_3” and so on, in a single string.

I tried to use the “Item lists” node but when I enter the name of the field that contains the information, this error message appears:

Here is also an example of my code (quite simple). The value I want to make a string of is named “presentment_title”:

And the dataset I use:



{


"headers":
{



"x-real-ip":
"35.239.60.61",



"x-forwarded-for":
"35.239.60.61",



"host":
"odd-dragonfly-62.hooks.n8n.cloud",



"x-forwarded-proto":
"https",



"x-nginx-proxy":
"true",



"connection":
"close",



"content-length":
4285,



"user-agent":
"Faraday v1.10.2",



"content-type":
"application/json",



"x-shopify-topic":
"checkouts/update",



"x-shopify-shop-domain":
"test2ac.myshopify.com",



"x-shopify-hmac-sha256":
"T8v2fUEj1G16eyejJeR4I5feDglIdemi2s9l1G8EorY=",



"x-shopify-webhook-id":
"d3757251-b4ed-43a4-b68c-4b22e3d3093b",



"x-shopify-api-version":
"unstable",



"x-cloud-trace-context":
"06c8623e7cb7e9d0b980fd49c8d1cd71/13128330866444347373;o=1",



"x-shopify-trace-context":
"06c8623e7cb7e9d0b980fd49c8d1cd71/13128330866444347373;o=1",



"accept-encoding":
"gzip;q=1.0,deflate;q=0.6,identity;q=0.3",



"accept":
"*/*"


},


"params":
{


},


"query":
{


},


"body":
{



"id":
981820079255243500,



"token":
123123123,



"cart_token":
"eeafa272cebfd4b22385bc4b645e762c",



"email":
"[email protected]",



"gateway":
,



"buyer_accepts_marketing":
false,



"created_at":
"2022-12-05T15:14:54+01:00",



"updated_at":
"2022-12-05T15:14:54+01:00",



"landing_site":
,



"note":
,



"note_attributes":
[



],



"referring_site":
,



"shipping_lines":
[



],



"taxes_included":
true,



"total_weight":
400,



"currency":
"EUR",



"completed_at":
,



"closed_at":
,



"user_id":
,



"location_id":
,



"source_identifier":
,



"source_url":
,



"device_id":
,



"phone":
,



"customer_locale":
,



"line_items":
[




{





"applied_discounts":
[





],





"discount_allocations":
[





],





"key":
"952db8230f9d6de26a8c9e4997690911",





"destination_location_id":
3754976346399,





"fulfillment_service":
"manual",





"gift_card":
false,





"grams":
200,





"origin_location_id":
3754976313631,





"presentment_title":
"Aviator sunglasses",





"presentment_variant_title":
,





"product_id":
788032119674292900,





"properties":
,





"quantity":
1,





"requires_shipping":
true,





"sku":
"SKU2006-001",





"tax_lines":
[





],





"taxable":
true,





"title":
"Aviator sunglasses",





"variant_id":
642667041472714000,





"variant_title":
,





"variant_price":
19.99,





"vendor":
,





"user_id":
,





"unit_price_measurement":
{






"measured_type":
,






"quantity_value":
,






"quantity_unit":
,






"reference_value":
,






"reference_unit":






},





"rank":
,





"compare_at_price":
24.99,





"line_price":
89.99,





"price":
89.99




},




{





"applied_discounts":
[





],





"discount_allocations":
[





],





"key":
"ca82d66b06138abeb3d2d0ad0a062315",





"destination_location_id":
3754976346399,





"fulfillment_service":
"manual",





"gift_card":
false,





"grams":
200,





"origin_location_id":
3754976313631,





"presentment_title":
"Mid-century lounger",





"presentment_variant_title":
,





"product_id":
788032119674292900,





"properties":
,





"quantity":
1,





"requires_shipping":
true,





"sku":
"SKU2006-020",





"tax_lines":
[





],





"taxable":
true,





"title":
"Mid-century lounger",





"variant_id":
757650484644203900,





"variant_title":
,





"variant_price":
19.99,





"vendor":
,





"user_id":
,





"unit_price_measurement":
{






"measured_type":
,






"quantity_value":
,






"quantity_unit":
,






"reference_value":
,






"reference_unit":






},





"rank":
,





"compare_at_price":
24.99,





"line_price":
159.99,





"price":
159.99




}



],



"name":
"#981820079255243537",



"source":
,



"abandoned_checkout_url":
"https://checkout.shopify.com/68747100447/checkouts/123123123/recover?key=example-secret-token",



"discount_codes":
[



],



"tax_lines":
[



],



"source_name":
"web",



"presentment_currency":
"EUR",



"buyer_accepts_sms_marketing":
false,



"sms_marketing_phone":
,



"total_discounts":
0.00,



"total_line_items_price":
249.98,



"total_price":
249.98,



"total_tax":
0.00,



"subtotal_price":
249.98,



"total_duties":
,



"billing_address":
{




"first_name":
"Bob",




"address1":
"123 Billing Street",




"phone":
"555-555-BILL",




"city":
"Billtown",




"zip":
"K2P0B0",




"province":
"Kentucky",




"country":
"United States",




"last_name":
"Biller",




"address2":
,




"company":
"My Company",




"latitude":
,




"longitude":
,




"name":
"Bob Biller",




"country_code":
"US",




"province_code":
"KY"



},



"shipping_address":
{




"first_name":
"Steve",




"address1":
"123 Shipping Street",




"phone":
"555-555-SHIP",




"city":
"Shippington",




"zip":
"K2P0S0",




"province":
"Kentucky",




"country":
"United States",




"last_name":
"Shipper",




"address2":
,




"company":
"Shipping Company",




"latitude":
,




"longitude":
,




"name":
"Steve Shipper",




"country_code":
"US",




"province_code":
"KY"



},



"customer":
{




"id":
603851970716743400,




"email":
"[email protected]",




"accepts_marketing":
false,




"created_at":
,




"updated_at":
,




"first_name":
"John",




"last_name":
"Smith",




"orders_count":
0,




"state":
"disabled",




"total_spent":
0.00,




"last_order_id":
,




"note":
,




"verified_email":
true,




"multipass_identifier":
,




"tax_exempt":
false,




"tags":
,




"last_order_name":
,




"currency":
"EUR",




"phone":
,




"accepts_marketing_updated_at":
,




"marketing_opt_in_level":
,




"email_marketing_consent":
{





"state":
"not_subscribed",





"opt_in_level":
,





"consent_updated_at":





},




"sms_marketing_consent":
,




"admin_graphql_api_id":
"gid://shopify/Customer/603851970716743426",




"default_address":
{





"id":
,





"customer_id":
603851970716743400,





"first_name":
,





"last_name":
,





"company":
,





"address1":
"123 Elm St.",





"address2":
,





"city":
"Ottawa",





"province":
"Ontario",





"country":
"Canada",





"zip":
"K2H7A8",





"phone":
"123-123-1234",





"name":
,





"province_code":
"ON",





"country_code":
"CA",





"country_name":
"Canada",





"default":
true




}



}


}

}
]

Thanks in advance for your help!

PS:
For the first screenshot, just remarked I took it after trying with an other value, but the problem’s the exact same when I put “presentment_title” instead of “line_items” in “Input Field Name”.

Hey @Anthony_CAVALIER, it seems your example data consists of a single n8n item only with fields such as headers, query, or body.

If you want to aggregate the individual presentment_title in a comma-separated string using the Item Lists node, you’d first need to spread out your body.line_items field, then aggregate the data from the presentment_title field. For example like so:

This would, however, still leave you with an array rather than a string.

So perhaps you might want to consider using .map() and .join() instead? For example:

Result:

1 Like

Hi @MutedJam !

Tank you a lot for your help it worked pretty well!

It was a bit disturbing to request some help for such a simple thing…

Does anyone here knows where I could find the doc to learn how to do it by myself by chance?

I mean, I don’t even know exactly which skill to target or what to search on dev forums (I don’t know how to code)

Well, transformations from one n8n item into multiple different items are always tricky @Anthony_CAVALIER. This is because most n8n nodes work their logic on each item.

As for learning I think asking here on the forum is a good starting point, don’t hold back with that :slight_smile:

In the example I’ve used vanilla JavaScript and shared my personal approach to learning it here, but this might not be the right path for you. Such transformations could, for example, also be done using JMESPath.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.