0

I haven't tried using cUrl Request with API and converting it to Guzzle HTTP.

I need to convert this cUrl to a working guzzle http post request to try the API

curl -X POST
"https://urltosendblahblah" -H "Content-Type: application/json" -d
{
    "outboundRewardRequest" : {
        "app_id" : "B54z9Ug55zLh5rTGRT5g6hq64pGUq6ap",
        "app_secret" : "f6554137d08f5607a696cd40741993758c411af3bb5f6c230270ec26e8d54126",
        "rewards_token" : "I7SkxKYid_F_p-JSgTejow",
        "address" : "9271051129",
        "promo" : "LOAD 50"
    }
}

Currently I had done this with my Guzzle Http but receiving 500 response

public function loadSample(){
    $url = "";

    $request = $this->client->post($url, [
        'verify'=>false,
        'outboundRewardRequest' => [
            'app_id'=>'',
            'app_secret'=> '',
            'rewards_token'=>'==',
            'address'=>'',
            'promo'=>''
        ]
    ]);
    $response = $request->getBody();
    dd($response);

}

thank you!

0

3 Answers 3

1
$request = $this->client->post($url, [
    'headers' => [
        'verify' => false
    ],
    'form_params' => ['outboundRewardRequest' => [
        'app_id'=>'',
        'app_secret'=> '',
        'rewards_token'=>'==',
        'address'=>'',
        'promo'=>''
    ]],
      'debug' => false,
]);

Try this approach when using guzzle. Your body parameters must be a part of the form_params array.

Also you can set your guzzle debugging to false so you don't have any issues there.

Sign up to request clarification or add additional context in comments.

Comments

1

The expected key for the request body is body source. So try changing outboundRewardRequest to body.

Comments

1

Put your data in the json attribute or form_params depending on how it is received.

public function loadSample(){
    $url = "";

    $request = $this->client->post($url, [
        'verify'=>false,
        'json' => [
            'outboundRewardRequest' => [
                'app_id'=>'',
                'app_secret'=> '',
                'rewards_token'=>'==',
                'address'=>'',
                'promo'=>''
            ]
        ]
    ]);
    $response = $request->getBody();
    dd($response);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.