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

dimnks's avatar

How can I use Guzzle to make a post request to Vertifire API using Laravel?

I'm trying to use Guzzle with Laravel to make a post request using Vertifire API. According to Vertifire's documentation, a minimal post request should be:

curl https://api50.vertifire.com/v2/serp/url \
--header "X-Vertifire-Token: MY TOKEN HERE" \
--data terms[0][term]=videos \
--data terms[0][url]=wikipedia.org \
--data terms[0][sep][search_engine]=1

Following Guzzle's documentation, firstly I create a client:

$client = new Client(['base_uri' => 'https://api50.vertifire.com/']);

And I'm stuck in making the actual request:

$request = $client->post('v2/serp/url', [
    'headers'   => config('guzzleapi.vertifire_auth'),
    'data'      => [
        $terms[0]['term'] = 'videos',
        $terms[0]['url'] = 'wikipedia.org',
        $terms[0]['sep']['search_engine'] = 1,
    ]
]);

Which results with the error:

Client error: `POST https://api50.vertifire.com/v2/serp/url` resulted in a `400 Bad Request`
response: {"status":0,"error":{"code":3001,"message":"Missing term"}}

Obviously I'm messing up with the way I pass data to the request... How can I pass specific data or array of data to a post request using Guzzle? Any help will be really appreciated since I'm a rookie in this field.

Thanks!

0 likes
2 replies
martinbean's avatar
Level 80

@dimnks The keys in your data array aren’t write. You need to actually expand the data like this:

$request = $client->post('v2/serp/url', [
    'headers' => config('guzzleapi.vertifire_auth'),
    'data' => [
        'terms' => [
            [
                'term' => 'videos',
                'url' => 'wikipedia.org',
                'sep' => [
                    'search_engine' => 1,
                ],
            ],
        ],
    ]
]);
1 like
dimnks's avatar

Thanks @martinbean

The only modification needed was replacing 'data' with 'form_params'

        $ranks_request = $client->post('v2/serp/url', [
            'headers' => config('guzzleapi.vertifire_auth'),
            'form_params' => [
                'terms' => [
                    [
                        'term'  => 'videos',
                        'url'   => 'wikipedia.org',
                        'sep'   => [
                            'search_engine' => 1,
                        ],
                    ],
                ],
            ],
        ]);

Thanks again!!

Please or to participate in this conversation.