Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

798
Views
In Laravel, send a post request with json object data

I want to send request with Http facade in Laravel but i can't pass json object data it must be just array.

Http::withHeaders(['Content-Type' => 'application/json'])->withOptions(['headers' => $coockie])->post($this->policy_url . $address, json_encode($data));

My data variable value:

$data = [
    "document" => [
        "customerId" => 1,
        "currencyId" => 1,
        "settlementPolicyId" => 8,
        "storeId" => 16,
        "documentPatternId" => 2,
        "items" => [
            [
              "productId" => 193,
              "unitId" => 2,
              "quantity" => 1,
              "storeId" => 16,
              "TrackingFactor1" => "1214",
              "PartTrackingFactorRef1" => 1053,
              "TrackingFactorHasQuantity1" => true,
              "TrackingFactorValue" => "‏test",
              "fee" => 0
            ]
          ]
        ],
        "payments" => [
            [
                "key" => "Cash",
                "amount" => 445810,
                "attr" => []
            ]
        ]
    ];

The error:

TypeError Argument 2 passed to Illuminate\Http\Client\PendingRequest::post() must be of the type array, string given
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You may try using withBody method

Http::withBody(json_encode($data), 'application/json')
    ->withOptions([
       'headers' => $coockie
    ])
    ->post($this->policy_url . $address);
over 4 years ago · Santiago Trujillo Report

0

Make json_encode($data) before sending it to the request.

$myArray = json_encode($data);
 $finalData = explode(' ',$myArray);
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!