DropDownList + Data API

I want to get data from google API to Dropdownlist on new node. Can I use AJAX to call request and recieve data to my dropdownlist? If yes, how to I use it. Thank you~

Yes, you can use jQuery or native JavaScript AJAX calls to do this. Please refer to the appropriate jQuery or JavaScript documentation on the details.

You will find plenty of examples in existing nodes. uibuilder for example has several calls although they are requests back to Node-RED. However the principle is exactly the same.

1 Like

Sorry, I don't see any dropdown list in uibuilder

In addition, Can I get oauth token from file .JS?

If you click on "Edit Source Files", you will see some drop-downs.

In addition, I use API's calls to populate the list of libraries that you see when you click on "Manage front-end libraries".

Check out the html file and you will see the code that calls the API's.

You will need to explain more I'm afraid. What are you trying to achieve? In the Node-RED editor, authentication and authorisation are handled internally. If you specify an API on the admin server, you can pass an authentication level that users must possess in order to be able to access the API. Have a look at uibuilder's js file, the API's are defined at the end.

However, you should note a recent thread in the forum about whether or not the admin authorisation works the way it is supposed to as a few of us have experienced odd issues.

I intend to create drop-down list to show list email from API google calendar, I'm using oauth based on node-red-node-google to request API. I want to call api google in oneditprepare: function() {} by AJAX

oneditprepare: function() {
$.ajax({
        headers: {
            "Content-Type": "application/json",
            "Authorization": "Bearer " + **node.googleAPI.credentials.accessToken** (I want to get this from file google.js in node-red-node-google)
        },
        url: "https://www.googleapis.com/calendar/v3/users/me/calendarList",
        method: 'GET'
    }).then(function(data) {
        $("#node-input-dropdown").append('<option>data</option>');
    });
}

I wonder if you could help me with this?

I haven't used the Google API's for quite a while I'm afraid. So I don't know off the top of my head.

However, perhaps this will help?

Thank you for suggest. But, Do you know how to get variable or function from .js file to .html file?

Use a file in node to read your file the send the contents to UI builder. The extensive information that is included with UI builder (and the wiki) shows you how to send values into UI builder.

Sorry, I don't understand what you mean. Can you talk detail about this?

Not sure what you mean?

My last post was about using the Google API's directly. You should be able to do that directly in your node's html file in the script section.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.