Creating new document with REST PUT isn't working for me


#1

[In what category would posts about REST go?]

I can create new documents using REST POST. However, when I try creating a document with REST PUT I get the error “database already exists”. Here are the details of my request:

URL:


Request Headers

* `If-Match` not supplied in request headers
* `Content-Type` is `application`/json

Query parameters:

* `new_edits` not provided
* `rev` not provided

Message Body example:

```javascript
{ "created_at": 1471015248.411849,
  "id": "A1471015248-411875",
  "tags": ["tag1", "tag2"],
  "category": "test"',
}

An equivalent POST works (same URL, none of the query parameters or request headers. etc. – just the same URL and body).

(By the way, there is documentation ambiguity here: it says that If-Match is “required for document updates if the rev query parameter or _rev body property are not supplied.” However, neither would be supplied when creating a new document.)

[I am mystified by the appearance of the code block above. It formats correctly as javascript, but its first line shows when it shouldn’t (three backpacks and “javascript”. It also prints the opening brace in black but the closing brace in red. Furthermore, “javascript” isn’t really doing anything – I can put anything after the backpacks and get the same formatting with the first line showing inappropriately. Any ideas?]


#2

Hmm, sounds startlingly similar to Sync Gateway 1.3 API docs problem

For your meta points:

  • Sync Gateway seems the best category, or perhaps just Mobile
  • For the formatting, at a guess it’s because some code block got merged together, but difficult to say without the raw input.

#3

Thanks for the quick answer.

Raw input was:

‘’‘javascript
{ “created_at”: 1471015248.411849,
“id”: “A1471015248-411875”,
“tags”: [“tag1”, “tag2”],
“category”: “test”’,
}
’’’

with backpacks substituted for the surrounding triple single-quotes.


#4

Thanks for the pointer. Reading that page made it clear that I was handling the id of the data incorrectly — I was putting it in the data rather than the URL. I have notes extracted from the documentation pages and that endpoint got accidentally deleted while I was formatting the text.

With the id in the URL, it actually does create a new document as specified.