Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

103
Views
Issue with using the axios post method with a couchdb local database

I am trying to use Axios to perform a post to a local couchdb database.

const options = {
            headers: {
                'Content-type': 'multipart/form-data',
                Referer: "http://localhost:5984",
                Accept: "application/json"
            }
        }
try{
            const response = await axios.get("http://Username:Password@localhost:5984/users/" + user.Name + "/")
            rev = response.data._rev
            console.log("Fresh _rev acquired.\n\n")
        }catch{
            console.log("An error occured")
        }
        try{ 
            var response = await axios.post('http://Username:Password@localhost:5984/users/' + user.Name + '/?_rev="' + rev + '"', user, options)
            console.log("posted\n\n")
        }catch(error){
            console.log("post failed\n", error)
        }

This produces an error message. "Request failed with status code 500" The data line of the error message is: data: { error: 'case_clause', reason: 'undefined', ref: 2200284843 } After researching the problem I believe the error is caused by axios using multipart/form-data rather than application/json, but when I change that I get errors stating that the content type must be multipart/form-data. I have found a work around for using the post method by using a get, then deleting the document in the database and finally using a put to make a new document. It is just really bothering me that after a few days of trying to understand the issues I been having with this post method that I am still empty handed. If you have anything that may help, I would greatly appreciate it.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Solved the error 500 by changing the Content-type back to application/json in the header

headers: {
    'Content-type': 'application/json',
    Referer: "http://localhost:5984",
    Accept: "application/json"
} 

For this change couchdb returned an error 415. After a bit more digging, and some trial and error I removed the {docid} and revision number from the URL and included them in the data portion of the request.

try{ 
    var response = await axios.post('http://Username:Password@localhost:5984/twitchusers/' /*+ user.Name + '/'?_rev="' + rev + '"'*/, {_id: user.Name, _rev: rev, user}, options)
    console.log("posted\n\n")
}catch(error){
    console.log("post failed\n", error)
}

This change resulted in no error.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!