mailjet / mailjet-apiv3-php-no-composer

[API v3] Mailjet PHP Wrapper bundled with composer dependencies
MIT License
9 stars 5 forks source link

Response int(401) #1

Open gesquivelob opened 7 years ago

gesquivelob commented 7 years ago

Hi!

Please apologize my English.

Im integrating Mailjet into my website, and following the "Getting Started !" Github guide of Mailjet, exactly on "Make your first call" I got this message from server: int(401)

And looking into "Getting Started" guide, I found the meaning of that message:

Unauthorized You have specified an incorrect Api Key / API Secret Key. You may be unauthorized to access the API or your API key may be expired. Visit API keys Management section to check your keys.

But the problem is that my Public and Private keys are correct.

Could be another reason for that message?

Thanks in advance.

TomTheRock commented 6 years ago

Same happens on my try...do you solve it?

TomTheRock commented 6 years ago

be sure that you do not missmatch the parameters(which was my fault): new \Mailjet\Client($apikey, $apisecret,true,['version' => 'v3.1']); FIRST: APIKEY SECOND: SECRET

frtlkmn commented 6 years ago

Same here, with mailjet github c# library, getting 401 error

baptiste-fi commented 5 years ago

Same here, with mailjet github c# library, getting 401 error. I tried my keys with php and it works

baptiste-fi commented 5 years ago

I found the solution, the example is wrong. Juste replace the following line in the example :

MailjetClient client = new MailjetClient(Environment.GetEnvironmentVariable("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"), Environment.GetEnvironmentVariable("yyyyyyyyyyyyyyyyyyyyyyyyyyyyy")) {
    Version = ApiVersion.V3_1,
   };

by

MailjetClient client = new MailjetClient("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "yyyyyyyyyyyyyyyyyyyyyyyyyyyyy")
            {
                Version = ApiVersion.V3_1,
            };
adamyanliev commented 5 years ago

hey @baptiste-fi ,

All code samples in the readmes - including the ones in the C# wrapper - are written with the assumption that the user has set up their API and Secret keys as environment variables. This makes it easier for users who copy-paste the examples, as they don't need to enter the values in the code sample - instead they will be pulled automatically. See here for information on how to set up environment variables in Windows.

Of course, you can authenticate by directly entering your API and Secret keys, like the example you gave above.

I hope this explanation helps.

Regards, Atanas

Stratix-pixel commented 4 years ago

Hello,

I tried making the request with the code provided and entered the API keys directly but i get a status code 400 Bad Request

Does someone knows why?

this is my output of the verbose debug of mailjet client :

=== HTTP Request === POST https://api.mailjet.com/v3.1/send Accept-Charset:UTF-8 Accept:application/json user-agent:mailjet-apiv3-java/v4.5.0 Content-Type:application/json === HTTP Response === Receive url: https://api.mailjet.com/v3.1/send Status: 400 date:Thu, 18 Jun 2020 13:24:20 GMT null:HTTP/1.1 400 Bad Request content-length:177 x-mj-request-guid:ad521902-195f-4550-8ce3-e1b1145b6f62 content-type:application/json; charset=UTF-8 Content: null Exception in thread "main" com.mailjet.client.errors.MailjetServerException at com.mailjet.client.MailjetResponseUtil.validateMailjetResponse(MailjetResponseUtil.java:40) at com.mailjet.client.MailjetClient.post(MailjetClient.java:283) at MyClass.main(MyClass.java:34)

Process finished with exit code 1

usama-ahmad-coeus commented 4 years ago

Brother kindly verify that your environment variables api key and secret are actually coming in your required send mail function or not. May be they are correct but in the function you cant access them correctly You can see official doc for status codes: https://dev.mailjet.com/sms/reference/overview/errors/

MaheraNadaf commented 1 year ago

Hello usebouncer api Does someone knows why? API request failed with status code: 401 {"status":401,"error":"Unauthorized","message":"api key is required"}