Jump to content

Recommended Posts

Hello everyone!
I am building the front-end for an add-on within the Seeq Data Lab environment. I am trying to call the api endpoint declared in the Jupyter Notebook tab: '# GET /loops' via JavaScript using key functions within the Plugin API of Seeq Data Lab.
In the following code snippet:

api.getDataLabProject(projectName)
  .then((projectResponse) => {
    if (!projectResponse) {
      throw new Error(`No response received when fetching project: ${projectName}`);
    }

    const projectId = projectResponse.projectId;

    if (!projectId) {
      throw new Error(`Project with name "${projectName}" not found.`);
    }

    // Step 2: Call the Data Lab API using the retrieved project ID
    return api.callDataLabApi({
      projectId: projectId,
      notebookName: notebookName,
      path: apiPath,
      method: 'GET', // or 'POST', 'PUT', 'DELETE', etc.
      headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
      }
    });
  })

I'm having an error about api in api.getDataLabProject, in browser's developer console, console it shows: ReferenceError: api is not defined
From the info I could find this is a part of Plugin API lib of Seeq and if I am in Seeq Data Lab environment by default it is a known library. Is info I got right or 'api' is just a custom object? Can someone help me with this issue? 
 

Thanks!

Screenshot from 2024-08-22 11-56-49.png

Edited by Eolian Tomcini
Link to comment
Share on other sites

  • Seeq Team

Good Question.  The `api` needs to be initialized prior to being used.  This is done with the `getSeeqApi` function.  Here is a snippet of what that initialization might look like. 

 

// initialize the api variable
let api

// check if api has already been initialized
if (!api) {
  await getSeeqApi()
  // Call the function `getSeeqApi()`.
    .then(async function (_seeq) {
    // Assign the return value of `getSeeqApi()` to the variable `seeq`.
    api.set(_seeq)

  })
    .catch((error: Error) => {
    console.log("getSeeqApi ERROR", error);
  });

}


//Continue to use the api 

 

Link to comment
Share on other sites

  • Seeq Team
  • Solution

@Eolian Tomcini, Is the error showing after the Add-on is packaged and installed with the Add-on Manager? 

One reason for this may be that the SDK script is not loaded.  In your `index.html` be certain import the script.

<script src="/api/plugins/sdk/seeq.js"></script>

 

Link to comment
Share on other sites

Thank you John, I didn't know about seeq.js lib.  At the moment I have no error even though the data still does not appear. Anyway, I will have to check the code a bit to make sure I haven't made any mistakes.
Thank you once again!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...