cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
SCTdan
Level 8

JSON formatting issues

This got marked as spam last time I tried to post, not sure why...

 

Mailchimp allows batch operations, allowing you to complete multiple operations with a single call.  Helpful when dealing with hundreds/thousands of records.  The format of the JSON is causing me a headache though.  This is what it needs to look like (confirmed working in postman)-

 

{
	"operations": 
	[
	{
	"method":"POST",
	"path": "/lists/f8b596c66e/members/",
	"body":"{
            \"email_address\": \"test1@gmail.com\",
            \"status\": \"subscribed\",            
            \"merge_fields\": {
                \"FNAME\": \"Test\",
                \"LNAME\": \"One\",
                \"ADDRESS\": {
                    \"addr1\": \"1122 Rad Dr\",
                    \"addr2\": \"\",
                    \"city\": \"Toledo\",
                    \"state\": \"OH\",
                    \"zip\": \"12345\",
                    \"country\": \"US\"
                },
                \"PHONE\": \"1233047645\",
                \"COMMERCIAL\": 1,
                \"SALUTE\": \"Dear Dan\",
                \"SOURCE\": \"CR\",
                \"ACQUIRED\": \"2019-01-01\",
                \"ARBAL\": \"\",
                \"RAU\": \"\",
                \"EXPIRES\": \"2019-07-01\",
                \"SECONDARYP\": \"1236996491\",
                \"CUSTID\": \"12345\",
                \"LOCATION\": \"1\"
            }
		}	
	"},
	{
	"method":"POST",
	"path": "/lists/f8b596c66e/members/",
	"body":"{
            \"email_address\": \"dan@tech.com\",
            \"status\": \"subscribed\",
            \"merge_fields\": {
                \"FNAME\": \"Dan\",
                \"LNAME\": \"I\",
                \"ADDRESS\": {
                    \"addr1\": \"12 Road\",
                    \"addr2\": \"\",
                    \"city\": \"Toledo\",
                    \"state\": \"OH\",
                    \"zip\": \"12345\",
                    \"country\": \"US\"
                },
                \"PHONE\": \"1233047645\",
                \"COMMERCIAL\": 1,
                \"SALUTE\": \"Dear Dan\",
                \"SOURCE\": \"CR\",
                \"ACQUIRED\": \"2019-01-01\",
                \"ARBAL\": \"\",
                \"RAU\": \"\",
                \"EXPIRES\": \"2019-07-01\",
                \"SECONDARYP\": \"1236996491\",
                \"CUSTID\": \"12345\",
                \"LOCATION\": \"1\"
            }
		}
	"}
	]
}

Looks fun, right?  

 

My problem is that it's adding quotes around part of the JSON I've generated

aia-error3.png

 

 

 

 

 

Relevant part of the flow (if it's not large enough- https://i.imgur.com/tuenGFS.png )-

The Input for Generate Record is a solid block to avoid it adding \n \t in later compose operations.

It also will not accept it as valid JSON without the whole thing inside single quotes, hence the compose action to remove those.  

 

aia-flow.png

 

The ouput from Compose 3 is what I need, I just need to stick this inside the main operations object without it adding the double quotes

 

aia-good.png

 

 

No matter how I try to do that, it will add double quotes around the entire object array (not each array item), as shown above.  Converting it to JSON works, but that strips all the escaped double-quotes, which breaks it anyways.

 

 

Ideas?

 

 

Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
SCTdan
Level 8

Re: JSON formatting issues

I figured this out.  The issue was in trying to put the joined array (becomes a string at that point) back into an array or object variable.  That added the quotes, and I didn't notice, but it also escaped all my escaped characters.

 

So instead, just write it to a string variable instead, then pass that string variable* as the POST body.  In hindsight, rather simple.  

 

Lesson learned-  Just because you need to pass an object/array via POST (and you don't need to utilize it as an object/array inside flow anymore), doesn't mean it has to be an object/array inside Flow.  Not really a common issue though, just due to the unique batching syntax in mailchimp.

 

mc-success.png

mc-success2.png

 

 

*You must pass a fully-formed query as a variable, it won't format properly when done like you see in the HTTP body heremc4.png

 

View solution in original post

1 REPLY 1
SCTdan
Level 8

Re: JSON formatting issues

I figured this out.  The issue was in trying to put the joined array (becomes a string at that point) back into an array or object variable.  That added the quotes, and I didn't notice, but it also escaped all my escaped characters.

 

So instead, just write it to a string variable instead, then pass that string variable* as the POST body.  In hindsight, rather simple.  

 

Lesson learned-  Just because you need to pass an object/array via POST (and you don't need to utilize it as an object/array inside flow anymore), doesn't mean it has to be an object/array inside Flow.  Not really a common issue though, just due to the unique batching syntax in mailchimp.

 

mc-success.png

mc-success2.png

 

 

*You must pass a fully-formed query as a variable, it won't format properly when done like you see in the HTTP body heremc4.png

 

View solution in original post

Helpful resources

Announcements
firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Solution Authors
Top Kudoed Authors (Last 30 Days)
Users online (5,443)