Skip to content

Commit cf2fdda

Browse files
authored
fix: properly encode JSON parameters
1 parent 347a8bc commit cf2fdda

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/API/AbstractAPI.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ protected function post(string $path, array $parameters = [])
132132
{
133133
$response = $this->connection->getHttpClient()->post(
134134
$this->getUri($path),
135-
['json' => $parameters]
135+
[],
136+
$this->createJsonBody($parameters)
136137
);
137138

138139
return ResponseMediator::getContent($response);
@@ -149,4 +150,18 @@ private function getUri(string $path): string
149150
{
150151
return '/' !== $path[0] ? "/{$path}" : $path;
151152
}
153+
154+
/**
155+
* Create a JSON encoded version of an array of parameters.
156+
*
157+
* @param array $parameters Request parameters
158+
*
159+
* @return null|string
160+
*/
161+
protected function createJsonBody(array $parameters): ?string
162+
{
163+
return (count($parameters) === 0)
164+
? null
165+
: json_encode($parameters, empty($parameters) ? JSON_FORCE_OBJECT : 0);
166+
}
152167
}

0 commit comments

Comments
 (0)