Home > Back-end >  unable to get response form an API in Laravel
unable to get response form an API in Laravel

Time:10-25

I am getting null response in laravel after dd(); ,however in Postman i am getting a response, maybe I am passing the wrong body to the API, kindly guide me on how to pass the following body to this API.

Thanks for your help.

This is my controller

public function callpdf(Request $req)
  {
    // code...
    $host = new HostClass();
    $obj = new SessionClass();
    $response8 = Http::POST($host->getserverIp() . '/PDFReport',[
      // "patientId"=> $obj->getpatientId(),
      "patientId"=>"001000010818",
      "reportId"=> "618",
      "con"=>"003001200326197",
      "departmentId"=> "128",
      "orderStatusId" => "12",
      "organizationId"=>"332",
      "sessionId"=> "3",
      
    ]);
  
    dd($response8);
    return $response8;
  }

This is Postman request and response

{
       "patientId": "001000010818",
        "departmentId": "128",
        "con": "003001200326197",
        "odi": "2",
        "orderStatusId" : "12",
        "reportId": "618",
        "organizationId":"332",
        "sessionId": "3"
}

CodePudding user response:

I am getting null response in laravel after dd();, however in Postman i am getting a response

Based on your response to my question:

Is your callPdf method a web or api route? When using Postman, are you calling the API directly?

@Peppermintology it's a web route, API is "PDFReport"

I would expect this behaviour. You're using dd(); which is Laravels dump and die method. What this does is dump the data you provide it and then die which halts execution meaning nothing after the dd() is ever executed.

So your return statement is never executed, hence no response.

CodePudding user response:

I see your code. The code looks fine but in my thinking problem could be at multiple parts of the HTTP request.

  • First Look at the URL this may be difference between URL or postman and your request. First, verify that
  • The second problem may be due to some headers like (Accept, Content-Type) to be application/json.
  • Related