PHP code example of myfmbutler / myfmapilibrary-for-php

1. Go to this page and download the library: Download myfmbutler/myfmapilibrary-for-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

myfmbutler / myfmapilibrary-for-php example snippets




$dataApi = new \Lesterius\FileMakerApi\DataApi('https://test.fmconnection.com/fmi/data', 'MyDatabase', null, 'filemaker api user', 'filemaker api password');

$dataApi = new \Lesterius\FileMakerApi\DataApi('https://test.fmconnection.com/fmi/data', 'MyDatabase', null, null, true, 'oAuthRequestId', 'oAuthIdentifier');


$dataApi->logout();


$dataApi->validateSession();


$data = [
    'FirstName'         => 'John',
    'LastName'          => 'Doe',
    'email'             => '[email protected]',
    'RepeatingField(1)' => 'Test'
];

$scripts = [
    [
        'name'  => 'ValidateUser',
        'param' => '[email protected]',
        'type'  => Lesterius\FileMakerApi\DataApi::SCRIPT_PREREQUEST
    ],
    [
        'name'  => 'SendEmail',
        'param' => '[email protected]',
        'type'  => Lesterius\FileMakerApi\DataApi::SCRIPT_POSTREQUEST
    ]
];

$portalData = [
  'portalName or OccurenceName' => [
      [
          "Occurence::PortalField 1" => "Value",
          "Occurence::PortalField 2" => "Value",
      ]
  ]
];

try {
    $recordId = $dataApi->createRecord('layout name', $data, $scripts, $portalData);
} catch(\Exception $e) {
  // handle exception
}


try {
  $dataApi->deleteRecord('layout name', $recordId, $script);
} catch(\Exception $e) {
  // handle exception
}


try {
  $recordId = $dataApi->editRecord('layout name', $recordId, $data, $lastModificationId, $portalData, $scripts);
} catch(\Exception $e) {
  // handle exception
}


try {
  $recordId = $dataApi->editRecord('layout name', $recordId, $scripts);
} catch(\Exception $e) {
  // handle exception
}


$portals = [
    [
        'name'  => 'Portal1',
        'limit' => 10
    ],
    [ 
        'name'   => 'Portal2',
        'offset' => 3
    ]
];

try {
  $record = $dataApi->getRecord('layout name', $recordId, $portals, $scripts);
} catch(\Exception $e) {
  // handle exception
}


$sort = [
    [
        'fieldName' => 'FirstName',
        'sortOrder' => 'ascend'
    ],
    [
        'fieldName' => 'City',
        'sortOrder' => 'descend'
    ]
];

try {
  $record = $dataApi->getRecords('layout name', $sort, $offset, $limit, $portals, $scripts);
} catch(\Exception $e) {
  // handle exception
}


$query = [
    [
        'fields'  => [
            ['fieldname' => 'FirstName', 'fieldvalue' => '==Test'],
            ['fieldname' => 'LastName', 'fieldvalue' => '==Test'],
        ],
        'options' => [
            'omit' => false
        ]
    ]
];

try {
  $results = $dataApi->findRecords('layout name', $query, $sort, $offset, $limit, $portals, $scripts, $responseLayout);
} catch(\Exception $e) {
  // handle exception
}


$data = [
  'FieldName1'	=> 'value',
  'FieldName2'	=> 'value'
];

try {
  $dataApi->setGlobalFields('layout name', $data);
} catch(\Exception $e) {
  // handle exception
}



try {
  $dataApi->executeScript('script name', $scriptsParams);
} catch(\Exception $e) {
  // handle exception
}


$containerFieldName       = 'Picture';
$containerFieldRepetition = 1;
// replace 'upload' below with the name="value" of the file input element of your web form
$filepath                 = $_FILES['upload']['tmp_name'];
$filename                 = $_FILES['upload']['name'];

try {
  $dataApi->uploadToContainer('layout name', $recordId, $containerFieldName, $containerFieldRepetition, $filepath, $filename);
} catch(\Exception $e) {
  // handle exception
}


$containerFieldName       = 'Picture';
$containerFieldRepetition = 1;
$filepath                 = '/usr/home/acme/pictures/photo.jpg';

try {
  $dataApi->uploadToContainer('layout name', $recordId, $containerFieldName, $containerFieldRepetition, $filepath);
} catch(\Exception $e) {
  // handle exception
}


try {
  $dataApi->getProductInfo();
} catch(\Exception $e) {
  // handle exception
}


try {
  $dataApi->getDatabaseNames();
} catch(\Exception $e) {
  // handle exception
}


try {
  $dataApi->getLayoutNames();
} catch(\Exception $e) {
  // handle exception
}


try {
  $dataApi->getScriptNames();
} catch(\Exception $e) {
  // handle exception
}


try {
  $dataApi->getLayoutMetadata('layout name', $recordId);
} catch(\Exception $e) {
  // handle exception
}
bash
composer