Closed KDederichs closed 6 years ago
Can you post a piece of code to give some more context on what you're using?
Sure, the scenario is simple: I have a doctrine listener that queries the Mollie Api after a new customer is registered to get an ID from you. That is done simply by calling:
/** @var MollieApiClient */
private $mollie;
public function __construct(MollieApiClient $mollie)
{
$this->mollie = $mollie;
}
public function postPersist(LifecycleEventArgs $args)
{
/** @var Customer $customer */
$customer = $args->getEntity();
if (!$customer instanceof Customer) {
return;
}
$em = $args->getEntityManager();
$response = $this->mollie->customers->create();
if ($response) {
$customer->setMollieId($response->id);
$em->persist($customer);
$em->flush();
}
}
The MollieApiClient is registered as a service and is inject by DI into the listener. The MollieApiClient is simply registered by setting:
GuzzleHttp\Client:
alias: eight_points_guzzle.client.defaultClient
Mollie\Api\MollieApiClient:
calls:
- method: setApiKey
arguments:
- '%env(MOLLIE_API_KEY)%'
Hi @KDederichs,
The error is because you are not supplying any parameters to $this->mollie->customers->create()
.
Which tries to json_encode the parameters to send to our endpoint. Which will result into an error. Since we're actually trying to json_encode null.
This error is not really clear though.
It's actually encoding "[]" as httpBody though. The same code did work at one point as well, it just stopped somehow.
Yes sorry, it is actually a message given by the API. But the cause is the same, it needs parameters.
I'll check if we can alter this message in the API.
In that case your documentation is wrong though, cause all parameters in create customer are marked optional. So it would make sense that it works with no parameters: https://docs.mollie.com/reference/v2/customers-api/create-customer
@smitsel This must be altered in the client. It should not send a body if there are no parameters (empty array).
Thanks for reporting this. The body should indeed not be passed when left empty.
I've committed and released the fix under https://github.com/mollie/mollie-api-php/releases/tag/v2.0.10
Specifications
Describe the issue
Hey,
I'm using your API in combination with Symfony 4 and so far it was working fine. Out of the blue I started to get
Error executing API call (400: Bad Request): The JSON request body does not represent an object..
Errors while trying to create new customers.
Any idea what could be causing this?