I have a Zapier automation that pulls conversation data from Intercom using a GET request. All the messages get stored as line items but I need to convert this into a clean text string.
The problem is that when Zapier combines the line item values, it adds commas everywhere. I want to remove these commas and create a readable conversation format that I can save as a text note in another system.
Here’s what I’m working with:
data_input = {
"messages": "<p>Sure, let me check that for you right away</p>,<p>thanks</p>,<p>I've sent the information to your email. Please check and let me know if you need anything else</p>,<p>perfect</p>,<p>Testing new integration setup</p>"
}
I attempted this approach:
message_list = data_input['messages']
return {" ".join(str(item) for item in message_list)}
But I keep getting these errors:
TypeError(repr(o) + " is not JSON serializable")
TypeError: set(['< p > T h a n k s < / p >']) is not JSON serializable
How can I properly convert the line items into a single clean string?
Had the exact same issue last month building a similar workflow. Your return statement syntax is wrong - you’re creating a set when Zapier expects a dictionary. Here’s what worked for me:
data_input = {
"messages": "<p>Sure, let me check that for you right away</p>,<p>thanks</p>,<p>I've sent the information to your email. Please check and let me know if you need anything else</p>,<p>perfect</p>,<p>Testing new integration setup</p>"
}
messages = data_input['messages'].split(',')
clean_text = '\n'.join(msg.replace('<p>', '').replace('</p>', '') for msg in messages)
return {'conversation_text': clean_text}
Key difference: use \n instead of spaces for better readability and handle the HTML cleanup in one step. Creates a proper conversation format that reads naturally when saved to your other system.
You’re returning a set instead of a dictionary, which breaks Zapier’s JSON serialization. Your current code return {" ".join(str(item) for item in message_list)} creates a set with one element - that won’t work.
Since your messages are already a single comma-separated string, split them first, then join:
data_input = {
"messages": "<p>Sure, let me check that for you right away</p>,<p>thanks</p>,<p>I've sent the information to your email. Please check and let me know if you need anything else</p>,<p>perfect</p>,<p>Testing new integration setup</p>"
}
message_string = data_input['messages']
clean_messages = message_string.split(',')
final_text = ' '.join(clean_messages)
return {'clean_conversation': final_text}
This splits the comma-separated string into individual messages, joins them with spaces, and returns a proper dictionary that Zapier can actually handle.
you’ll need to strip those html tags too. use regex or the replace method after splitting - something like clean_text = message.replace('<p>', '').replace('</p>', '') for each message before joining them back.