Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

400 Bad request #2

Closed
christophrumpel opened this issue Aug 11, 2016 · 13 comments
Closed

400 Bad request #2

christophrumpel opened this issue Aug 11, 2016 · 13 comments

Comments

@christophrumpel
Copy link

Hey @iboldurev ,

today it started given me this error:

GuzzleHttp\\Exception\\ClientException: Client error: `GET https://api.api.ai/v1/query?v=20150910&query=fsdfds` resulted in a `400 Bad Request

When I try to query a simple message like:

 $query = $this->apiClient->get('query', [
      'query' => $message,
]);

I checked the apiai token and my code and I'm not sure why I get this error. Can you help me?

Thx Christoph

@iboldurev
Copy link
Owner

iboldurev commented Aug 11, 2016

What version the library you are using?
Today I updated to the new version of the library, is now sending queries occur through a post request

@iboldurev
Copy link
Owner

@christophrumpel I checked your code, it works.
Maybe you need to update your version of the library (composer update) to 0.2.3

@christophrumpel
Copy link
Author

0.2.2, ah ok then I will try 0.2.3 👍 thx

@iboldurev
Copy link
Owner

@christophrumpel I am glad to help you, thank you for the use of the library.

@christophrumpel
Copy link
Author

Thx, I am really glad you created it!

@christophrumpel
Copy link
Author

christophrumpel commented Nov 29, 2016

Interesting, I got the same problem with another project where I use your package version 0.2.5.
I figured out, that I needed to add a session ID in order to make it work. Is this a bug? (I used the time() method for testing purpose)

try {
    $client = new Client($this->accessToken);

    $query = $client->get('query', [
        'query'     => $message,
        'sessionId' => time()
    ]);

    $response = json_decode((string)$query->getBody(), true);
    dd($response);
} catch (\Exception $error) {
    dd($error);
}

@bottomoftheheap9000
Copy link

bottomoftheheap9000 commented Jan 3, 2017

Christoph, how am I to resolve this issue? Im getting 400 error. What is the $this variable? My composer shows iboldurev/api-ai-php 0.2.5 API.ai php sdk

@bottomoftheheap9000
Copy link

How should my code look?

@bottomoftheheap9000
Copy link

bottomoftheheap9000 commented Jan 3, 2017

@christophrumpel
Copy link
Author

Hey @bottomoftheheap9000 , in my example $this->accessToken refers to my variable. You can just put your access token in like ... new Client('your-access-token');.

Have your tried to add a sessionId to the query params like in my example above? Because it is missing in your gist example.

@bottomoftheheap9000
Copy link

Hi! Thanks for responding! I've altered my code as advised, the page now loads (so it must be connecting to the api!), however Im not able to display the json response. Im not sure if Im receiving anything from api.ai, I have tried

echo $response;
echo (string)$response['result']['fulfillment']['speech'];

But it just comes up blank.. How am I supposed to know if api.ai is responding and how would I display the response, thanks again @christophrumpel !!

@christophrumpel
Copy link
Author

Try var_dump($query->getBody()); to see what you get back from API.ai. There must be a response, even if it is an error.

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

No branches or pull requests

3 participants