Convert Type to JSON in Workflow for API consumption

Hello,

I have a workflow which needs to post some data to an API endpoint using the API connector. The API expects a JSON formatted input and I want to pass a Data Type I have stored. However I cannot figure out how to convert the Data Type into JSON.

Any advice?

Thanks

There are several techniques discussed already on the forum. You’d need to provide more information to work out which is appropriate.

To summarise …

  • The JSON body is a string, which you can build up with text operations.

  • If there is a single instance of the data type (not a list), or a fixed length list (example, always two items), it can be built up at the time of the API call.

  • If there is a variable length list of the data type, there are two alternatives:

  • Build up each item’s JSON structure as it is created or modified, and store it in the database. Then at the time of the API call, retrieve the list of JSON objects and join them together into a JSON array.

  • Use the List Item Expression to build the entire JSON array at once. This only works on the client, so if your API call is happening from an API workflow triggered outside of Bubble, it would need to be done earlier by a client operation, and stored somewhere, i.e. similar to the first alternative.

1 Like

I got it working using text operations, it doesn’t look the prettiest but its functional!

Thanks for the advice!

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.