Search code examples
watson-discovery

Receiving a 415 error when ingesting a document into Watson Discovery service


I am trying to POST documents to Watson's Discovery service via Postman. It gives me the following not-so-helpful error message no matter what kind document I try:

{
"code": 415,
"error": "The request failed. Please try again."}

The request looks like:

https://gateway.watsonplatform.net/discovery/api/v1/environments/7c83f310-0f3a-4ad0-bb71-5f260672cbca/collections/c0080236-aac1-405c-8111-322caa6b0b65/documents?version=2016-12-01

with the body containing the file in binary and the credentials in the header.

I can upload these documents fine via the collection dashboard, so I must be doing something wrong. Can anyone tell me what it is?


Solution

  • HTTP status code 415 is titled Unsupported Media Type.

    There are two levels which can trigger a 415 from Discovery.

    1. Discovery demands that the overall HTTP POST request be a multipart form, when adding (or updating) a document (to be precise: Content-Type: multipart/form-data; boundary=…) The file needs to be sent within that multipart form request as a part named file.

    2. When sending the multipart form, the file you are sending, or possibly just the Content-Type header that you are sending for the file part, can be rejected. Watson Discovery supports HTML, JSON, PDF and Microsoft Word documents. Anything else will get the 415 response, including if Discovery does not correctly guess the content type. Discovery uses the filename as an aid to guessing what the content type is.

    Relevant questions:

    • Are you bundling your request up in multipart/form-data?
    • What kind of file are you sending?
    • What is the name of the file that you are sending?