跳到主要内容

IApiPlugin

The plugin that is provided with the origin, proxy, and prefix to make requests to the portal server.

Example​

The plugin class implements IApiPlugin. ONLYOFFICE Apps fills in the API parameters via setOrigin/setProxy/setPrefix (or setAPI) when the plugin is loaded; the plugin then uses getAPI to build request URLs to the portal.

import { type IApiPlugin } from "@onlyoffice/docspace-plugin-sdk";

class Plugin implements IApiPlugin {
origin = "";
proxy = "";
prefix = "";

setOrigin = (origin: string): void => {
this.origin = origin;
};

setProxy = (proxy: string): void => {
this.proxy = proxy;
};

setPrefix = (prefix: string): void => {
this.prefix = prefix;
};

getOrigin = (): string => {
return this.origin;
};

getProxy = (): string => {
return this.proxy;
};

getPrefix = (): string => {
return this.prefix;
};

setAPI = (origin: string, proxy: string, prefix: string): void => {
this.origin = origin;
this.proxy = proxy;
this.prefix = prefix;
};

getAPI = (): { origin: string; proxy: string; prefix: string } => {
return { origin: this.origin, proxy: this.proxy, prefix: this.prefix };
};

// Example of a custom method that uses the API parameters to call the portal
getUsersList = async (): Promise<unknown> => {
const { origin, proxy, prefix } = this.getAPI();
const response = await fetch(`${origin}${proxy}${prefix}/people`);
return response.json();
};
}

Methods​

setOrigin()​

setOrigin(origin: string): void;

Update the origin parameter of the ONLYOFFICE Apps portal.

Parameters​

ParameterTypeDescription
originstringThe new origin parameter

Returns​

void

setProxy()​

setProxy(proxy: string): void;

Update the proxy parameter of the ONLYOFFICE Apps portal.

Parameters​

ParameterTypeDescription
proxystringThe new proxy parameter

Returns​

void

setPrefix()​

setPrefix(prefix: string): void;

Update the prefix parameter of the ONLYOFFICE Apps portal.

Parameters​

ParameterTypeDescription
prefixstringThe new prefix parameter

Returns​

void

getOrigin()​

getOrigin(): string;

Get the origin parameter of the ONLYOFFICE Apps portal.

Returns​

string

The current origin parameter

getProxy()​

getProxy(): string;

Get the proxy parameter of the ONLYOFFICE Apps portal.

Returns​

string

The current proxy parameter

getPrefix()​

getPrefix(): string;

Get the prefix parameter of the ONLYOFFICE Apps portal to access the server side.

Returns​

string

The current prefix parameter

setAPI()​

setAPI(
origin: string,
proxy: string,
prefix: string): void;

Update all the API parameters of the ONLYOFFICE Apps portal in one request.

Parameters​

ParameterTypeDescription
originstringThe new origin parameter
proxystringThe new proxy parameter
prefixstringThe new prefix parameter

Returns​

void

getAPI()​

getAPI(): {
origin: string;
proxy: string;
prefix: string;
};

Get all the API parameters of the ONLYOFFICE Apps portal in one request.

Returns​

{
origin: string;
proxy: string;
prefix: string;
}

An object containing the current origin, proxy, and prefix parameters

NameType
originstring
proxystring
prefixstring

Properties​

PropertyTypeDescription
originstringStores the origin parameter of the ONLYOFFICE Apps portal
proxystringStores the proxy parameter of the ONLYOFFICE Apps portal
prefixstringStores the prefix parameter of the ONLYOFFICE Apps portal to access the server side