Accessing the SGS API

SkylineGlobe Server includes a GraphQL API that provides flexible, query-based access to server data. This API allows clients to request exactly the data they need and perform operations such as retrieving layers, users, and service configurations - all through a single endpoint.

The SkylineGlobe Server (SGS) API can be accessed and tested using Nitro (formerly known as Banana Cake Pop), a user-friendly GraphQL Integrated Development Environment (IDE). Nitro provides a visual interface for exploring your GraphQL API, writing and running queries or mutations, viewing the schema, and debugging responses - directly from your browser.

Using Nitro to Access SGS API

To use Nitro to access SGS API:

1.      Log in to SGS: Open [SkylineGlobeServerURL]/Admin/Login in your browser and enter your username and password.

2.      Access the GraphQL interface. If SGS is deployed on a remote server, open http://[SkylineGlobeServerURL]/graphql in your browser.

Note:       A separate Nitro sign-in is not required.

3.      Click Create Document.

4.      On the Operation tab, click Operation Builder .

5.      In the Builder panel, click + and select one of the following:

§  New Query – to retrieve system information

§  New Mutation – to add or modify data

6.      Enter a name for your operation and press Enter.

7.      In the Builder panel, expand the operation name to display a list of the available operations. Select the check box next to the query or mutation you want to run (e.g., HelpSettings).

8.      In the Builder panel, expand the operation further to select the required parameters. The query is generated in the Request panel. Enter the required parameter values.

9.      Click Run  to run the operation. The response is displayed in the Response panel.

Examples

Query: Retrieving Help Settings

query test {

       HelpSettings {

        allowExternalLinks

        errorMessage

        knowledgeBaseURL

        videoTutorialsURL

       }

      }

Mutation: Adding a Category

mutation test {

       AddCategory(categoryInputDto: { name: "category1" }) {

        actionResultDtoList {

         errorMessage

         key

         successStatus

        }

       }

      }

 

Programmatically Accessing SGS API

Access to the SkylineGlobe Server (SGS) GraphQL API requires a valid authentication cookie (SGAuth) issued by the SGS web application. When you log in through the SGS web interface, the server creates this cookie in your browser and Nitro uses it automatically. For custom applications, however, you need to obtain the cookie and include it manually in the GraphQL request headers.

To obtain this cookie outside the browser environment, you can connect to the SGS API programmatically from your own scripts or applications. This method allows developers to authenticate through the SGS API, obtain the required SGAuth cookie, and send GraphQL queries directly to the server without using the browser interface.

The example below demonstrates how to log in through the SGS API, extract the authentication cookie from the login response, and use it to send an authenticated GraphQL request.

Example: Logging in and Querying GraphQL

// loginAndQuery.js

// Node 18+ (uses built-in fetch)

 

const baseURL = 'https://cloud.skylineglobe.com'; // single base URL reference

 

const loginPayload = {

  request: 'login',

  username: 'USER',       // change to your Skyline username

  password: 'PASSWORD',   // change to your Skyline password

  isPersistent: true

};

 

const query = `

  query sites {

    Sites {

      errorMessages

      storageUsed

      totalSites

      siteDtoList {

        id

        name

        description

        dateCreated

        expirationDate

        isActive

        isDefault

        isPublicProjectAllowed

        isTefPlusAllowed

        storageUsed

      }

    }

  }

`;

 

(async () => {

  try {

    // === LOGIN ===

    const loginRes = await fetch(`${baseURL}/Default/ConnectSG`, { // 👈 hardcoded path

      method: 'POST',

      headers: {

        'Accept': 'application/json',

        'Content-Type': 'application/js'

      },

      body: JSON.stringify(loginPayload)

    });

 

    if (!loginRes.ok) throw new Error(`Login failed: ${loginRes.status}`);

    const loginData = await loginRes.json();

    console.log('\n===== LOGIN RESPONSE =====');

    console.log(loginData);

 

    // === Extract cookie(s) ===

    let rawCookies = [];

    if (typeofloginRes.headers.raw === 'function') {

      const raw = loginRes.headers.raw();

      rawCookies = raw['set-cookie'] || [];

    } else {

      const single = loginRes.headers.get('set-cookie');

      if (single) rawCookies = [single];

    }

 

    // Handle multiple cookies in one header

    rawCookies = rawCookies.flatMap(c => c.split(/,(?=\s*[A-Za-z0-9_\-]+=)/));

 

    // Find SGAuth cookie

    const sgAuthCookie = rawCookies

      .map(c => c.trim())

      .find(c => c.includes('SGAuth='));

 

    if (!sgAuthCookie) {

      console.warn('\n⚠️  SGAuth cookie not found in login response.');

      console.log('Raw cookies:', rawCookies);

      return;

    }

 

    // Extract only "SGAuth=...."

    const cookieHeader = sgAuthCookie

      .split(';')[0]

      .trim();

 

    console.log('\nUsing cookie:', cookieHeader, '\n');

 

    // === GRAPHQL REQUEST ===

    const gqlRes = await fetch(`${baseURL}/graphql`, { // 👈 hardcoded path

      method: 'POST',

      headers: {

        'Content-Type': 'application/json',

        'Cookie': cookieHeader

      },

      body: JSON.stringify({ query })

    });

 

    if (!gqlRes.ok) throw new Error(`GraphQL query failed: ${gqlRes.status/pan>}`);

    const gqlData = await gqlRes.json();

 

    console.log('===== GRAPHQL RESPONSE =====');

    console.dir(gqlData, { depth: null });

 

    // === Print site list ===

    console.log('\n===== SITE LIST =====');

    const sites = gqlData?.data?.Sites?.siteDtoList || [];

    sites.forEach((s, i) => {

      console.log(`${i + 1}. ${s.name} (${s.id}) - Active: ${s.isActive}`);

    });

 

  } catch (err) {

    console.error('\nError:', err);

  }

})();