Passing JSON through API Connector

I usually don’t come here, because generally I can find answers to most everything, but I am absolutely stumped on this one.

I can get the API endpoint to succeed when I initialize my call. However, as soon as I try to pass the same data through the API plugin, it fails.

I have tried everything, and if I change something, a new line error proceeds. Unless, I make the call through the initialization.

To see how it was sending each way, I passed the data through pipedream using the workflow (failure), and then again while making the call through initializing (success).

I can copy the data directly from the failed body in pipedream, paste it into the initializer, and it works. But as soon as I try to make the same call with the workflow and the API plug in it fails.

I did notice that there is an extra header called Baggage when making the call through the initializer. I even tried adding that then sending it through the workflow, and still nada. Also, you can see that the json was parsed differently with the initializer call, than with the workflow call. I ran everything through a validator also.

Current setup, although I have tried a few different ones. And all the same results.


What we get when passing the data through the initializer-Pass

What we get when passing the data through the workflow plugin-Fail

Been struggling with this for 3 days now. It seems to be a common theme amongst the API connector when passing arrays.

I think it’s absolutely ridiculous that there’s an obvious issue with the API connector, yet Bubble has done nothing to fix or address it, or if anyone requires help with it, they’re left to figure it out on their own or have to back end hack workflows.

GIVE US AN API CONNECTOR THAT DOESN’T PARSE OUR JSON INTO CRAP IT DOESNT NEED TO BE.

It’s sooooo simple!

Can you clarify what works and what doesn’t? Such as:
Pipedream → Bubble API endpoint Initialize PASS (receive webhook)
Pipedream → Bubble API endpoint FAIL (receive webhook)
Bubble API Connector → Bubble API endpoint Initialize ?
Bubble API Connector → Bubble API endpoint ?

Can you also clarify where is your data source and where is the desired destination?

1 Like

I started with a test page that created an array, using the format as text command, like so.
exhibit1

I then passed this data server side like so, and got a successful return.
exhibit2

I then setup my call like so, and retested that call and got another success.

I then setup my workflow, the same way I did my test page, but the moment I try to pass that data through the api plugin, the same way I have set it up on all of my tests. It fails. No matter what I do, I get an error 400 that its not formatted correctly.

I setup a pipedream to see the output, and from what I can tell, the plugin is parsing the json list into another format. I have tried formatasjsonsafe. I have tried so many things, and I absolutely cannot get the data to pass through the api plugin successfully. I always get a formatting error or the most recent error is that json could not be formatted into bs.ms model library.

Its crazy. I want to cry.

So, after some research. I believe its a serializer issue with the plugin and Azure Devops. I found an article about a converter built to get around this.

I still don’t understand why I can get the call to work from the initializer, but not through the plugin through a workflow. This article explains it better than I can.

I believe the issue is that the JSON all needs to be on the same line because Bubble actually passes a /n with the API body call, so where-ever there is a line break in your JSON, Bubble adds /n in the call body, so your JSON is no longer valid JSON.

It was a real pain to figure this out recently for myself, and once I found the thread on the forum that mentioned this, I changed my JSON to have no line breaks, all of it on the same line and it works.

Get used to this. Bubble has now decided to label these types of issues as ‘known limitations’ because they know there is a problem, but they refuse to address it properly through a fix, and have opted to just change the wording used to describe it.

1 Like

Yea, I noticed that from the outputs I was getting. I think I tried it without the line breaks, because I have literally tried everything, but I will try it again. Won’t hurt, I’ve already tried everything a couple of a hundred dozen times anyways.

I am also going to give the JsoNest plugin a try, but I don’t see how it will help since once I pass the data through the API connector, it’s going to do its own thing anyways.

Very strange, and I am not sure the reasoning behind them doing that. What’s the purpose of the jsonsafe command, if Bubble is just going to try and make everything json safe anyways. Maybe so we can have it json safe-safe, idk.

But the crazy thing is too, is most of the outputs I am getting are json validated. Its just when I run it through the plugin module itself, it doesnt work -but can still be validated, but if I run the same data through just the initializer and not the plugin module - it works fine. Sometimes, I can’t even tell the difference between the two outputs, other than when I copy and past into a validator, and can see that its being serialized and parsed differently.

Also I keep getting the BS.MS parse error. Which has something to do with Azure, and in fact the server I am trying to post to does use Azure.

So,… I don’t know.

It is likely saying it has an error parsing the JSON because of the /n

yeah, depending on how I format, I get the \n, and find and replace doesnt work with that.

The screenshot of the API Connector shows all params as private, this means the workflow won’t be able to pass other values, I assume it is not the right screenshot?

Can you show the API call in the workflow where it uses JSONsafe?

JSONsafe for a text param puts "double quotes" around what it is passed, which would be an issue for the partial report number.

Can you show the matching mangled output and the API connector setup and the workflow API call?

Yea, that’s the wrong screen shot. But this is what’s currently going on.

Here is the call

Here is the workflow

This is the error:
“{"type":"RFC 7231 - Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content or more validation errors occurred.","status":400,"traceId":"00-2cb2123e057d39fed99a63e053d6631e-dfd4f9add821b594-01","errors":{"$.PowersToExecute[0]":["The JSON value could not be converted to BSMS.Model.Library.PowerExecutionReport.Request.PowerToExecute. Path: $.PowersToExecute[0] | LineNumber: 10 | BytePositionInLine: 262."]}}”

This is the output:

Now I know the error sees something in line 10, but the above screen shot is of the entire output being pasted into a validator, and its good.

Also, if I copy line 10, and paste it directly into the "PowersToExecute variable, and click initialize, we get it to work. Yet, the two outputs are slightly different in that, the json is serialized different, and Bubble adds a baggage header when passed through the initializer but not through plugin when being passed.

I sent the wrong screenshot of the current call again. I have tried so many different ones.
This is the current one

I needed to try it without spaces too. Try that @jnoblescas

I have no explanation for why spaces might break it, but it worked for me… And yeah, there should be a checkbox that stops format as text being formatted as JSON-safe…

No spaces, is the only thing I haven’t tried. If this works…

Change the API URL in the API connector to a link at https://requestcatcher.com/ so you can see the raw body that’s being sent by Bubble to help debug. Run the raw body through a JSON validator to locate any issues.

3 Likes

The validator sees PowersToExecute as an array of text, which is “valid” but you want an array of object.

The problem is API connector treating the entire parameter as one text and escaping it, so instead of a structured object it is all text.

Not sure the solution …

Edit - since you want to pass a list of objects, perhaps change the API Body type to Raw, then do all the formatting yourself instead of JSON params.

1 Like

The no spaces deal produced same error. json value could not be converted to BSMS.Model.

I’ve been using pipdream to check the outputs.

Can you post an example output here (text not screenshot)

This is likely something that can be fixed (without using plugins) but it’s just unreasonably difficult purely because of Bubble’s fault.

Yea, I’ll post again after I get some rest. Thanks for the help!

1 Like

Yea, I thought that as well. I think I do need to play with the raw text some more though. Off to bed for now though. I’ll keep you posted.