Hit a roadblock working on a Plugin (Using Object Property Name as Data)

I am working on putting together a plugin for Indico that will access there custom data set feature. I have all of the calls working to add data, train the collection and tag text from it. Now the problem, I don’t know anything about JS and I believe writing an action to define the object as a variable that I can write to a table is what I need to do.
Results are returned as an object and its probability of being a match like this

Here is an actual return from a test data set I trained with a few cars and motorcycles just to test. I expect my actual dataset to have 100+ possible objects that may change at any given time so hardcoding them is not an option.

I can have the API only return the best match but the way that the data is structured I only get access to the probability when what I need is the object name. Ideally I would like to have access to both the object name and the probability so that if there are multiple high probability objects I could classify something as both and weight it on the probability.

I’m not expecting somebody to write this for me but if someone could point me in the right direction that would be great. I have no intention of becoming a master at JS but I am certainly willing to learn enough to get by. The problem is I don’t even know where to start and I can’t seem to find any examples that seem close to what I want to do and to be honest I’m not quite sure where to start. Also I will release this with dynamic options so other can define their own custom collections and make use of it.

1 Like

Some ideas …

If you want to access an API differently than the API connector or the API endpoints, you can do your own in javascript, for examples look up GET / POST via ajax … then put it into a HTML element or an element plugin. It will be limited to client-side only, as in the API is called from the browser rather than the server.

An alternative is to have the data in a different form, where your “field names” are on the data side, like:
{ "result list": [{ "name": "Automobile", "probability": 0.6667 }, { "name": "Motorcycle", "probability": 0.3332 } ] }

If you can’t change how the data is sent, you could use an intermediate server to alter the structure.

1 Like

Thanks for the suggestions. I don’t think that doing it through an HTML element will accomplish what I need, It seems like it would be better to be able to run some of the Actions on the server and I also need to keep my key hidden(I believe, I really am learning all of this as I go).

I like the different data format idea, there is nothing in their documentation about changing the format of their responses so I sent them an email. I would like to stay away from putting an intermediary in to reformat, just seems like another piece to break. I will follow up with what they say.

I finally got a response from Indico, they do not offer a way to change the output. Data can be manipulated through JS in a plugin action though correct? I am pretty sure that reformatting the response with JS is pretty simple, I have found a couple of different examples of how I think I can do it, I am still trying to get enough of a grasp on JS to incorporate them into a plugin though. I have been taking some JS courses at Codecademy and am starting to get a lot better understanding of how things really work. If anybody has any suggestions on other places I should be looking for content more specifically relevant to working with Bubble I would love to hear from you. I am having trouble figuring out what data or functions I have access to inside the plugin and how to pass data back out of it.

Hi @matt3.

The plugin element code has no access to the API calls defined for the plugin :stuck_out_tongue: So the API calls would have to be done by the code too.

The code has read access to the keys in the shared tab, so API tokens etc. can be put there.

Also the code has read access to the Fields when running the update function.

Passing data back to the Bubble app is done with the instance.publishState function. See Emmanuel’s example linked to in the announcement post.

The code can also call instance.triggerEvent to let the Bubble app know something has changed.

Thank you @mishav! I really appreciate the help, this really helps with understanding what I should be learning, Thanks again!

If you, or anyone else, don’t mind can you tell me if this sounds like I am on the right path.

I have started to writing most of the code that I need in my browser console with manually defined variables and console.log outputs to test it? Then once it works I should be able to move it into Bubble where I can change my test data to dynamic data from bubble and change my console.log operations to actually send data either to the screen or directly to the database?

For anyone following this.

I totally missed this entire example the first time I read through the Plugin Announcement Post post.

Hi @matt3,

Good that you are taking a methodical approach.

Sending to the screen involves building up HTML that gets displayed in the element, as per the example:
div = $('<div></div>'); instance.canvas.append(div);

The way to get data into the database is indirect:

  • Define an “exposed state” and then in the code use the function instance.publishState.
  • Use the element’s published values in a workflow action.

Good luck :slight_smile:

2 Likes

Hey all! thanks for contributing each day! I think I’m not being able to find the right syntax on this.

This is an example of I think it is.

instance.publishState.text_state(properties.text);

basically, I’m trying to pass the text in the text property to a text state. Am I right?

Thanks in advance

Pedro

and I also tried:

text_state is the state
text is the property

instance.publishState(text_state, properties.text);

but it didnt work :frowning:

Thanks!!

Pedro

try this:

instance.publishState("text_state", properties.text);

1 Like

I tried with with quotes but didnt work :frowning:

I tried with single qoutes ‘text_state’, with double quotes “text_state”.

Am I missing something?

Thank you very much!

What result did you get? Any error message?

Have you tried the debugger yet?

1 Like

Now 's it’s working! What happened is that the field was on static text, I put the field in dynamic and it worked! Important to have in mind :wink:

Thanks a lot for your support!

Have a nice day!
Regards
Pedro

1 Like

When i try to access the demo, i get an alert saying I don’t have permission to access.