Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X
Hey All,
I am trying to create a user and organization via TW API calls, (not through the Composer).
and everytime I do it, I get "An Entity Name Must Be Provided" response.
Interesting thing is, call works on POSTman but it doesnt work on my node script. I made sure I put headers and everything same with the postman, but still I get "An Entity Name Must Be Provided"
Here is my post call on Node script
app.get('/hey/:name', function (req, res) {
var payload = {
method:'POST',
url: 'https://XXXX.net/Thingworx/Resources/EntityServices/Services/CreateUser?appKey=XXXXXXXXXXXXXXX,
headers: {
'ACCEPT':'application/json',
'Content-Type':'application/json',
'Access-Control-Allow-Origin': '*',
},
data: {
'name':req.params.name,
'password':req.params.name,
'description':req.params.name
}
}
request(payload, function (err,response,body) {
//var data = JSON.parse(body);
//console.log(data);
res.send('Hello '+body)
})
any idea how I can get this working?
Thanks,
Mustafa
I'm not super familiar with node, but if you're using Request, this is working for me in PostMan:
var request = require("request");
var options = { method: 'POST',
url: 'http://localhost/Thingworx/Resources/EntityServices/Services/CreateUser',
headers:
{ appkey: 'c30da817-cf61-49ea-a2b0-c9027c7eaa29',
accept: 'application/json',
'content-type': 'application/json' },
body:
{ name: 'helloUser123',
password: 'test123',
description: 'testDescription' },
json: true };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
I don't really see anything wrong with your request, however, and I can't get that same error despite trying a few things. Are you use the parameter name is being passed? Could you try hardcoding this to some value and see if you get the same error? Maybe it is because you are using data instead of body?
yes this has worked this time, thank you