API - HTTP subschema not defined
I am learning to create an API in integrator.io. I want to retrieve data from a saved search in Netsuite. I created these functions:
function api_mainItemLogic (options) {
let NSObject;
let invokeExportResponse;
let response = {};
NSObject = return_NS_Export_Obj (options);
//Execute the export
try {
invokeExportResponse = exports.runVirtual({export:NSObject});
response.statusCode = 200;
} catch(e) {
invokeExportResponse = JSON.stringify(e);
response.statusCode = 400;
}
// Create body response
response.body = invokeExportResponse;
return {
statusCode: response.statusCode,
headers: { },
body: response.body
}
}
function return_NS_Export_Obj (options) {
let NSObject;
let buyerPartId = options.body.records[0].buyerpartid;
NSObject = {
"_connectionId": "removed",
"netsuite": {
"type": "restlet",
"skipGrouping": true,
"statsOnly": false,
"restlet": {
"recordType": "Item",
"searchId": "1275",
"criteria": [
{
"field": "id",
"operator": "is",
"searchValue": "441" << for testing hardcoded
}
]
},
"distributed": {
"disabled": false,
"forceReload": false,
"executionContext": [
"userinterface",
"webstore"
],
"executionType": [
"create",
"edit",
"xedit"
]
}
},
"adaptorType": "NetSuiteExport"
}
return NSObject;
}
The API will call function: api_mainItemLogic.
Via Postman I am sending a POST request to the API:
POST url/xxxx/request
This is the JSON which I use in the request:
{
"records":[
{"buyerpartid":"123456"}
]
}
However I am getting this error as a response:
{
"code":"missing_required_field",
"message":"http subschema not defined"
}
What am I doing wrong here?
0
Comments
My guess is that the _connectionId in your virtual export is not pointing to a NetSuite connection. i.e. you are likely pointing to an 'HTTP' connection since it is complaining about the missing http subschema. Please double check that the _connectionId is in fact pointing to a NetSuite connection.
Also, here is the general guidance that I tell everyone to get virtual exports and imports working:
The above guidance is very generic and should help craft any virtual exports and imports. i.e. since you first build what you want in the UI, and then just GET the exact JSON from our API.
On a side note, we are planning to make it much easier to parameterize existing exports and imports that you create in the UI so that virtual exports and imports are not needed at all. This ability should get released mid next year. Hopefully you can be successful before this, but I wanted to let you know we will improve this eventually.
Thanks for the detailed answer!
It seems it was pointing to a wrong connection indeed. Virtual export is now working.
However I also tried the second approach just for learning.
Thanks Scott I appreciate it :)
It seems working. However it does not work always. Sometimes when I do a POST request to the same API, without changes to code nor the saved search it gives me this error:
{"code":"sss_invalid_srch_filter","message":"Failed to run saved search because An nlobjSearchFilter contains invalid search criteria: custrecord_scm_cpn_item.name."}
Nuri Ensing You can validate this by supplying the same search criteria on the export from the product UI. This would help you figure out if the problem lies with MyAPI or the saved search criteria.
Bhavik Shah Thanks for your comment. I already did that, and in the UI it works. However sometimes in Postman the API call also works. That is the strange part.
To give a bit more details:
I have a custom saved search from type Item. In this saved search I also join the customer part number records.
It seems that intergrator.io API is having problems when doing a virtual export to a saved search that has joined subrecords in it.
I fixed it by doing a workaround:
Created two virtual exports. First fetching the customer part number records and secondly the items. Until now no errors anymore.
It seems very strange that the API call works sometimes, but not always. Are you submitting the exact same data to the API, and it only works sometimes for the exact same data? Or, is it possible that the problem is related to specific data permutations being sent to the API. I wonder if NetSuite is rejecting some search values. Very hard to say...
Regardless of the above, I am glad you found a work around, and that is def a very common work around to invoke multiple exports and combine the results in your code!
Please sign in to leave a comment.