Mocha throwing 400 bad request error when making a post request with raw data

var expect=require('chai').expect;
var http=require("http");
var request = require('request');
var env = require('./environment');

describe("Testing Callflow Functionality", function(done) {
  //this.timeout(15000);
  it("Testing the minutes field ",function(done){
    var formData = [{
        "variables":[{"name": "OpMode",
        "value":"3",
        "section": "Treatment",
        "type": "queue"}]
    }]
    var data=(JSON.stringify(formData));
    console.log(data);

    console.log(JSON.stringify(formData));
    var options={
      url:env.hostname+'variables/menus/Call%20Flow?siteName=VHT%20TITAN&queueId=VHT_Test&segmentId=6&segmentName=58897&allQueues=false&allSegments=false',
      **raw:data**,
      headers:{
        //'lastAccess':1516781803697,
        'Token':'14275bb3c2fbc60d0dac05113dac1d6bcf3ccde00cf2699c43efedd820c2660a',
        //'ttl':2592000000,
        'Content-Type': 'application/json'
      }
    }
    request.post(options,function(err,res,body) {
      //console.log(JSON.stringify(options.raw));
      console.log(options);
      //body=JSON.parse(body);
      expect(res.statusCode).to.equal(204);
      done();
   });
  });
});

Note: When using 'form' instead of 'raw', a 500 internal server error is thrown. The same object works fine on Postman, returning status code 204 when testing this case there.

Answer №1

Give it a shot

const settings = {
    ...
    data: formData,
    ...
}

Refer to the documentation for more information.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

JavaScript struggles when dealing with dynamically loaded tables

I am currently working on integrating the javascript widget from addtocalendar.com into my website. The code example provided by them is displayed below. Everything functions as expected when I place it on a regular page. However, I am facing an issue wher ...

Transforming a simple MySQL query into a structured nested JSON format

Is there a way to easily reorganize data without using complex for loops (perhaps with Underscore.js or refining the MySQL query)? I have data formatted like this: [ { "J_NUM": "BOAK-1212", "X_DUE_DATE": "2012-06-20T00:00:00.000Z", "X_LEAD_T ...

Decoding a JSON response requires understanding the structure and content of

[ { "property1": "prop-00000001", "property2": "property2value1", "property3": {}, "property4": [ "Prop4-00000001", "Prop4-00000002" ] }, { "property1": "prop-00000002", ...

What is the best way to transform a JsonWriter into a JsonObject using GSON?

Looking for assistance on converting JsonWriter to JsonObject in GSON without using any predefined object. JsonWriter writer = new JsonWriter(new FileWriter("C:\\Users\\ravr\\Desktop\\outputJSONSChema.json")); ...

Adding an exception for ClickAwayListener in React-MUI

Hey there! I'm currently exploring MUI and trying to incorporate the ClickAwayListener API into my project, but I'm facing some difficulties. You can take a look at my project on codesandbox here: https://codesandbox.io/s/react-leaflet-icon-ma ...

Utilizing JQuery for parsing information

I am working on a project that involves displaying Google Maps API on one tab and images on another within a container. The goal is to have the image in the second tab change when a location is selected from the list. To achieve this, I have set up a hidd ...

How can I make a checkbox checked in AngularJS?

Hello, I am currently working on a web application using AngularJS. Within this application, I have a form where I am populating values into a multi-select dropdown. <li ng-repeat="p in locations"> <input type="checkbox" ng-checked="master" n ...

Extract all objects from an array where a specific field contains an array

data:[ { id:1, tags:['TagA','TagB','TagC'] }, { id:2, tags:['TagB','TagD'] }, { id:3, tags:[&a ...

Is there a problem with the alignment of

<s:form id="inputThresholdForm" name="inputThresholdForm" theme="simple"> <table border="0" class="display-table" cellspacing="2" cellpadding="2" height="100%" width="100%"> <tr> <td colspan= ...

Encountered an issue with resolving the module specifier while attempting to import a module

Whenever I attempt to import a module, I consistently encounter this error message Failed to resolve module specifier "mongodb". Relative references must start with either "/", "./", or "../". and I have searched ext ...

I need to position a Vue component at the top of the page for a specific view only

How can I ensure that the component SiteHead only appears at the very top of the HomeView page, above the SiteNavigation component? If I place the SiteHead component within the HomeView.vue code, it ends up below SiteNavigation. Here is my App.vue code: & ...

Implement a jQuery slider that pauses on hovering

Currently, I am grappling with the clearInterval function in a small jQuery project. To better illustrate the issue, I have created a jsFiddle example: http://jsfiddle.net/eWTSu/ While the rotation works smoothly, I encountered an obstacle when hovering ...

Having trouble uploading a file with Parse.File in an express web application

Currently, I am developing an express web application with a Parse backend. To render webpages, I am utilizing .ejs files. Upon clicking the submit button on the file upload form, Express routes me to testfile.js where I am using the Parse.File method to u ...

Unveiling Insights from a JSON File: Data Extraction

I have a JSON file named pio2.json that contains the following data: { "controles":[{ "chart":[{ "type":"columns", "title":"Pollitos" }], "datos":[{"key":"Math","value":98}, {"key":"Physics" ...

Sorting technique failing to reorganize list

I'm currently troubleshooting why my sorting function is not functioning as expected. My goal is for it to operate similarly to this example: https://codepen.io/levit/pen/abmXgBR The data I am working with is retrieved from an API: <BookCard v-fo ...

Issue with checkboxes preventing submission of form

Currently working on a website project for a company that requires certain steps to be completed for deliveries. Unfortunately, I am facing issues with the submit button, and I apologize as I am still new to this. The code I have pasted is divided into tw ...

Troubleshooting: Issues with the functionality of ng-include in AngularJS

Hi there, I am new to angular js and I'm attempting to integrate a simple html file into my page. Below is the code I am using: <!DOCTYPE html> <html ng-app=""> <head> </head> <body ng-controller="userController"> < ...

How to target and set focus on dynamically generated input field when the ID is unknown

I am facing an issue with a jQuery/AJAX function that loads HTML form elements from the server. The form fields vary, and I want to set focus on the first available input field after the load is complete. I have tried: $(':input:enabled:visible:firs ...

Send a request to the uClassify API using the Node request module

I'm currently working on integrating the uClassify API into my Node project, but I'm encountering some issues with my code. Here's what I have so far: const req = JSON.stringify('Hello, my love!'); const options = { body: ...

What is the correct way to set up a click event listener for a radio button?

Currently, I am in the process of dynamically generating HTML radio buttons. Each button is assigned an Id stored in a variable. My goal is to add a click event handler to these radio buttons using the assigned Id. However, I am encountering an issue where ...