Issues loading/formatting API data to be read by Plugin

This has been driving me crazy. I’ve tested my code and everything works fine but when I try to implement it in my plugin… no dice.

The API data type is “text”. That is working fine. Below is a screenshot of the raw data received from the API.

My plugin settings are below:

My code is very basic. It simply reformats the document into an array of objects. Please ignore the return values of the code in the screenshot because I have since corrected it and created two separate arrays of dates “d.getTime()” and numbers “dates[date][obj]”… instead of one array of objects…

I initially tested the code by bypassing the API input and just creating a value that holds the RAW JSON text, I then parsed it using “JSON.parse(json_object)”. That worked but when I removed that and tried to pull directly from the API (i.e. dates = properties.json_object) it would not work.

I have been researching the issue for hours and trying different things like:

  • “properties.json_object.get()” and “properties.json_object.get(0, properties.json_object.length());”
    ← error msgs are telling me these are not functions now

  • changing the keys and/or return values to be preceded by " _ p_"

  • parsing the incoming data using JSON.parse(properties.json_object);

  • making sure it was only reading the body by using (properties.json_object.body);

  • converting it using JSON.stringify when I was getting errors like “unexpected token o in json at position 1” suggesting it was already parsed

I made a test return value to output the JSON text by outputting “dates” so I could see what the plugin is receiving from the API and it showed [object Object] but when I used JSON.stringify to display it I only saw {“single_api”:true}

I’ll keep searching but I don’t see much detailed documentation in Bubble’s Docs. Any help or pointing me in the right direction that covers any key details that are not in Bubble’s Docs will be greatly appreciated!

I have read:

I don’t know the answer to this, but I would suggest looking at the code of some free plugins to see how they set it up. There is a free plugin for calendar and I believe it has a timeslot generator feature.

Go to the desired plugin page and press button to see code (only available for free plugins)…it opens the plugin editor for a behind the scenes sneak peak.

1 Like

So for anyone coming across this issue in the future, I finally found the problems… they were pretty basic but I’m new to making plugins so had to get my bearings with trial and error.

I did not need to:

  • use get() to cache the JSON document as I thought
  • convert ‘json-to-bubble-object’ in my situation
  • JSON.stringify the JSON document

I did need to:

  • JSON.parse(properties.input) the incoming JSON data prior to processing it with my code
  • clean up my code
  • reinitialize my API connection after tinkering with it, it appears that the reason I did not get the option to specify using the “body” of the JSON document was due to my tinkering
  • make sure I was specifically referencing the “body” of the JSON document in my workflow and not the whole raw text which I initially thought was necessary

Yes, all pretty basic but hopefully this helps a newbie like myself in the future!

Struggling with this too, any chance you can share your final code?

I have a field called payload, set as dynamic value, type any thing. not a list.
I can do:
console.log(properties.payload)

and I get:
INFO LambdaSingleApi { single_api: true, __original: [Function], listProperties: [Function], get: [Function] } END.

I tried adding:
JSON.parse(properties.payload)

and I get an error:
Unexpected token o in JSON at position 1 at JSON.parse () at eval (eval at build_function (/var/task/index.js:86:21)