I have various GET http calls to my api with the following format:
/api/posts?userId=3
However, it is not filtering posts by its userId column, and just returns all posts, regardless of the posts' userId.
This syntax has worked in past projects I've had also, and is documented here. (The example they give is GET /purchase?amount=99.99).
Questions I've seen do not address the query language via defaults routes in this way, so I'm having trouble finding help. Any guesses on what could be going wrong?
UPDATE:
What does work as expected
req.query is getting set and read by policies (eg, ?userId=3 is found by req.param("userId"))
/api/posts?userId=3&populate=userId populates the userId field, (but still returns all posts for all users)
filtering by primary key (eg ?id=5) filters and returns only one record as expected
When working in the api, or in sails console, (eg Posts.find({userId: 3})) works
What does not work as expected
filtering by foreign keys (eg ?userId=6)
filtering by non-foreign keys (eg ?name=test)
filtering using where (eg &where={"userId":1})
It turns out I was adding a "where" clause to every query in a policy (eg, "where: {"status": "active"}}). Having a "where" in the query string automatically overrides the other params, and so nothing else was getting seen. (To be precise, if you have a where clause, other criteria never get seen)
For some reason, the "where" was also not working to set the search criteria for sails 0.12.13, so I ended up hacking the parseCriteria function actionUtils in sails and using the one they have for v.1 and that worked for me.
Hope that helps anyone in the future
Related
I have my data model already defined and implemented. I can very easily write manually the filter to filter out non-authorized results for the user who sent the query (which would be in the style of: "collection.acl.personId": queryPersonId )
My problem is, where and how should I write this "thing" to be as automatic as possible?
I tried to do it with a custom query and a static method, but did not had any luck on both.
Static method con: I don't want to rewrite all my code to use .then(). I want to keep the current chaining.
Custom query: it simply did not worked, even by following the doc.
Ideal the result would be something like
Model.findWithAcl(filters).lean()
Model.findOneWithAcl(filters).lean()
Note that we are using Typescript. The priority would be to have something working, but having the ability to have a working type would be the second priority right after.
Thanks for any help
Casl mongoose gives a very good way of filtering both results (row level) and fields from collections. Note that it also can be used in the front end.
Great package that works very well with auth0 rights.
https://casl.js.org/v5/en/guide/intro
https://casl.js.org/v5/en/package/casl-mongoose
I want to fetch all documents in a CouchDB database where the document ID starts with a given prefix.
Did some searching and found, according to the CouchDB Documentation, the best way to accomplish this is by using a startkey and endkey, where the startkey is the prefix, and the endkey is the prefix with a high-value unicode character appended at the end.
So, as I understand it, a call to "http://server:5984/some_db/_all_docs?startkey=2018&endkey=2018\ufff0&include_docs=true" should fetch all docs from some_db with an ID starting with '2018'.
That url is being encoded by the web browser as follows:
http://server:5984/some_db/_all_docs?startkey=2018&endkey=2018%EF%BF%B0&include_docs=true
And the response I get back is {"error":"bad_request","reason":"invalid UTF-8 JSON"}
So I tried just sticking to pure ASCII and used ~ instead of \ufff0. Same response. Also got the same response using a z.
If I do something like _all_docs?startkey=2018&endkey=2019&include_docs=true&inclusive_end=false everything works fine and I get the expected results. However, I can't guarantee the prefix will always be a number, and I get the impression trying to implement it like that programmatically will cause me issues some where or some how. Any thoughts?
I'm using Dart running in the web browser to make the request, if it makes a difference.
Update
So, I've realized in actuality _all_docs does not support the endkey and startkey parameters. The request I originally thought was working was actually just returning the entire database.
I had assumed _all_docs supports startkey and andkey because I have used PouchDB in the past, which does support those parameters in the allDocs() function.
Still looking for a solution, since this project is not using PouchDB, but at least now I know what the problem is.
Update 2
Previous update was wrong, Although the documentation of _all_docs doesn't have these parameters listed, there is a note which I had missed indicating it also supports the parameters for view, see my answer below.
Okay, I figured it out.
I was wrong in my update, startkey and endkey are supported by _all_docs because it's just a built-in view, so all the parameters for views apply. However, it expects the passed values to be JSON values, not just a bare string as a key. The solution is just to put quotation marks around the keys.
That is, encoded quotation marks, e.g. startkey=%222018%22&endkey=%222018%EF%BF%B0%22
I created a savedSearch for a savedSearch itself via UI with an internal id customsearch_savedsearch.
When I'm loading the search using a suiteScript. It shows me an Unexpected error has occured.
var search = nlapiLoadSearch(null, 'customsearch_savedsearch');
The above statement works fine for all other record-types, But fails for a savedSearch record type.
What could be the internal id for the savedSearch record type?
You cannot use null for the first parameter. When loading or creating a search, you must specify the record type for the search as well. Whatever record type customsearch_savedsearch searches for, that's what you would pass in as the first parameter.
So for instance if your saved search is a Customer search, then you would load it by:
var search = nlapiLoadSearch('customer', 'customsearch_savedsearch');
Try
var search = nlapiSearchRecord(null, 'customsearch_savedsearch');
Documentation:
nlapiSearchRecord(type, id, filters, columns)
Performs a search using a set of criteria (your search filters) and columns (the results). Alternatively, you can use this API to execute an existing saved search. Results are limited to 1000 rows. Also note that in search/lookup operations, long text fields are truncated at 4,000 characters. Usage metering allowed for nlapiSearchRecord is 10 units.
This API is supported in client, user event, scheduled, portlet, and Suitelet scripts.
If `
var search = nlapiSearchRecord(null, 'customsearch_savedsearch');
does not work`use
var search = nlapiSearchRecord('', 'customsearch_savedsearch');
Everything looks correct in your statement. I think the problem is that SuiteScript does not support SavedSearch record types. Here is a list of supported types.
You should be able to run this using the above mentioned
var search = nlapiSearchRecord(null, 'customsearch_savedsearch',null,null);
I've used this in my code and haven't had any issues. Make sure you have the right permissions set on the saved search. To start with, set it as Public. And in the Audience, "select all" roles.
Your syntax is correct. However, Saved Search type (also like Budget record) is not scriptable even you are able to create a saved search. That is why you encountered that error. Most likely, those record types listed on the SuiteScript Record Browser are supported. You may check the list here:
***Note: You should log in first to the account..
Production: https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2016_1/script/record/account.html
Sandbox: https://system.sandbox.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2016_1/script/record/account.html
I know this is a bit of an old question, and I came across it in my own attempt to do the same, but I just tried the following with success:
var search = nlapiLoadSearch('savedsearch', 'customsearch_savedsearch');
Seemed a little on the nose, but it did the trick.
I have created an OnDemandGrid but noticed that the column sorts weren't working on any column. The arrows are there and the screen refreshes, but it won't sort the columns in asc or desc order. I have even tried specifying for each column but it still doesn't work. Anybody having/had the same issue?
UPDATE: 6.16.15 - After trying sortParam suggestion:
Comment below explains. It appears to be doing the right thing... but still won't sort.
UPDATE 6.16.15 - 4:00pm
Apparently ANY type of filtering or sort doesn't work well with Django - trying to determine how set filtering where dojo can communicate to Django Rest or vice versa - so far haven't been able to find a setting on either side that works. Not only does column sort not work - creating a search field doesn't work, nor creating a sort button.
This is after changing to the ORDERING_PARAM in DJANGO settings.py to 'SORT'... for all intensive purposes this looks like it should work.
A quick search through the Django Rest Framework documentation reveals that it defaults to expecting an ordering query parameter to indicate which field should be sorted. The dstore/Request store (inherited by Rest) allows you to indicate the query parameter name that sends sort information, via sortParam.
Additionally, it appears that DRF's OrderingFilter indicates ascending sort with no prefix, and descending sort with -. dstore/Request defaults to expecting + and - as prefixes, but these can be overridden via ascendingPrefix and descendingPrefix.
So in your case, you'll want to include sortParam: 'ordering', ascendingPrefix: '' in the properties passed when you create your Rest store instance.
In general, when you run into store-related issues like this where the grid and backend don't seem to be making ends meet, this is the process you'll have to follow - find out what the server expects, find out what the client-side store implements, and see if it can be tweaked or needs to be customized.
UPDATE 6.17.15 -
Changing server side settings to match dojo/dgrid parameters -
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAdminUser',),
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
# 'PAGE_SIZE': 25,
'ORDERING_PARAM': 'sort'
I know for a fact that there are atleast 5-6 POI within the 50 mile radius in this area. However, I don't get any results on this query.
https://api.foursquare.com/v2/venues/suggestCompletion?ll=-44.67,167.92&query=milford&radius=50000
I see results when I try search api (it doesnt use query as mentioned in documentation):
https://api.foursquare.com/v2/venues/search?ll=-44.67,167.92&intent=checkin&query=milford&radius=50000
No results with intent match on the search query.
I really like the suggestcompletion api (compact). Any suggestion/input would be great?
Thanks!
The suggestcompletion endpoint is used to suggest venues whose names start with the provided query. The endpoint is used to provide autocomplete results for search input fields. It is not used as a general purpose venue search - you should use the /venues/search endpoint for this purpose.
looks like you have missed out the API version param. You need to denote it by adding this into your request :
&v=20150826
suggestCompletion is included into newer API released on 20150826 which differs from default one that not including suggestCompletion feature.