These docs are for v1.0. Click to read the latest docs for v4.1.

Comunidade

Ask a Question
Back to All

Erro HTTP: 200 - Resposta da API: {"error_messages":[{"error":"invalid_request_body","description":"There are some syntax errors in the request payload. Please check the documentation."}]}

Peguei o código direto de https://developer.pagbank.com.br/reference/criar-checkout e coloquei em meu servidor para testar:

$curl = curl_init();
curl_setopt($curl, CURLOPT_VERBOSE, true);

curl_setopt_array($curl, [
CURLOPT_URL => "https://sandbox.api.pagseguro.com/checkouts",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'customer' => [
'phone' => [
'country' => '+55',
'area' => '27',
'number' => '999999999'
],
'name' => 'João teste',
'email' => 'joao@teste.com',
'tax_id' => '12345678909'
],
'shipping' => [
'address' => [
'country' => 'BRA',
'region_code' => 'SP',
'city' => 'São Paulo',
'postal_code' => '01452002',
'street' => 'Faria Lima',
'number' => '1384',
'locality' => 'Pinheiros',
'complement' => '5 andar'
],
'box' => [
'dimensions' => [
'length' => 15,
'width' => 10,
'height' => 14
],
'weight' => 300
],
'type' => 'FREE',
'amount' => 0,
'service_type' => 'PAC',
'address_modifiable' => true
],
'reference_id' => '123',
'expiration_date' => '2024-12-30T19:09:10-03:00',
'customer_modifiable' => true,
'items' => [
[
'reference_id' => 'ITEM01',
'name' => 'Nome do Produto',
'quantity' => 1,
'unit_amount' => 50,
'image_url' => 'https://www.xxx.com.br/imagem/102.jpg'
]
],
'additional_amount' => 0,
'discount_amount' => 0,
'payment_methods' => [
[
'type' => 'credit_card',
'brands' => [
'mastercard'
]
],
[
'type' => 'credit_card',
'brands' => [
'visa'
]
],
[
'type' => 'debit_card',
'brands' => [
'visa'
]
],
[
'type' => 'PIX'
],
[
'type' => 'BOLETO'
]
],
'payment_methods_configs' => [
[
'type' => 'credit_card',
'config_options' => [
[
'option' => 'installments_limit',
'value' => '1'
]
]
]
],
'soft_descriptor' => 'xxxx',
'redirect_url' => 'https://pagseguro.uol.com.br',
'return_url' => 'https://pagseguro.uol.com.br',
'notification_urls' => [
'https://pagseguro.uol.com.br'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer xxx",
"Content-type: application/json",
"accept: /"
],
]);

// Executa a requisição
$response = curl_exec($curl);

// Verifica se houve erro no cURL
$err = curl_error($curl);

// Fecha a conexão
curl_close($curl);

// Diagnóstico detalhado
if ($err) {
echo "Erro no cURL: " . $err;
} else {
// Exibe o código HTTP da resposta
echo "Código HTTP: " . http_response_code() . "
";
// Exibe a resposta da API
echo "Resposta da API: " . $response;
}

Seendo que esta aparecendo o seguinte erro e não sei o que pode estar errado:

C�digo HTTP: 200
Resposta da API: {"error_messages":[{"error":"invalid_request_body","description":"There are some syntax errors in the request payload. Please check the documentation."}]}

Apesar do exemplo ter acentuação, não se pode coloca-los, se tirar ele funciona

Olá Juarez, também peguei o código direto da documentaçao e deu certo por aqui, tenta usar esse payload:

curl --request POST
--url https://sandbox.api.pagseguro.com/checkouts
--header 'Authorization: Bearer '
--header 'Content-type: application/json'
--header 'accept: /'
--data '
{
"customer": {
"phone": {
"country": "+55",
"area": "27",
"number": "999999999"
},
"Name": "Teste 123",
"email": "joao@teste.com",
"tax_id": "12345678909"
},
"shipping": {
"address": {
"street": "Faria Lima",
"number": "1384",
"complement": "5 andar",
"locality": "Pinheiros",
"city": "São Paulo",
"region_code": "SP",
"country": "BRA",
"postal_code": "01452002"
},
"box": {
"dimensions": {
"length": 15,
"width": 10,
"height": 14
},
"weight": 300
},
"type": "FREE",
"service_type": "PAC",
"address_modifiable": true
},
"reference_id": "123",
"customer_modifiable": true,
"items": [
{
"reference_id": "REFERÊNCIA DO PRODUTO",
"name": "Nome do Produto",
"quantity": 1,
"unit_amount": 500,
"image_url": "https://www.petz.com.br/blog//wp-content/upload/2018/09/tamanho-de-cachorro-pet-1.jpg"
}
],
"payment_methods_configs": [
{
"config_options": [
{
"value": "1",
"option": "INSTALLMENTS_LIMIT"
}
],
"type": "CREDIT_CARD"
}
],
"soft_descriptor": "xxxx",
"redirect_url": "https://pagseguro.uol.com.br",
"notification_urls": [
"https://pagseguro.uol.com.br"
],
"payment_notification_urls": [
"https://pagseguro.uol.com.br"
],
"additional_amount": 0,
"discount_amount": 0,
"payment_methods": [
{
"type": "CREDIT_CARD"
},
{
"type": "PIX"
},
{
"type": "BOLETO"
},
{
"type": "DEBIT_CARD"
}
]
}



© 1996- Todos os direitos reservados.

PAGSEGURO INTERNET INSTITUIÇÃO DE PAGAMENTO S/A - CNPJ/MF 08.561.701/0001-01

Av. Brigadeiro Faria Lima, 1.384, São Paulo - SP - CEP 01451-001

English
Powered by Localize
Português (Brasil)