-2
I am doing integration of an api in Laravel, I have to submit a POST according to the documentation of the api with the following body
{
"token": "TOKEN DA APLICACAO",
"email": "[email protected]",
"frete": "0",
"carrinho": '[{
"produto":"Produto 1",
"quantidade":"1",
"preco":"10.92",
"imagem":"http://site.com.br/foto.jpg",
"url":"http://site.com.br/produto"
}]'
}
however, the body I’m sending is like this
{"token":"xxxxxxx","email":"[email protected]","frete":"0","carrinho":[{"produto":"computador","quantidade":"1","preco":"3000.00","imagem":"http:site.com.br/foto.jpg","url":"http//loja.dooca.local/computador"}]}
i am populating that array as follows:
$checkouts = [
'token' => 'xxxxxx'),
'email' => $checkout->getCustomer()->getEmail(),
'frete' => '0',
'carrinho' => [],
];
foreach ($checkout->getItems() as $item) {
$checkouts['carrinho'][] = [
'produto' => $item->getName(),
'quantidade' => strval($item->getQuantity()),
'preco' => $item->getPrice(),
'imagem' => 'http://site.com.br/foto.jpg',
'url' => $item->getUrl(),
];
The problem is that this api only accepts if in the cart part there are simple quotes before the brackets and I can’t put it at all... as for example "cart": '[{
It makes no sense, as they already said "", something wrong is not right, if
carrinho:
need to receive a "STRING" with a JSON format or it is because the author of the API did something very serious. Since you didn’t present the sending part or how you used json_encode then there is no way anyone can answer you reasonably, and I can’t guess a response, after all the site is not for this. Give more details.– Guilherme Nascimento
Exactly, in the documentation it is only accepted to send the body in this mold: { "token": "APPLICATION TOKEN", "email": "[email protected]", "freight": "0", "cart": '[{ "product":"Product 1", "quantity":"1", "price":"10.92", "image":"http://site.com.br/foto.jpg", "url":"http://site.com.br/product" }]' } Sending this: Api::sent()->checkout()->post($checkouts); I’m sending that array above.. that would be right..
– Eduardo
I don’t have access to such documentation to know if this is it or if you got something wrong, and don’t add code in the "comments" field, look at the question, have a link called "edit", correct the question with the minimum details that are missing so we can understand the problem, It won’t do any good if I’m kicking answers like the ones I’ve already answered, in order to get an answer you have to "help us" to help you, it shows what you’ve done understandably, loose pieces of code that don’t do anything won’t help.
– Guilherme Nascimento