Contents

Cancel

Recommended Articles

  1. unify-apps

    Indexing

    Unify AI

    Transform raw content into searchable knowledge through AI-powered indexing and vector embeddings

  2. unify-apps

    IMAP

    Unify Integrations

    Integrate your app with IMAP to enable seamless email synchronization, real-time access, and enhanced communication workflows.

  3. unify-apps

    Preview Your Work

    Unify Automations

    Effortlessly review & monitor your automation’s performance

  4. unify-apps

    QuickBooks

    Unify Integrations

    Integrate your app with QuickBooks to streamline accounting, automate invoicing, and manage finances effortlessly

  5. unify-apps

    FTP/FTPS

    Unify Integrations

    Connect your app with FTP/FTPS to automate secure file transfers and streamline data exchange across systems.

  6. unify-apps

    Snowflake

    Unify Automations

    Connect to Snowflake for fast, scalable cloud data warehousing and analytics

  7. unify-apps

    Button

    Unify Applications

    Create interactive elements with ease using buttons

  8. unify-apps

    BambooHR

    Unify Automations

    Integrate your app with BambooHR to streamline HR management, automate employee data processing, and enhance onboarding workflows

  9. unify-apps

    Build your first automation

    Unify Automations

    Learn how to build your automation step by step

  10. unify-apps

    User Management

    Unify Applications

    Efficiently manage user roles and permissions

  11. unify-apps

    Microsoft Teams

    Unify Automations

    Connect your app with Microsoft Teams to enhance communication, automate workflows, and foster collaboration across your organization

  12. unify-apps

    Jira

    Unify Automations

    Use Jira to plan, track, and manage your agile and software development projects

  13. unify-apps

    Pre Processing

    Unify AI

    Optimize query processing through intelligent rephrasing, retrieval, and ranking to deliver accurate AI responses

  14. unify-apps

    Google Calendar

    Unify Integrations

    Integrate your app with Google Calendar to streamline scheduling, automate event management, and improve team coordination

  15. unify-apps

    SAP HANA

    Unify Integrations

    Connect your app with SAP HANA to leverage in-memory computing for real-time data processing and advanced analytics at scale.

#
Unify Integrations
Logo
App Embed

App Embed

Logo

5 mins READ

Please follow the below instructions for installation through NPM/Javascript.

Via NPM

Installation

To install the package, use npm:

npm install @unifyapps/sdk-react

Usage

Rendering an application

Render UAProvider, and pass the necessary props. Then, use the WebApplication component to render the UI.

import React from 'react';
import ReactDOM from 'react-dom';
import { UAProvider, WebApplication } from '@unifyapps/sdk-react';
const options = {
  host: '<HOST_NAME>',
  token: '<SESSION_ID>',
  identityProviderId: '<IDP_ID>',
};
// Example: { host: 'https://prod.unifyapps.com', token: '123456789', identityProviderId: '123456789' }
const webApplicationProps = {
  applicationId: '<APPLICATION_ID>',
  pageId: '<PAGE_ID>',
  pageInputs: '<PAGE_INPUTS>',
};
// Example: { applicationId: 'my_app' }
const App = () => (
  <UAProvider options={options}>
    <WebApplication {...webApplicationProps} />
  </UAProvider>
);
ReactDOM.render(<App />, document.getElementById('root'));

Props

  • UAProvider

    • options: An object containing configuration options for the provider.

      • host: The base URL of the host application

      • token: The token to authenticate the user

      • identityProviderId: Identity provider, required for authentication

  • WebApplication: Renders application made via UnifyApps platform.

    • applicationId: ID of the application. Application ID you can get from application's overview page on UnifyApps platform

    • pageId (optional): Page ID of the application. Page ID you can get from application's page settings (Page URL field)

    • pageInputs (optional): Page inputs required to render the applications's page, if any.


Via JavaScript

Installation

To use the js snippet to embed your application, copy the following code and paste it in your HTML file.

<script>
    window.unifyAppsSettings = {
        host: '<HOST_NAME>',
        token: '<SESSION_ID>',
        identityProviderId: '<IDP_ID>',
        applicationId: '<APPLICATION_ID>',
        pageId: '<PAGE_ID>',
        pageInputs: '<PAGE_INPUTS>',
        containerEl: '<CONTAINER_ELEMENT>',
    };
    (function() {
        var w = window,
            ua = w.UnifyApps;
        if (typeof ua === 'function') {
            ua('update', w.unifyAppsSettings);
        } else {
            var d = document,
                u = function() {
                    u.c(arguments);
                };
            u.q = [];
            u.c = function(args) {
                u.q.push(args);
            };
            w.UnifyApps = u;
            w.UnifyApps('init');
            var l = function() {
                var s = d.createElement('script');
                s.type = 'text/javascript';
                s.async = true;
                s.src = window.unifyAppsSettings.host + '/lib/delta-matrix/ua-web-sdk.js';
                var x = d.getElementsByTagName('script')[0];
                x.parentNode.insertBefore(s, x);
            };
            if (document.readyState === 'complete') {
                l();
            } else if (w.attachEvent) {
                w.attachEvent('onload', l);
            } else {
                w.addEventListener('load', l, false);
            }
        }
    })();
</script>

Props

  • host (required): The base URL of the host application

  • token (required): The temporary session id to authenticate the user

  • identityProviderId (required): Identity provider, required for authentication

  • applicationId (required): Application ID: The unique identifier of the application. Retrieve this from the application's overview page in UnifyApps platform

  • pageId (optional): Page ID: If a specific page needs to be opened. Retrieve this from inside application's page settings (Page Slug)

  • pageInputs (optional): Page inputs required to render the application's page

  • containerEl (optional): The element where the application will be rendered. If not provided, the application will be rendered in the body of the page

How to get the required parameters. Contact support@unifyapps.com

  1. HOST_NAME

  2. IDP_ID

  3. APPLICATION_ID

Replace these values in the code snippet above.

Authenticating a user

Authentication via Auth Token

Make a request to an endpoint with the required parameters to get the session id.

Example in NodeJS

const URL = '<HOST_NAME>/auth/createUserExternalLoginSession';
const AUTH_TOKEN = '<AUTH_TOKEN>';
const data = {
  identityProviderId: '<IDP_ID>',
  formData: {
    username: '<USER_NAME>',
    name: '<NAME>',
    email: '<USER_EMAIL>',
  },
};
// Example data:
// {
//   identityProviderId: '123456789',
//   formData: {
//     username: 'user',
//     name: 'Full name',
//     email: 'user@domain.com',
//   }
// }
// Make a POST request to create a user session
async function makeRequest(applicationId: string) {
  try {
    const response = await fetch(URL, {
      method: 'POST',
      headers: {
        Authorization: `Bearer ${AUTH_TOKEN}`,
        'Content-Type': 'application/json',
        'x-ua-app': applicationId,
      },
      body: JSON.stringify(data),
    });
    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }
    const responseData = await response.json();
    // Example responseData: {"sessionId":"<SESSION_ID>"}
    console.log('Success:', responseData);
    return responseData;
  } catch (error) {
    console.error('Error:', error);
  }
}
// Pass this sessionId to the UAProvider options in the token field
const { sessionId: SESSION_ID } = await makeRequest(applicationId);

How to get the required parameters. Contact support@unifyapps.com

  1. HOST_NAME

  2. AUTH_TOKEN

  3. IDP_ID

  4. APPLICATION_ID

  5. NPM details: To access the package, you need to have these npm package details, since it's a private repo.