Netsuite - REST API - Making query with Token Based Authentication (TBA) - (in Python) - rest

This is a follow up to the successful call using Netsuite Token Based Authentication (TBA) REST webservice,
I would like to get some guidance on how to perform a query.
I am supposed to read records like this (please see screenshot)
how can I perform a specifc query (by table for a list of records and also specific record) ?
https://gist.github.com/axilaris/4386c3537d04737d3775c156562b7545 <-- here is the python code for the TBA that has worked successful. I would like to know how to construct the next step on how to perform the query and read specific record (as shown in the screenshot).
This is a custom record with an ID like this customrecord1589

To query a specific record: You're going to need to create/ deploy a RESTlet in Netsuite similar to the following:
/**
* #NApiVersion 2.1
* #NScriptType Restlet
*/
define([
"N/log",
"N/search",
], function (log, search) {
function post(context) {
return JSON.stringify(getCustomRecords(context));
}
function getCustomRecords(context) {
log.debug('POST Context', context);
return search.lookupFields({
//Change CUSTOM_RECORD to the type of custom record you are querying
type: search.Type.CUSTOM_RECORD + '1589',
id: context.id,
columns: context.fields,
});
}
return {
post: post,
};
});
In your Python Script: Make sure you change the URL of the request to the deployment URL of this new RESTlet. Also, make sure to pass any parameters you need (like 'id' or 'fields' in my example) in your POST request payload. So instead of:
payload = {
"name":"value",
"foo":"bar",
"duck":"hunt",
}
pass
payload = {
"id":"9999999",
"fields": ["custrecord_field1", "custrecord_field2"],
}
where id is the internalid of the record you want to query and the fields array are the internalids of the fields you want values from.
If this goes successfully, the result should show up as conn.text in your python script!

Related

In Tableau's graphiql, how to I filter for populated elements?

Using the borwser, I want to get back the names of workbooks that have upstream Flows. I think s something like below:
query fq {
workbooks(filter: {has: upstreamFlows})
{
name
upstreamFlows {
name
}
}
}
That gives me error Validation error of type WrongType: argument 'filter' with value 'ObjectValue{objectFields=[ObjectField{name='has', value=EnumValue{name='upstreamFlows'}}]}' contains a field not in 'Workbook_Filter': 'has' # 'workbooks'",
Looking for how to do it in the browser, am familiar with how to do it using api
Does Tableau's graphiql allow for filtering on missing/not missing ?

Can I send any other parameter rather than id, to fetch Function of mongoose to get that specific data from mongodb

This is a fetch code, which is working fine to get the specific data from mongodb, like in the below code i got the specific year, but I wanted to send the parameter from my front end and based on that parameter I wanted to fetch, but the send parameter is not in req.body, although I get the parameter in create , update and delete functions, but not working in fetch func. I dont know why
export const getOfferedCourse = async(req,res) =>{ //it is time consuming task so this func is async
console.log('within controller',req.body);
try{
const course = await OfferedCourse.find({year:'2021'}).exec();
res.status(200).json(course);
}catch(error){
res.status(404).json({ message: error.message});
}
}
For sending a POST request with JSON body, you'll need to use the body-parser middleware to parse the request body into req.body
app.use(express.json());
For GET requests with query params, use req.query

get route only with specified parameter

I am new to MongoDB and CRUD APIs.
I have created my first database and inserted some data. I can do get, post and delete requests.
Now I want to request a 'get' by adding a parameter, so I do the following:
router.get('/:story_name', async function (req, res, next) {
const selectedStory = await loadStoryToRead()
res.send(await selectedStory.find({}).toArray())
})
say that story_name is S1C1,
I can do http://localhost:3000/api/whatever/s1c1 to get the data.
I would have expected to retrieve the data ONLY by using the specified parameter, however I can use the ID or the date or any other parameter found in the json file to get the data.
for example I can do
http://localhost:3000/api/whatever/5d692b6b21d5fdac2... // the ID
or
http://localhost:3000/api/whatever/2019-08-30T13:58:03.035Z ... // the created_at date
and obtain the same result.
Why is that?
How can I make sure that if I use router.get('/:story_name' ... I can retrieve the data only if I use the 'story_name' parameter?
Thanks!
* UPDATE *
my loadStoryToRead() looks like this:
async function loadStoryToRead () {
const client = await mongodb.MongoClient.connect(
'mongodb+srv://...', {
useNewUrlParser: true
})
return client.db('read').collection('selectedStory')
}
I will try to reformulate my question.
I want to ensure that the data is retrieved only by adding the 'story_name' parameter in the URL and not by adding any other parameter within the file.
The reading that I have done suggested to add the parameter to the get request, but when I do it, it doesn't matter what parameter I enter, I can still retrieve the data.
The delete request, however, is very specific. If I use router.delete('/:id'... the only way to delete the file is by using the ID parameter.
I would like to obtain the same with a get request and not using the 'id' but by using 'story_name'.
you can use regular expression capabilities for pattern matching strings in queries.
Syntax is:
db.<collection>.find({<fieldName>: /<string>/})
for example, you can use
var re = new RegExp(req.params.story_name,"g");
db.users.find({$or:[{"name": re}, {"_id": re}, {..other fields}]});
You can use $and and $or according to your requirement.
To read more follow the link
https://docs.mongodb.com/manual/reference/operator/query/regex/

Updating Data From MongoDB using Web API

I have a database that created in MongoDB using Robomongo tool. How can I update these data in Web API by its default POST, PUT, DELETE methods in ValuesControllers.cs?
Database name : StudentInfo
Collection Name : Student
{
_id : ObjectId(),
name : "lqbal",
department : "CSE",
phone : "0194949402"
}
Here is an example of the POST Action. WebApi can perform Model binding so it can take content from the body of the POST action and bind it to a c# entity - in this case the Student object.
Here is the content of the Request Body.
{
"name": "lqbal",
"department": "CSEGlobal",
"phone": "0194949402"
}
Also make sure to set the Content-Type of the Reqest to application/json so WebApi can perform the correct model binding.
The code in the POST action then has to look up the student in question in the DB. Once it retrieves the Student object, it can update the values and then save the object back to the DB.
public void Post([FromBody]Student value)
{
var student = ((MongoCollection)collection).AsQueryable<Student>().First(c => c.name == value.name);
student.department = value.department;
student.phone = value.phone;
collection.Save(student);
}
The concept for the PUT action is similar to this POST action except that a new Student object is created.
The DELETE action is straightforward as well is similar to the GET action - you only need to pass the ID of the record to delete in the query string and then just delete it in the action controller.
Here is a link to how to remove a document with the mongo c# driver
Mongo c# Driver - Remove an Existing Document

Yii2 REST API fields (user?fields=id) does not work

I've got the REST API working with the user table provided in the base migration. I can "GET /users" just fine, but according to the docs, I should also be able to "GET /users?fields=id" and receive a response limited to the id fields.
But instead I get the full result set.
Under the topic Fields in Yii2 Guide it says;
// only returns field id and email, provided they are declared in fields()
http://localhost/users?fields=id,email
so you have to override the fields() function to get the expected result.
// explicitly list every field, best used when you want to make sure the changes
// in your DB table or model attributes do not cause your field changes (to keep API backward compatibility).
public function fields()
{
return [
// field name is the same as the attribute name
'id',
// field name is "email", the corresponding attribute name is "email_address"
'email' => 'email_address',
// field name is "name", its value is defined by a PHP callback
'name' => function ($model) {
return $model->first_name . ' ' . $model->last_name;
},
];
}