How to get the value of a string with the same name as a list?

This is related to this post, just with some clarifications/simplifications.

So I’m looking to get the bottom-most display_value from this JSON file, highlighted below:

Unfortunately, the API Connector automatically identifies display_value as a list:

This makes it impossible to retrieve this value in my bubble app, because it throws an error unless I provide it with other fields (which don’t exist):

api-line-item-metadata-9

Does anyone know a workaround for this? I tried “format as text” but the issue persists. Is there any way to force the API to identify this as a string? Is it possible to write a small JavaScript file just to retrieve this value?

Thanks in advance

If you’re trying to get the last display-value then just add ‘last item’ to your expression.

Thanks, but unfortunately Bubble is treating the display_value as a list. I can access it using last item but it still prompts me for further qualifiers.

No, I meant add last item to the end of your current expression.

Oh I see, that prompts me for more options, but unfortunately none of those exist because the value I’m looking to retrieve is a string, not a list, as you can see in the JSON response on the right:

The issue is I’m looking to retrieve display_value itself, but the API connector is identifying it as a list of values.

I’m thinking a JS API call might be the way to go, but my Javascript knowledge is pretty rough. Something like this:

Display value IS a list (of objects)…

So I’m not too sure i understand what you’re trying to do.

A text element can only display texts.

What are you trying to display?

The display_value I’m trying to retrieve (the last one) is actually a string. There are 2 previous entries with display_values that are lists, which is why the Bubble API identifies it as such, but the 3rd one is a string (unless I’m mistaken).

When you initialized the API call, is there was both possibilities? the list and the string?

No, that’s sort of where the problem begins. In the API Setup it only has ‘list’ or ‘ignore’ as options, I can’t return display_value as a value itself.

No my questions is When you click call api (and initialized, is the response contain both possibllities? (not what Bubble show you, but what the API response return, click show raw data)

Oh I see, yes, both possibilities show up in the raw data.

display_value as a list:

display_value as a string:

Is this just an edge case?

I will say, for me, it’ a bad API service encoding (should always be a list, even if there’s only 1 item in the list and two different key/object if you want to display one string and one list).
I was thinking that Bubble may parse it as two different fields, but doesn’t seem to be the case. I guess you may submit a support ticket, but I don’t have a lot of hope on short term.

One thing you may consider, and if the API have this endpoint, is to call this specific item in the list (using the ID) to get the payload when list:count is 0 for example to bring the data you need for display value when this is a string.

Another option may be to use one of the JSON plugin that exist to parse the JSON (API connector will get it as text instead of JSON)

2 Likes

Thanks for the info, I iterated a bit on your first solution and came up with something that works (but it’s a bit hackey).

api-line-item-metadata-17
I manually edited the API response and took out the square brackets that defined display_value as an array rather than a value.

This obviously won’t work if you need both versions of display_value, but it works for my use case. If you do need both, I imagine you could have two almost identical API calls and use one for each.

Thanks all!

1 Like