Skip to content

DataAPI SDK english MT.DataAPI Constructor

Taku AMANO edited this page Aug 28, 2013 · 8 revisions

Constructor

Parameters

Name Type Required Description
options Object yes Options.
options.clientId String yes Client ID
This value allows alphanumeric, (_)underscore, (-)dash.
options.baseUrl String yes The absolute CGI URL of the DataAPI.
(e.g. http://example.com/mt/mt-data-api.cgi)
options.format String The format to serialize.
options.sessionStore String The session store.
In browser, the cookie is used by default.
options.sessionDomain String The session domain.
When using the cookie, this value is used as cookie domain.
options.sessionPath String The session path.
When using the cookie, this value is used as cookie path.
options.async String If true, use asynchronous XMLHttpRequest.
The default value is the true.
options.timeout Number The number of milliseconds a request can take before automatically being terminated.
The default value is not set up, browser's default is used.
options.withoutAuthorization Boolean If true, the "X-MT-Authorization" request header is not sent even if already got accessToken.
The default value is the false.
options.loadPluginEndpoints Boolean If true, load endpoint data extended by plugin and generate methods to access that endpoint automatically.
The default value is the true.
(However even if this option's value is false, you are able to use all the methods to access to core endpoint.)
options.suppressResponseCodes Boolean If true, add suppressResponseCodes parameter to each request. As a result, the Data API always returns 200 as HTTP response code.
The default value is the false when requested via XMLHttpRequest or IFRAME. The default value is the true when requested via XDomainRequest.
options.crossOrigin Boolean If true, requests are sent as a cross-origin request.
The default value is assigned automatically by document's URL and baseUrl.
options.cache String If false, add an additional parameter "_" to request to avoid cache.
The default value is the true.
options.disableFormData String If false, use FormData when available that.
The default value is the false.

Example

Specify minimal options.

var api = new MT.DataAPI({
  clientId: "your-client-id",
  baseUrl:  "https://your-host/your-mt-api.cgi"
});

Specify all options explicitly.

var api = new MT.DataAPI({
  clientId: "your-client-id",
  baseUrl:  "https://your-host/your-mt-api.cgi",
  format: "json",
  sessionStore: "cookie",
  sessionDomain: "your-host",
  sessionPath: "/client-app/",
  async: true,
  timeout: 1000,
  withoutAuthorization: false,
  loadPluginEndpoints: true,
  suppressResponseCodes: false,
  crossOrigin: false,
  cache: true,
  disableFormData: false
});

Using as a library for Node.js

var api = new MT.DataAPI({
  clientId: "your-client-id",
  baseUrl:  "https://your-host/your-mt-api.cgi",
  sessionStore: "fs",
  sessionPath: "/home/your-login/.mt-data-api.json"
});
Clone this wiki locally