Skip to content

Commit 44c2ccd

Browse files
committed
fix: properly send JSON payload via POST
1 parent 1287cf3 commit 44c2ccd

File tree

1 file changed

+3
-30
lines changed

1 file changed

+3
-30
lines changed

src/API/AbstractAPI.php

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ protected function get(string $path, array $parameters = [])
102102
$path .= '?'.http_build_query($parameters);
103103
}
104104

105-
$response = $this->connection->getHttpClient()->get($this->getUri($path));
105+
$response = $this->connection->getHttpClient()->get($path);
106106

107107
return json_decode($response->getBody()->getContents(), true);
108108
}
@@ -118,37 +118,10 @@ protected function get(string $path, array $parameters = [])
118118
protected function post(string $path, array $parameters = [])
119119
{
120120
$response = $this->connection->getHttpClient()->post(
121-
$this->getUri($path),
122-
[],
123-
$this->createJsonBody($parameters)
121+
$path,
122+
['json' => $parameters]
124123
);
125124

126125
return json_decode($response->getBody()->getContents(), true);
127126
}
128-
129-
/**
130-
* Get the URI used for the request.
131-
*
132-
* @param string $path
133-
*
134-
* @return string
135-
*/
136-
private function getUri(string $path): string
137-
{
138-
return '/' !== $path[0] ? "/{$path}" : $path;
139-
}
140-
141-
/**
142-
* Create a JSON encoded version of an array of parameters.
143-
*
144-
* @param array $parameters Request parameters
145-
*
146-
* @return null|string
147-
*/
148-
protected function createJsonBody(array $parameters): ?string
149-
{
150-
return (count($parameters) === 0)
151-
? null
152-
: json_encode($parameters, empty($parameters) ? JSON_FORCE_OBJECT : 0);
153-
}
154127
}

0 commit comments

Comments
 (0)