http.get and http.post through error in scheduled script Netsuite - Error: Cannot find function post in object - netsuite

I'm using schedule script and http.get method but throws error as "Cannot find function get in object".
code snapshot:
var headers_= []
headers_["Content-Type"] = "application/x-www-form-urlencoded";
headers_["Accept"] = "appli`enter code here`cation/json";
headers_["cache-control"] = "no-cache";
var response = http.get({
url: URL_,
headers: headers_
});

Check your define statement. It should be:
define(["N/http"], function (http) {
...
});
If there are other dependencies as well, double-check that the order of the dependencies in the Array matches exactly the order of the parameters in the callback.
If the order matches exactly, make sure you don't have a typo in the parameter name you use for the http module.

Related

Inline component is not defined or not allowed (HTTP PUT)

I have been looking at this for quite some time and I don't know why it fails, because in another controller I have the same code and it updates the model. What do you think it could be?
onAcepta: function(oEvent) {
var oModel = this.getOwnerComponent().getModel();
var oDataModel = this.getOwnerComponent().mainIdentJson;
console.log(oDataModel);
var sPath = "/IdentitiesSet(Userid='" + oDataModel.Userid + "',Ident='" + oDataModel.Ident + "')";
oModel.update(sPath, oDataModel, {
success: function(oData, oResponse){
console.log("OK");
},
error: function(oResponse){
console.log("No");
}
});
this.closeParent();
this.selectedItems = [];
}
Error in Log-dbg.js:
2021-08-13 14:01:40.161899 Request failed with status code 400: MERGE IdentitiesSet(Userid='?????????'.Ident='?') - [{"code":"SY/530","message":"Inline component is not defined or not allowed (HTTP PUT)","persistent":false,"targets":["/IdentitiesSet(Userid='?????????'.Ident='?')"],"type":"Error"}] sap.ui.model.odata.ODataMessageParser
[![2021-08-13 14:01:40.161899 Request failed with status code 400: MERGE IdentitiesSet(Userid='?????????'.Ident='?') - [{"code":"SY/530","message":"Inline component is not defined or not allowed (HTTP PUT)","persistent":false,"targets":["/IdentitiesSet(Userid='?????????'.Ident='?')"],"type":"Error"}]
this is the batch:
and the changes that I want are okay
batch:
so, I think that the batch is doing okay? so I don't know the error
and the weird thing is that in other view in this project, I have an update with this same path and works perfectly.
Are you trying to pass nested payload like we pass to deep insert.
If yes, it wont work as the feature is not supported for Put operation. Instead you need to process it via batch.
Deep Entity Update

Node.js - Why does my HTTP GET Request return a 404 when I know the data is there # the URL I am using

I'm still new enough with Node that HTTP requests trip me up. I have checked all the answers to similar questions but none seem to address my issue.
I have been dealt a hand in the Wild of having to go after JSON files in an API. I then parse those JSON files to separate them out into rows that populate a SQL database. The API has one JSON file with an ID of 'keys.json' that looks like this:
{
"keys":["5sM5YLnnNMN_1540338527220.json","5sM5YLnnNMN_1540389571029.json","6tN6ZMooONO_1540389269289.json"]
}
Each array element in the keys property holds the value of one of the JSON data files in the API.
I am having problems getting either type of file returned to me, but I figure if I can learn what is wrong with the way I am trying to get 'keys.json', I can leverage that knowledge to get the individual JSON data files represented in the keys array.
I am using the npm modules 'request' and 'request-promise-native' as follows:
const request = require('request');
const rp = require('request-promise-native');
My URL is constructed with the following elements, as follows (I have used the ... to keep my client anonymous, but other than that it is a direct copy:
let baseURL = 'http://localhost:3000/Users/doug5solas/sandbox/.../server/.quizzes/'; // this is the development value only
let keysID = 'keys.json';
Clearly the localhost aspect will have to go away when we deploy but I am just testing now.
Here is my HTTP call:
let options = {
method: 'GET',
uri: baseURL + keysID,
headers: {
'User-Agent': 'Request-Promise'
},
json: true // Automatically parses the JSON string in the response
};
rp(options)
.then(function (res) {
jsonKeysList = res.keys;
console.log('Fetched', jsonKeysList);
})
.catch(function (err) {
// API call failed
let errMessage = err.options.uri + ' ' + err.statusCode + ' Not Found';
console.log(errMessage);
return errMessage;
});
Here is my console output:
http://localhost:3000/Users/doug5solas/sandbox/.../server/.quizzes/keys.json 404 Not Found
It is clear to me that the .catch() clause is being taken and not the .then() clause. But I do not know why that is because the data is there at that spot. I know it is because I placed it there manually.
Thanks to #Kevin B for the tip regarding serving of static files. I revamped the logic using express.static and served the file using that capability and everything worked as expected.

Vala - How to create a HTTP request with Soup?

I'm a bit lost with vala docs.
Im trying to do a POST request to my AJAX service with soap lib, but no luck. Can anyone tell me what i'm doing wrong?
string url = "http://myservice/ajax.php";
// create an HTTP session
var session = new Soup.Session ();
var message = new Soup.Message ("POST", url);
//Setting params and request
var params = "action=call&method=get_monuments";
Soup.MemoryUse buffer = Soup.MemoryUse.STATIC;
//(Error here - Line 73)
message.set_request ("application/x-www-form-urlencoded", buffer, params, params.length);
// send the HTTP request and wait for response
session.send_message (message);
stdout.write(message.response_body.data);
Compiler drops following error:
/home/ibsenleo/valaprojects/test/main.vala(73,73): Error: Argument 3: Cannot convert from `string' to `uint8[]'
I'm sure is something about request parameters and the data type, but i couldn't find some useful examples.
Soup.Message.set_request's third argument is a uint8[], not a string, and there is no fourth argument. You probably want something like
message.set_request ("application/x-www-form-urlencoded", buffer, params.data);
See string.data.

Get headers from a request using Nodejs

I'd like to get the headers form a request (ex: status code, content-lenght, content-type...). My code :
options = {
method:'HEAD'
host:"123.30.xxx.xxx"
port:80
}
http.request(options,(res)->
res.send JSON.stringify(res.headers)
)
but this is not working
Please help me :(
Your JSON is not valid and it appears that you are not instantiating options as a variable prior to it's use. ev0lutions code resolves these issues as well as ending the request.
For info on how to create valid JSON check out this tutorial:
http://www.w3schools.com/json/
You need to call .end() on your http.request() object in order to make your request - see the docs:
With http.request() one must always call req.end() to signify that you're done with the request - even if there is no data being written to the request body.
For example:
var options = {
method:"HEAD",
host:"google.com",
port:80
};
var req = http.request(options,function(res) {
console.log(JSON.stringify(res.headers));
});
req.end();
Another issue in your code is that res doesn't have a .send() method - if you're referring to another res variable (for example, containing the code that you have posted) then your variables will be conflicting. If not, you should double check what you're trying to do here.

CouchDB list "An error occured accessing the list: Invalid JSON" error

I'm trying to call a CouchDB list from JavaScript.
My jQuery call is:
var listItems = $.couch.db('foo').list('foo/barList', 'foo/barView');
If I test this in the FireBug console when I'm on a page that has jquery.couch.js loaded (like Futon) it returns exactly what I want it to (several <input> tags with the appropriate data populated).
However, when I call this from code, I get the error:
An error occured accessing the list: Invalid JSON: [the html]
... where [the html] is the html I want to manipulate in my script. I don't understand why I'm getting a JSON error - I thought the point of lists was to return HTML. Is there a way to force it to return my html to me?
Also, my list function includes the following, so I'm not sure why this doesn't work.
start({
"headers": {
"Content-Type": "text/html"
}
});
According to https://issues.apache.org/jira/browse/COUCHDB-1059 this was a recognized bug and it had been patched. However after making the changes in jquery.couch.js recommended by Jan Lehnardt on the above page, I had to do one thing further.
The page above recommends making the following change in jquery.couch.js :
- var resp = httpData(req, "json");
+ var resp = httpData(req, dataType);
For some reason this didn't work for me but it did when I instead replaced it with the following. Theoretically one could add handlers for different types of content-types below.
var cType = req.getResponseHeader('Content-Type');
switch(cType) {
case 'text/html':
var resp = req.responseText;
break;
default:
var resp = $.parseJSON(req.responseText);
break;
}
If I'm missing something, I welcome recommendations on how to do this more effectively, but this works for me.

Resources