JSON formatting for an external API "put" request

Hi there - wondering if someone can help me before I tear what currently remains of my hair out.

I’m trying to send an external PUT request to an API endpoint and I’ve got 99% of it working but I can’t get the array of “ASN items” into the right format for it to be accepted at the other end. If I use format as JSON safe it accepts the creation of the main item but then can’t find the Products because random \ are being inserted into the data. Please help!

So this is where I search for the items and format the data as text

I send the data to this backend workflow as “json”

And here is the API

I get this info in my log:

But it throws this error:

Hey @alastair1 :wave:

Hmm :thinking: I would try adding a find and replace, ‘/’ with a space, here

As an alternative, you can also do JSON safe at the same place but then you will have to remove the “” around This ASN Item’s SKU

Does that help? :man_shrugging:

Hey, thanks for the suggestion - I’ve narrowed the issue down to the quirk of bubble inserting /n between each object in an array:

“Items”: [{“ProductId”:267240,“SKU”:“BTR-408 Monza Waterfall High Rise Mono Basin Mixer TapHIG001”,“Quantity”:1}\n,{“ProductId”:267241,“SKU”:“BTR-408 Tap holeWE12TEST”,“Quantity”:1}\n,{“ProductId”:267242,“SKU”:“BTR-408 Tap hole insertWE12TEST”,“Quantity”:1}\n]

1 Like

SOO…I just need to stop it doing this but it seems like this is quite a common issue??

Does JSON safe fix it?
Is there a space at any of these 3 arrows :point_down:
image

I’ve checked and can’t see any spaces (although I can only see two arrows on your screen grab). In terms of Json safe - I’m a bit confused as /n is technically the json safe way of doing a line break isn’t it? But there aren’t any line breaks so I don’t know why it’s being added in.

I was just trying some things. JSON safe often works for me.
In the API connector, is it initializing properly?

THanks for the suggestion - It didn’t resolve the issue. So I don’t think it’s anything within the individual object. I saw a different thread and they suggested using request catcher, which I did…

{
“WarehouseId”: 3,
“POReference”: “BTR-408 TBO-111 TEST9999”,
“Supplier”: “Victorian Plumbing”,
“EstimatedDelivery”: “2023-11-23T12:11:00:SSSGMT”,
“GoodsInType”: “Pallet”,
“Quantity”: 3,
“ProductSupplierId”: 229,
“Items”: [{“ProductId”:267240,“SKU”:“BTR-408 Monza Waterfall High Rise Mono Basin Mixer TapHIG001”,“Quantity”:1}\n,{“ProductId”:267241,“SKU”:“BTR-408 Tap holeWE12TEST”,“Quantity”:1}\n,{“ProductId”:267242,“SKU”:“BTR-408 Tap hole insertWE12TEST”,“Quantity”:1}\n]
}

Why i run this through a JSON validator it fails. If I remove the /n between each item - it works.

Yeah that’s what’s so annyoing - in the initializer it works…

Ugh. So annoying. I’d try 2 things. After setting the state, in a separate action find and replace"\n" and try saving it all on the back-end without it passing thru a custom state.

Do you know how I can do the equivalent in the backend workflow in terms of doing a search for etc ?

Remove the dynamic fields and replace them with static values, this should allow you to modify the complete JSON in your Workflow. It’s easier to debug and in case the data is empty, it will not trigger any issues executing the workflow.

I’d recommend you use format as json safe to avoid having empty fields where possible and replace empty numbers with a null value.

Example for numbers: This number is not empty

Yes >> this number 

No >> null