Skip to content
This repository has been archived by the owner on Dec 22, 2019. It is now read-only.

The parameters passed to the API were invalid. Check your inputs! #39

Closed
lmquang opened this issue Jan 3, 2015 · 15 comments
Closed

The parameters passed to the API were invalid. Check your inputs! #39

lmquang opened this issue Jan 3, 2015 · 15 comments

Comments

@lmquang
Copy link

lmquang commented Jan 3, 2015

Hello,
This is my code:

$to           = 'abc@yahoo.com';
$subject      = 'offline';
$html_message = 'test offline';

$data = array(
    'customer' => 'John Smith',
    'url' => 'http://laravel.com'
);

Mailgun::send('mail', $data, function($message) use ($to,$subject)
{
    $message->to($to, 'John Smith')->subject($subject);
});

But it show error which is:
The parameters passed to the API were invalid. Check your inputs!
Can you explain ?
Thank you

@Bogardo
Copy link
Owner

Bogardo commented Jan 3, 2015

Hi @ivkean,
Do you have a mail.blade.php template in your views directory?

@lmquang
Copy link
Author

lmquang commented Jan 3, 2015

yes, and it's code:
{{ $customer }}

@Bogardo
Copy link
Owner

Bogardo commented Jan 3, 2015

All required fields in the configuration file are entered?
https://github.com/Bogardo/Mailgun#configuration

@Bogardo
Copy link
Owner

Bogardo commented Jan 6, 2015

@ivkean Have you managed to solve the issue?

@lmquang
Copy link
Author

lmquang commented Jan 6, 2015

@Bogardo
Not yet, i set up mailgun account free. Is that why i can not send mail ?

@CupOfTea696
Copy link

I have the same issue. I checked my config file a million times. I always get those kinds of errors.

I get the error The parameters passed to the API were invalid. Check your inputs! on Mailgun::lists()->create() I'm using the exact code from the documentation.
When I call Mailgun::lists()->all(); everything works perfectly.

@CupOfTea696
Copy link

I found the error. The problem is that the Mailgun-PHP package just throws that exception and disregards the data it gets. I edited the file where the error was and just did a var_dump() of the response it actually gets. Here's what came out:

{
  "message": "The 'address' parameter should be a valid email address"
}

Maybe you could find a way to catch the exception and add the data from the response? Because otherwise with errors like this you just have no clue what went wrong.

@Bogardo
Copy link
Owner

Bogardo commented Jan 13, 2015

@CupOfTea696 I'm glad you found the problem.
What kind of list 'address' did you create in the Mailgun Control Panel?
Never mind, you were creating a new list... :)

And which file did you change to get the error message?

@Bogardo
Copy link
Owner

Bogardo commented Jan 13, 2015

@CupOfTea696 I see you're already creating a PR on the mailgun/mailgun-php repo.
mailgun/mailgun-php#71 (comment)

They should probably do something like this:

public function responseHandler($responseObj){
        $httpResponseCode = $responseObj->getStatusCode();
        if($httpResponseCode === 200){
            $data = (string) $responseObj->getBody();
            $jsonResponseData = json_decode($data, false);
            $result = new \stdClass();
            // return response data as json if possible, raw if not
            $result->http_response_body = $data && $jsonResponseData === null ? $data : $jsonResponseData;
        }
        elseif($httpResponseCode == 400){
            $response = json_decode((string)$responseObj->getBody(), false);
            if (isset($response->message)) {
                throw new MissingRequiredParameters(EXCEPTION_MISSING_REQUIRED_PARAMETERS . " " . $response->message);
            }
            throw new MissingRequiredParameters(EXCEPTION_MISSING_REQUIRED_PARAMETERS);
        }
        elseif($httpResponseCode == 401){
            throw new InvalidCredentials(EXCEPTION_INVALID_CREDENTIALS);
        }
        elseif($httpResponseCode == 404){
            throw new MissingEndpoint(EXCEPTION_MISSING_ENDPOINT);
        }
        else{
            throw new GenericHTTPError(EXCEPTION_GENERIC_HTTP_ERROR, $httpResponseCode, $responseObj->getBody());
        }
        $result->http_response_code = $httpResponseCode;
        return $result;
    }

@CupOfTea696
Copy link

Yeah, that's pretty close to what I have. I'll create a pull request in a sec.

@Bogardo
Copy link
Owner

Bogardo commented Jan 13, 2015

@CupOfTea696 There is no need to add this to the EXCEPTION_INVALID_CREDENTIALS and EXCEPTION_MISSING_ENDPOINT these are fine the way they are. Just the EXCEPTION_MISSING_REQUIRED_PARAMETERS should do.

@CupOfTea696
Copy link

Trust me, I had a 404 error earlier which I wouldn't have figured out if it wasn't for the response data. It just said the url was wrong, while the actual problem was that I was trying to get() a list that didn't exist (because I thought you could check if the list existed that way but instead it throws this error).

@Bogardo
Copy link
Owner

Bogardo commented Jan 13, 2015

The InvalidCredentials exception returns the message "Your credentials are incorrect." which should be sufficient.
The MissingEndpoint exception does return the message Mailing list abc@abc.com not found when trying to get a non-existent resource.

But when you try to access a completely non-existent url/path like /test you get the following response:
error
Which isn't really what you want.

@kldeepak
Copy link

kldeepak commented Jun 16, 2016

Hi @Bogardo ,

I faced same issue ("The parameters passed to the API were invalid. Check your inputs!") when I tried to add a domain that exists already in the same account. I updated responseHandler function to get correct error message. Just want to check whether the code is merged into main repo or not.

@paulmartin84
Copy link

Thanks @CupOfTea696 in the end my message was Please activate your Mailgun account. Check your inbox or log in to your control panel to resend the activation email. How frustrating!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants