Howard
Howard

Reputation: 31

Dialogflow v2 REST call returns 400 Bad Request

I get a 400 Bad Request when issuing this entityTypes.create call:

wget --header="Authorization: Bearer ${TOKEN}" \
 --post-data=' { "displayName": "writer1", "kind": "KIND_MAP", "autoExpansionMode": "AUTO_EXPANSION_MODE_DEFAULT", "entities": [ { "value": "Virginia Woolf", "synonyms": [ "Virginia Woolf" ] } }' \
 https://dialogflow.googleapis.com/v2/projects/MyProject/agent/entityTypes

but this -- entityTypes.list -- works OK:

wget --header="Authorization: Bearer ${TOKEN}" \
https://dialogflow.googleapis.com/v2/projects/MyProject/agent/entityTypes

Any ideas? Thanks.

Upvotes: 1

Views: 810

Answers (1)

Prisoner
Prisoner

Reputation: 50701

By default, --post-data uses a content-type of application/x-www-form-urlencoded. The API requires the content-type of application/json.

I tend to use something more like

wget \
 --header="Authorization: Bearer ${TOKEN}" \
 --header="Content-type: application/json" \
 --post-data='{ ... }' \
 https://dialogflow.googleapis.com/v2/projects/MyProject/agent/entityTypes

Upvotes: 2

Related Questions