From 807cb87d643a4ea1035bea7eb7a0e1441b1b8815 Mon Sep 17 00:00:00 2001 From: Justijn Depover Date: Tue, 22 Jun 2021 11:18:22 +0200 Subject: [PATCH] post method --- src/Teamleader.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Teamleader.php b/src/Teamleader.php index 62d64f3..01bc9f2 100644 --- a/src/Teamleader.php +++ b/src/Teamleader.php @@ -202,6 +202,22 @@ public function get(string $endpoint, array $parameters = []) } } + public function post(string $endpoint, array $body, array $parameters = []) + { + $body = json_encode($body); + + try { + $request = $this->createRequest('POST', $endpoint, $body, $parameters); + $response = $this->client->send($request); + + return $this->parseResponse($response); + } catch (ClientException $e) { + $this->parseExceptionForErrorMessages($e); + } catch (Exception $e) { + throw ApiException::make($e->getCode(), $e->getMessage()); + } + } + private function createRequest($method, $endpoint, $body = null, array $parameters = [], array $headers = []) { $endpoint = $this->buildUrl($endpoint);