Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

LaCoder's avatar

Laravel sending raw request body

I am trying to send an API request to the endpoint, which is successful via Postman raw JSON, Now I am implementing the same in Laravel with HTTP facade.

The endpoint must see the data below in request body,

jData={"apkversion": "1.0.0",
            "uid": "dsfee3",
            "pwd": "deeddee",
            "factor2": "680208",
            "vc":"eefsdf",
            "appkey":"wefdsesdfd334",
            "imei": "abc1234",
            "source": "API"
            }

Now in Laravel, I am struggling to send a request, I tried the below code, but yes, it shows error syntax error, unexpected token "=", expecting ")"

 $response = Http::withBody(jData={"apkversion": "1.0.0",
            "uid": "dsfee3",
            "pwd": "deeddee",
            "factor2": "680208",
            "vc":"eefsdf",
            "appkey":"wefdsesdfd334",
            "imei": "abc1234",
            "source": "API"
            })->post('https://api.shoonya.com/NorenWClientTP/QuickAuth');

How can I send a request with given parameters as raw JSON?

0 likes
5 replies
tykus's avatar

You're working with PHP, so your code should look like this instead... i.e. the POST body is a PHP array:

$response = Http::post('https://api.shoonya.com/NorenWClientTP/QuickAuth', [
    "jData" => [
        "apkversion" => "1.0.0",
        "uid" => "dsfee3",
        "pwd" => "deeddee",
        "factor2" => "680208",
        "vc" => "eefsdf",
        "appkey" => "wefdsesdfd334",
        "imei" => "abc1234",
        "source" =>  "API"
    ]
]);

It is send as application/json by default

https://laravel.com/docs/10.x/http-client#request-data

LaCoder's avatar

@tykus Yes, but endpoint is throwing a bad request, If I send a request via Postman with my given syntax, it gives the correct response. So the question is to the conversion of that syntax to PHP Laravel syntax.

Illuminate\Http\Client\Response {#1661 ▼ // app\Livewire\Broker\AuthFinvasia.php:58
  #response: 
GuzzleHttp\Psr7
\
Response {#1658 ▼
    -reasonPhrase: "Bad Request"
    -statusCode: 400
    -headers: array:6 [▼
      "Date" => array:1 [▶]
      "Server" => array:1 [▶]
      "Content-Type" => array:1 [▶]
      "Access-Control-Allow-Origin" => array:1 [▶]
      "Content-Length" => array:1 [▶]
      "Connection" => array:1 [▶]

Below is what CURL generated by POSTMAN which gives success response.

curl --location 'https://api.shoonya.com/NorenWClientTP/QuickAuth' \
--header 'Content-Type: application/json' \
--header 'Cookie: NWC_ID=8b7dab8568fd3b6d9d471b29834b5062128814686dc34fcbd18f67828bdd3f56' \
--data 'jData={"apkversion": "1.0.0",
"uid": "sdfs",
"pwd": "324324",
"factor2": "680208",
"vc":"werwer",
"appkey":"dfsderw",
"imei": "abc1234",
"source": "API"
}'

Here is POSTMAN BODY

https://imgur.com/a/KfOpQ6l

postman

krisi_gjika's avatar
Level 14

@LaCoder try like this:

 $response = Http::withBody("jData=".json_encode([
        "apkversion" => "1.0.0",
        "uid" => "dsfee3",
        "pwd" => "deeddee",
        "factor2" => "680208",
        "vc" => "eefsdf",
        "appkey" => "wefdsesdfd334",
        "imei" => "abc1234",
        "source" =>  "API"
    ])->post('https://api.shoonya.com/NorenWClientTP/QuickAuth');
1 like
tykus's avatar

@LaCoder are you required to set certain headers/tokens/cookies because the HTTP Client snippet I shared does not?

Please or to participate in this conversation.