PHP cURL Working but HTTP request node isn't

I’ve this code, and it is functional

<?php
    
    $nodeurl = 'https://api.dw-api.com/send';
 
    $buttons = [
        ['index' => 1, 'urlButton' => ['displayText' => 'Botao 1 URL', 'url' => 'https://painel.dw-api.com']],
        ['index' => 2, 'callButton' => ['displayText' => 'Botao Ligacao', 'phoneNumber' => '+1 (234) 5678-9012']],
        ['index' => 3, 'quickReplyButton' => ['displayText' => 'Botao Texto', 'id' => 'id-like-buttons-message']],
    ];
 
    $data = [
        'receiver'  => '5584981521797',
        'msgtext'   => 'Essa requisi巽達o funciona',
        'sender'    => '553898318911',
        'token'     => 'HyHBhG3886eA8gFwvdZS',
        'buttons'   => $buttons, // delete this line if no buttons
    ];
 
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
    curl_setopt($ch, CURLOPT_URL, $nodeurl);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    $response = curl_exec($ch);
    curl_close($ch);
 
    echo $response; ?>

And i’ve this flow

, and this do not work.

Hey @antoni0duarte, welcome to the community!

Try this:

By default, n8n would try to send to send a string when using a value like this in a body parameter:

[{"index":"1","urlButton":{"displayText":"Visit my website!","url":"https://painel.dw-api.com"}},{"index":"2","callButton":{"displayText":"Call me!","phoneNumber":"+1 (234) 5678-9012"}},{"index":"3","quickReplyButton":{"displayText":"This is a reply, just like normal buttons!","id":"id-like-buttons-message"}}]

I’ve converted this plain text into an expression now so n8n would send a JSON structure instead which the service seems to accept:

It’s work for me! Thank you.

1 Like