'Post request with --data-raw in Cypress JS

Good day!

I have a problem with my autotest on JS cypress. I need to send post request in autotest. Here it is as I send it by hands:

curl --location --request POST 'http://test.com/service' \
--header 'Token: n7n7n7n7n7' \
--header 'Content-Type: text/plain' \
--data-raw 'text: v3'

This is how I try to send post in js test:

cy.request({
            method: 'POST',
            url: 'http//:test.com/service',
            headers: {
                'Token': n7n7n7n7n7,
                'Content-Type':'text/plain'
            },
            data: "text: v3"
        }).then((res)=>{
            expect(res.status).to.eq(200)
        })

It doesnt work, instead of 200 I get 400, in cypress log I see:

The request we sent was:

Method: POST URL: http//:test.com/service Headers: { "Connection": "keep-alive", "X-Gitlab-Token": "n7n7n7n7n7", "Content-Type": "text/plain", "user-agent": "Mozilla/5.0", "accept": "/", "accept-encoding": "gzip, deflate", "content-length": 0 }

And no data.

How can I send data-raw in cypress request? Thanks in advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source