diff --git a/src/Airtable.php b/src/Airtable.php index f241e20..fe318c7 100755 --- a/src/Airtable.php +++ b/src/Airtable.php @@ -187,6 +187,11 @@ public function upsert(array $data, array $fieldsToMergeOn) return $this->api->upsert($data, $fieldsToMergeOn); } + public function deleteMultiple(array $recordIds) + { + return $this->api->deleteMultiple($recordIds); + } + private function toCollection($object) { return isset($object['records']) ? collect($object['records']) : $object; diff --git a/src/Api/AirtableApiClient.php b/src/Api/AirtableApiClient.php index 6b7b53e..b786a54 100644 --- a/src/Api/AirtableApiClient.php +++ b/src/Api/AirtableApiClient.php @@ -312,4 +312,39 @@ protected function getQueryParams(): array return $query_params; } + + public function deleteMultiple(array $ids) + { + $records = []; + $chunks = array_chunk($ids, 10); + foreach ($chunks as $chunk) { + $url = $this->getEndpointUrl(); + $first = true; + foreach ($chunk as $id) { + if ($first) { + $url .= '?records=' . $id; + } else { + $url .= '&records=' . $id; + } + + $first = false; + } + + $responseData = $this->decodeResponse( + $this->client->delete($url) + ); + + if ($responseData->has('error')) { + return $responseData; + } + + if ($responseData->has('records')) { + $records += $responseData->get('records'); + } + } + + return collect([ + 'records' => $records, + ]); + } }