rolfo85
rolfo85

Reputation: 767

Getting Code 400 using Dialogflow on API request

this is my very first time using Dialogflow, so probably my mistake is very stupid.

here is my problem:

1) I created a sample agent "small-talk'.

2) I enabled the Webhook in the fulfilment section. I setup the URL of the web server making the request and the auth (username, password) of the that web server.

3) I uploaded a simple webpage on that web server with an API request that looks like this one below (this is the sample json referenced in their guide):

axios({
    method: 'POST',
    url: 'https://api.dialogflow.com/v1/query?v=20150910',
    headers: {
        'Authorization': 'Bearer ad7829588896432caa8940a291b66f84',
        'Content-Type': 'application/json',
    },
    body: {
        "contexts": [
        "shop"
        ],
        "lang": "en",
        "query": "I need apples",
        "sessionId": "12345",
        "timezone": "America/New_York"
    }
})  
.then((response) => {
    console.log(response);
})
.catch((error) => {
    console.log(error);                
})

I keep getting this error:

Cannot parse json. Please validate your json. Code: 400"

The only thing I can thing of, is that I noticed that Dialogflow is now working with the API V2 enabled by default in the agent settings and it seems there is no selection to V1 available anymore. But maybe this has nothing to do with my problem.

Thanks in advance!

Upvotes: 0

Views: 1088

Answers (2)

Punit Pandey
Punit Pandey

Reputation: 405

By the way, Google has shutdown Dialogflow V1 starting from 12th July 2021 as per this URL - https://cloud.google.com/dialogflow/docs/release-notes#June_15_2021

In case you are getting http response code 400 (bad request), it means that it is time to migrate :-)

Upvotes: 0

rolfo85
rolfo85

Reputation: 767

Solved it!

In the json request, instead of

body: {...}

I replaced it with

data: {...}

Probably it was obvious, but I am an absolute newbie on these things!

Upvotes: 1

Related Questions