Skip to content
Advertisement

param is missing or the value is empty laravel

I am creating a user with the api provided. I am using Laravel and trying to store data to smartrmail and docs to create new subscriber is here https://docs.smartrmail.com/en/articles/636615-list-subscribers Each time i send request i get following error:

Server error: `POST https://go.smartrmail.com/api/v1/lists/1sptso/list_subscribers` resulted in a `500 Internal Server Error` response: {"error":"param is missing or the value is empty: subscribers"}

{“error”:”param is missing or the value is empty: subscribers”}

I am using Laravel and my code is here

Route::get('smartrmail',function(){

    $headers = [
        'Accept' => 'application/json',
        'Authorization' => 'token f91715d5-3aac-4db3-a133-4b3a9493a9a4',
        'Content-Type' => 'application/json',
    ];
    
    $client = new GuzzleHttpClient([
        'headers' => $headers
    ]);
    $data = [
        "subscribers"=>[
            [
                "email"=> "vanhalen@example.com",
                "first_name"=> "van",
                "last_name"=> "halen",
                "subscribed"=> true,
            ]
        ]
    ];
    $res = $client->request('POST', 'https://go.smartrmail.com/api/v1/lists/1sptso/list_subscribers', [
    
        'form_params' => [
                $data 
                       
            ]

    ]);
    return($res);
    // echo $res->getStatusCode();
});

Anybody help me to figure out what is wrong here. I am following this docs https://docs.smartrmail.com/en/articles/636615-list-subscribers to create a new subscriber

Advertisement

Answer

Instead of

'form_params' => [
    $data
]

use

'json' => $data

Explanation

You want to send json data (I assume that because you set header 'Content-Type' => 'application/json', which means that you are sending json), but form_params is used for application/x-www-form-urlencoded.

json sets header to application/json and sends data as json.

As you set proper header, this should work too:

'body' => $data

Proper name of param you can find in Guzzle docs, I used uploading data part.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement