REST API Document

Contents

com.enonic.xp.web.vhost.cfg
mapping.api.host = localhost
mapping.api.source = /api
mapping.api.target = /webapp/com.enonic.app.explorer/api
mapping.api.idProvider.system = default

Get

Headers

Name Attributes Value Details

Accept

<optional>

application/json

What MIME-type the client wants in the response

Content-Type

<required>

application/json

What type of data is sent in the request body

Authorization

<required>

Explorer-Api-Key password

A valid API key (password) for the collection you want to get documents from.

Parameters

Name Type Attributes Default Details

id

String

<optional>

Id of document to get. May supply multiple. Will be converted into a query filter on the serverside.

count

Integer

<optional>

10

How many documents to get.

start

Integer

<optional>

0

Start index (used for paging).

filters

JSON

<optional>

{}

query

JSON

<optional>

{}

Query expression. Keep in mind that filters are usually more quicker. See documentation. https://developer.enonic.com/docs/xp/stable/storage/noql

sort

String

<optional>

score DESC

Sorting expression.

Example

Requesting in some controller
import {request} from '/lib/http-client';

const COLLECTION = 'collectionName';
const AUTHORIZATION = 'Explorer-Api-Key apiKey';

export function get() {
  const response = request({
    contentType: 'application/json'
    headers: {
      'Accept': 'application/json',
      'Authorization': AUTHORIZATION
    },
    method: 'GET',
    params: {
      count: 2,
      start: 0,
      filters: JSON.stringify({
        boolean: {
          must: {
            exists: {
              field: 'url'
            }
          }
        }
      }),
      sort: 'score DESC'
    },
    url: `http://localhost:8080/api/v1/collections/${COLLECTION}/documents`,
  });
}

Sample response

[
  { "_id": "7b89af94-32a9-4e39-aedb-c553675a3287" },
  { "_id": "2dec6e83-3cad-426a-ab7d-c7dabd3592f0" },
]

Post

Headers

Name Attributes Value Details Accept

<optional>

application/json

What MIME-type the client wants in the response

Content-Type

<required>

application/json

What type of data is sent in the request body

Authorization

<required>

Explorer-Api-Key password

Parameters

Name Type Attributes Default Details

requireValid

String

<optional>

true

The data has to be valid, according to the field types, to be created or updated. If requireValid=true and the data is not strictly valid, an error will be returned.

partial

String

<optional>

false

When true, values are only added or updated. Unprovided values are not removed.

Example

Requesting in some controller
import {request} from '/lib/http-client';

const COLLECTION = 'collectionName';
const AUTHORIZATION = 'Explorer-Api-Key apiKey';

export function get() {
  const response = request({
    body: [{
	available: true,
	count: -999999999999999,
	date: '2021-01-01',
	datetime: '2021-01-01T00:00:00',
	instant: '2021-01-01T00:00:00Z',
	location: '59.9090442,10.7423389',
	price: -999999999999999.9,
	time: '00:00:00',
	language: 'english',
	text: 'This domain is for use in illustrative examples in documents. You may use this domain in literature without prior coordination or asking for permission.',
	title: 'Example Domain',
	url: 'https://www.example.com'
},{
	available: false,
	count: 999999999999999,
	date: '2021-12-31',
	datetime: '2021-12-31T23:59:59',
	instant: '2021-12-31T23:59:59Z',
	location: [
		59.9090442,
		10.7423389
	],
	price: 999999999999999.9,
	time: '23:59:59',
	language: 'english',
	text: 'Whatever',
	title: 'Whatever',
	url: 'https://www.whatever.com'
}],
    contentType: 'application/json'
    headers: {
      'Accept': 'application/json',
      'Authorization': AUTHORIZATION
    },
    method: 'POST',
    params: {
      requireValid: true,
      partial: false
    },
    url: `http://localhost:8080/api/v1/collections/${COLLECTION}/documents`,
  });
}

Sample response

[
  { "_id": "7b89af94-32a9-4e39-aedb-c553675a3287" },
  { "_id": "2dec6e83-3cad-426a-ab7d-c7dabd3592f0" },
]

Delete

Headers

Name Attributes Value Details

Accept

<optional>

application/json

What MIME-type the client wants in the response

Content-Type

<optional>

application/json

What type of data is sent in the request body

Authorization

<required>

Explorer-Api-Key password

A valid API key (password) for the collection you want to get documents from.

Parameters

Name Type Attributes Details

id

String

<required>

Id of document to delete. May supply multiple.

Example

Requesting in some controller
import {request} from '/lib/http-client';

const COLLECTION = 'collectionName';
const AUTHORIZATION = 'Explorer-Api-Key apiKey';

export function get() {
  const response = request({
    contentType: 'application/json'
    headers: {
      'Accept': 'application/json',
      'Authorization': AUTHORIZATION
    },
    method: 'DELETE',
    params: {
      id: '7b89af94-32a9-4e39-aedb-c553675a3287'
    },
    url: `http://localhost:8080/api/v1/collections/${COLLECTION}/documents`,
  });
}

Sample response

[
  { "_id": "7b89af94-32a9-4e39-aedb-c553675a3287" },
]

Contents

Contents