Skip to main content
Question

How to invoke external REST API from inside LucidChart extension plugin

  • 10 July 2024
  • 2 replies
  • 45 views

I am trying to call an external REST API the way shown below, the script runs well through debug-server, but it fails with error when it is packaged and uploaded to run normally. 

import {EditorClient, Menu, MenuType, Viewport} from 'lucid-extension-sdk';
import {prepareData} from './preparedata';
import axios from 'axios';

const client = new EditorClient();
const menu = new Menu(client);
const viewport = new Viewport(client);

client.registerAction('testAction', () => {
const data = new prepareData(client,viewport);
data.analyzeData();

const response = axios.get('https://google.com')
console.log(response)
});

menu.addMenuItem({
label: 'test label',
action: 'testAction',
menuType: MenuType.Main,
});

Also the code below was tried out with 

 

import {EditorClient, Menu, MenuType, Viewport,XHRRequest} from 'lucid-extension-sdk';
import {prepareData} from './preparedata';
import axios from 'axios';

const client = new EditorClient();
const menu = new Menu(client);
const viewport = new Viewport(client);

client.registerAction('testAction', () => {
const data = new prepareData(client,viewport);
data.analyzeData();

var request : XHRRequest = {url:'https://google.com',method:'GET',headers:{'Content-Type':'application/json'},data:"Hi"}
const response = client.xhr(request)
console.log(response)
});

menu.addMenuItem({
label: 'test label',
action: 'testAction',
menuType: MenuType.Main,
});

With the XHRRequest I get the following error message

 

Could you explain how to do it the right/intended way?

Comments

Userlevel 3
Badge +4

Hi KGV!

This is a fairly technical question that we will want one of our developers to look at. However, for the rest of this week our developers are involved in an internal hackathon, so we unfortunately may not be able to answer until next week. I’ll let the devs know, but a response may take us a few days.

Thanks for building on our platform!

Badge +3

@Richard U any insight?

Reply