dongasai/apitable_phpsdk

dev-master 2023-11-30 05:51 UTC

This package is auto-updated.

Last update: 2024-10-30 02:26:54 UTC


README

apitable(apitable.com) The PHP SDK, giving you the ability to extend your datasheet with ease.

Mit License

Environment

php 8.0+

Installation

composer require dongasai/apitable_phpsdk

Get api_token

Visit the workbench of ApiTable, click on the personal avatar in the lower left corner, and enter [My Setting > Developer]. click generate token (binding email required for first use).

Use

<?php
require_once './vendor/autoload.php';
use ApiTable\ApiTable;

echo '<pre>';

ApiTable::auth('your api token');

$all = ApiTable::datasheet('your dstId')->record()->all([
    "fieldKey" => 'id'
]);
var_dump(json_encode($all->getData()->getRecords()));

$page = ApiTable::datasheet('your dstId')->get(['pageNum' => 2, 'pageSize' => 2]);
var_dump(json_encode($page->getData()->getRecords()));

$attach = ApiTable::datasheet('your dstId')->upload(__DIR__.'/image.png');
var_dump($attach);

$insertArr = [
    [
        'fields' => ['ID' => 88],
    ],
    [
        'fields' => ['ID' => 99],
    ]
];
$insert = ApiTable::datasheet('your dstId')->record()->add($insertArr, 'name');
var_dump('insert message ' . $insert->getMessage());

$insertRecords = $insert->getData()->getRecords();
$updateArr = [
    [
        'recordId' => $insertRecords[0]['recordId'],
        'fields' => ['ID' => 100],
    ],
    [
        'recordId' => $insertRecords[1]['recordId'],
        'fields' => ['ID' => 101],
    ]
];
$update = ApiTable::datasheet('your dstId')->record()->update($updateArr, 'name');
var_dump('update message ' . $update->getMessage());

$delete = ApiTable::datasheet('your dstId')->record()->del([$insertRecords[0]['recordId'], $insertRecords[1]['recordId'],]);
var_dump('delete message ' . $delete->getMessage());
echo '</pre>';