FileMaker Data Api wrapper for Vue.js
npm install fm-data-apiA Javascript wrapper based on "myFMApiLibrary for Javascript" by Lesterius (Claris) and using axios library to perform REST request to the FileMaker Data Api
=======================
You will be able to use every functions like it's documented in your FileMaker server Data Api documentation (accessible via https://[your server domain]/fmi/data/apidoc).
General Claris document on the Data API is available here
The recommended way to install it is with :
``bash`
npm install fm-data-api
After installing, you can call this javascript library by adding:
`js`
import DataApi from 'fm-data-api'
In your Javascript application.
1. Enable the FileMaker Data API option on your FileMaker server admin console.
2. Create a specific user in your FileMaker database with the 'fmrest' privilege
3. Define records & layouts access for this user
Login with credentials:
`javascript
let options = {
'apiUrl': 'https://test.fmconnection.com/fmi/data',
'databaseName' : 'MyDatabase',
'login' : 'filemaker api user',
'password' : 'filemaker api password'
};
let api = new DataApi(options);
`
Login with oauth:
`javascript
let options = {
'apiUrl': 'https://test.fmconnection.com/fmi/data',
'databaseName' : 'MyDatabase',
'oAuthRequestId' : 'oAuthIdentifier',
'oAuthIdentifier' : 'oAuthIdentifier'
};
let api = new DataApi(options);
`
Use only generated token:
`javascript
let options = {
'apiUrl': 'https://test.fmconnection.com/fmi/data',
'databaseName' : 'MyDatabase',
'token' : 'generated token'
};
let api = new DataApi(options);
`
To re generate a token, use 'login' function.
/!\\ Not available with 'Login with token' method, use 'setApiToken' function.
`javascript`
dataApi.logout();
`javascript`
dataApi.validateSession();
`javascript
let data = {
'FirstName' : 'John',
'LastName' : 'Doe',
'email' : 'johndoe@acme.inc'
};
let scripts = [
{
'name' : 'ValidateUser',
'param' : 'johndoe@acme.inc',
'type' : SCRIPT_PREREQUEST
},
{
'name' : 'SendEmail',
'param' : 'johndoe@acme.inc',
'type' : SCRIPT_POSTREQUEST
}
];
let portalData = {
'portalName or OccurenceName' : [
{
"Occurence::PortalField 1" : "Value",
"Occurence::PortalField 2" : "Value",
}
]
};
dataApi.createRecord('layout name', data, scripts, portalData).then((recordId) => {
console.log(recordId)
// display the recordId's new record.
});
`
`javascript`
dataApi.deleteRecord('layout name', recordId, script);
`javascript`
dataApi.editRecord('layout name', recordId, data, lastModificationId, portalData, scripts).then((recordId) => {
console.log(recordId)
// display the recordId's edit record.
});
`javascript`
dataApi.duplicateRecord('layout name', recordId, scripts).then((recordId) => {
console.log(recordId)
// display the recordId's new record.
});
`javascript
let portals = [
{
'name' : 'Portal1',
'limit' : 10
},
{
'name' : 'Portal2',
'offset' : 3
}
];
dataApi.getRecord('layout name', recordId, portals, scripts).then((record) => {
console.log(record)
// display the wished record.
});
`
`javascript
let sort = [
{
'fieldName' : 'FirstName',
'sortOrder' : 'ascend'
},
{
'fieldName' : 'City',
'sortOrder' : 'descend'
}
];
dataApi.getRecords('layout name', sort, offset, limit, portals, scripts).then((record) =>{
console.log(record)
// display the wished records.
});
`
`javascript
let query1 = [
{
'fields' : [
{ fieldname : 'd_firstName', fieldvalue : '==Jean'},
{ fieldname : 'd_lastName', fieldvalue : '==Dupond'},
{ fieldname : 'd_age', fieldvalue : '30'},
{ fieldname : 'd_height', fieldvalue : '160...180'},
{ fieldname : 'd_sex', fieldvalue : 'male'},
]
}
];
dataApi.findRecords('layout name', query1, sort, offset, limit, portals, scripts, dataInfo, responseLayout).then((record) => {
console.log(record)
// display the wished record.
});
let query2 = [
{
'fields' : [
{ fieldname : 'd_firstName', fieldvalue : '==Jean'},
{ fieldname : 'd_lastName', fieldvalue : '==Dupond'},
{ fieldname : 'd_age', fieldvalue : '30'},
{ fieldname : 'd_height', fieldvalue : '160...180'},
{ fieldname : 'd_sex', fieldvalue : 'male'},
{ omit : true }
]
}
];
dataApi.findRecords('layout name', query2, sort, offset, limit, portals, scripts, dataInfo, responseLayout).then((record) => {
console.log(record)
// display the wished record.
});
let query3 = [
{
'fields' : [
{ fieldname : 'd_firstName', fieldvalue : '==Marie'},
{ fieldname : 'd_age', fieldvalue : '20...30'},
]
},
{
'fields' : [
{ fieldname : 'd_firstName', fieldvalue : '==Ernest'},
{ fieldname : 'd_height', fieldvalue : '150...180'},
{ fieldname : 'd_sex', fieldvalue : 'male'},
]
}
];
dataApi.findRecords('layout name', query3, sort, offset, limit, portals, scripts, dataInfo, responseLayout).then((record) => {
console.log(record)
// display the wished record.
});
`
In this example of request query1 will find people named Jean Dupond AND who are 30 years old AND with an height between 160 and 180 cm AND who are male.
query2 will find all the people who don't match these criteria
query3 will find people named Marie AND who are between 20 and 30 years old, OR people named Ernest AND with an height between 150 and 180 cm AND who are male.
The dataInfo option is by default on false, on true it will provide the records on this form :
`javascript`
{
"response": {
"dataInfo": {
"database": "XXXXX",
"layout": "XXXXX",
"table": "XXXXX",
"totalRecordCount": 29,
"foundCount": 29,
"returnedCount": 9
},
"data": [{
"fieldData": {
"d_descriptif": "zzzzz",
"d_prix": "zzzzz",
.
.
.
},
"portalData": {},
"recordId": "35",
"modId": "0"
}, {
"fieldData": {
"d_descriptif": "zzzzz",
"d_prix": "zzzzz",
.
.
.
},
"portalData": {},
"recordId": "32",
"modId": "2"
},
.
.
.
]
},
"messages": [{
"code": "0",
"message": "OK"
}]
}
which bring the data foundCount, for example. By default the data form is :
`javascript`
[
{
"fieldData": {
"d_descriptif": "zzzzz",
"d_prix": "zzzzz",
.
.
.
},
"portalData": {},
"recordId": "35",
"modId": "0"
}, {
"fieldData": {
"d_descriptif": "zzzzz",
"d_prix": "zzzzz",
.
.
.
},
"portalData": {},
"recordId": "32",
"modId": "2"
},
.
.
.
]
`javascript
let data = {
'FieldName1' : 'value',
'FieldName2' : 'value'
};
dataApi.setGlobalFields('layout name', data);
`
`javascript`
dataApi.executeScript('script name', scriptsParams).then((result) => {
console.log(result)
// display the script result.
});
`javascript
dataApi.uploadToContainer('layout name', recordId, containerFieldName, containerFieldRepetition, file);
`
#### Product Info
`javascript`
dataApi.getProductInfo();
#### Database Names
/!\\ Not available with 'Login with token' method
`javascript`
dataApi.getDatabaseNames();
#### Layout Names
`javascript`
dataApi.getLayoutNames();
#### Script Names
`javascript`
dataApi.getScriptNames();
#### Layout Metadata
`javascript``
dataApi.getLayoutMetadata('layout name', recordId);