Error while inserting new row [Jun 10]

:raising_hand_man: vibrantium asked

Hello! I’m teaching myself how to insert a new row in the API through Axios. I’m suspecting that I’m formatting the request wrong since it queries for a row instead of inserts. Also all variables are working as I tested these before hands, so that’s why I suspected it’s the way I formatted the request that is wrong. Here’s how it looks so far:

```js

//NocoDB inputting

var create = {

method: ‘POST’,

url: ${sheet_Users},

headers: {

‘xc-auth’: process.env.nocodb_token,

},

fields: {

my_reversals: ${inputtingRev},

my_faves: ${inputtingFave},

random_or_faves: ${inputtingRoF},

created_on: new Date().toISOString(),

},

}; // End of create

var inputting

var inputtingrequest = await axios

.request(create)

.then(function (response) {

console.log(This is the response data for inputting new user:);

console.log(response.data);

inputting = response.data;

UserRow = response.data.ID;

})

.catch(function (error) {

console.error(error);

});

```

:man_bald: dstala replied

can you help us with the error message?

:raising_hand_man: vibrantium replied

Sure! It’s super long though :frowning: but first of all is the “await axios.request(create)” a correct sentence? I’ve seen people use “await axios.post”

:man_bald: dstala replied

axios.request(create) is fine. you will have to replace fields with data: {}

:man_bald: dstala replied

```const options2 = {

method: ‘POST’,

url: ‘http://localhost:8080/api/v1/db/data/noco/p_wiukyreqe052rf/Producer/’,

data: { Name: “x1”, Notes: “x1” },

headers: {

‘xc-auth’: authToken

}

};

axios.request(options2).then(function (response) {

console.log(response.data);

}).catch(function (error) {

console.error(error);

});```

:man_bald: dstala replied

this worked for me.

:man_bald: dstala replied

you can find ready sample code (mapped for read api) on clicking get api snippet on your right bottom of grid view window

:man_bald: dstala replied

here

:raising_hand_man: vibrantium replied

Okay! I tried replacing “fields” to “data” instead & while the error message looks a lot shorter now, here’s what it says:

TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received an instance of Object

I did use a variable for the url, it works for when I’m querying/getting a row :thinking:

:man_bald: dstala replied

try dumping url content to confirm if all good

:raising_hand_man: vibrantium replied

okay just did! pasted the url instead of using the variable where i stored it. still gave me the same TypeError message

:man_bald: dstala replied

${sheet_Users} : can you dump this? to confirm if its object or a string

:raising_hand_man: vibrantium replied

Wanted to clarify: you “dump” a variable by doing console.log(variable) right?

:man_bald: dstala replied

yes

:raising_hand_man: vibrantium replied

ah okay good let me share what I got

:raising_hand_man: vibrantium replied

So this is the console log line:

```js

console.log(This is the line right before NocoDB inputting, sheet_Users looks like: ${sheet_Users})```

and this is how it looks like in my log:

This is the line right before NocoDB inputting, sheet_Users looks like: http://heyheka.herokuapp.com/api/v1/db/data/noco/p_s828dsukkjkkq4/Heka - User Data/views/Heka - User Data/

:man_bald: dstala replied

there are spaces in name. try url: ${encodeURI(sheet_Users)},

:raising_hand_man: vibrantium replied

still gave me the same eror

:raising_hand_man: vibrantium replied

Also I just noticed that one of my fields is a single select field? Do I have to input my data differently or can I just write down my selection name?

:man_bald: dstala replied

single select, option in quotes. multi select, comma separated string under quotes (example: “option-1, option-2”)