Firebase Database REST get with orderBy value and parameters - rest

database.rules.json
{
"rules": {
"meetings" : {
".read": true,
".write": true,
".indexOn" : ["date"]
}
}
}
Request URL
"https://{baseURL}/meetings.json?orderBy=date&equalTo=20181005"
Error Message
error: "orderBy must be a valid JSON encoded path"
But
"https://{baseURL}/meetings.json"
No Error.
What did I do wrong? Plz help me.

The value of the name parameter in your URL needs to be enclosed in " quotes. So:
https://{baseURL}/meetings.json?orderBy="date"&equalTo=20181005
Depending on the way you store the values of the date property, the value of the equalTo parameter may also need be enclosed in " quotes. If you store date as a string, it needs to be:
https://{baseURL}/meetings.json?orderBy="date"&equalTo="20181005"
For more on this, read the Firebase documentation on querying using the REST API.

I have faced the exact issue.. and the trick is..the passing value should be "string " encode,
as example below..
searchRecordById(recordId: string) {
return this.http.get(
`https://your-app.firebaseio.com/skdocs.json`,
{
params: {
**orderBy: '"folder"',
equalTo: '"Panchla-2"',**
},
}
);
}

You'll need to escape the quotes for it to work. E.g.
"https://{baseURL}/meetings.json?orderBy=\"date\"&equalTo=\"20181005\""

If you are using curl then try this:
curl 'https://{baseURL}/meetings.json?orderBy="date"&equalTo=20181005'
If you fetch url from web or etc then url should be :
https://{baseURL}/meetings.json?orderBy="date"&equalTo=20181005

Related

Hasura 2.0, is there a way to use wildcards?

Hello everyone I am having some issues with the way I used to query my data before updating to Hasura 2.0 (I am currently on Beta 1), so Before 2.0 if you sent a null value to a query it would act as a wildcard * , now that I updated to 2.0 all query variables must have non-null values, is there anyway I could get around this?
A small query will serve as an example:
query get_student_organization($authorId: Int, $gradeId: Int, $groupId: Int, $schoolId: Int) {
validation: student_organization(where: {author_id: {_eq: $authorId}, escuela_id: {_eq: $schoolId}, grado_id: {_eq: $gradeId}, grupo_id: {_eq: $groupId}}) {
id
}
}
so if I send it with only
{"authorId": 5455}
I expect all other variables to act as wildcards.
Any help is welcome :)
you can simply send your whole where object from your front-end!
That way you can simply omit the null variables at all. For this, you need to tweak your query a little bit.
query get_student_organization($wh_frontend: student_organization_bool_exp!) {
validation: student_organization(where: $wh_frontedn) {
id
}
}
In the variables section, add your non-null variables only:
{
"where_fe": {
"authorId": 5455
}
}
so this time your haven't sent the schoolId, groupId and gradeId which serves your need for a wild-card.

ParseSwift ParseObject QueryConstraint

I have two collections in a mongo DB.
Here is how a document looks in the first collection (MainCollection):
_id
:"mzWqPEDYRU"
TITLE
:"ZAZ: I want."
ownerID
:"lGutCBY52g"
accessKey
:"0kAd4TOmoK0"
_created_at
:2020-03-13T11:42:11.169+00:00
_updated_at
:2020-03-13T17:08:15.090+00:00
downloadCount
:2
And here is how it looks in the second collection (SecondCollection):
_id
:"07BOGA8bHG"
_p_unit
:"MainCollection$mzWqPEDYRU"
SENTENCE
:"I love nature peace and freedom."
Order
:5
ownerID
:"lGutCBY52g"
AUDIO
:"07067b5589d1edd1d907e96c1daf6da1_VOICE.bin"
_created_at
:2020-03-13T11:42:17.483+00:00
_updated_at
:2020-03-13T11:42:19.336+00:00
There is a parent children relationship between the first and the second collection. In the last document we can see the _p_unit field where the "mzWqPEDYRU" part points to the id of the parent in the first collection.
I have one problem from start with the following code:
func theFunction() {
do {MainCollection.query().find() {
result in
switch result {
case .success(let items):
print("items.count = \(items.count)")
for item in items {
/// ....
}
case .failure(let error):
print("Error in \(#function): \(error)")
}
}
}
}
The way this above code is written works fine and I get the number of elements in MainCollection as one would expect. But then comes a less expected behaviour, in this same code if I replace MainCollection by SecondCollection, instead of getting the number of elements in SecondCollection as I would think. I get an error like:
ParseError(code: ParseSwift.ParseError.Code.unknownError,
message: "Error decoding parse-server response:
Optional(<NSHTTPURLResponse: 0x2837211a0> { URL:}
{ Status Code: 200, Headers {} }) with error:
The data couldn’t be read because it isn’t in the correct format.
Format: Optional(\"{\\\"results\\\": .......
Can anybody point out what is causing this?
It is something like:
var SecondCollection.query(unit == documentOne).find()
The .query() method works in a key/value scheme so it should pass the key as a string and the value as the referenced type, so passing "unit" between double quotes is correct:
do {SecondCollection.query("unit" == cell).find() {
The error you're getting is because cell is a Parse.Object and it is expecting a value in that place (a property in this case).
Please try the following and see if it works for you:
do {SecondCollection.query("unit" == cell.id).find() {

Retrieve UserName from ServiceNow

I am able to retrieve records for a particular Incident ID using Invoke-RestMethod. However, while retrieving the data, values like Resolved To, Updated By, etc. get populated by a sysid.
Resolved By comes in this format:
https<!>://devinstance.servicenow.com/api/sysid, value= sysid
I would like to view the username instead of the sysid.
The 'User ID' (user_name) isn't on the Incident, it's on the sys_user table, so you'll have to dot-walk to it.
If you're using the table API, you'll need to specify a dot-walked field to return, using the sysparm_fields query parameter.
This is no problem, just specify your endpoint like this:
$uri = "https://YOUR_INSTANCE.service-now.com/api/now/table/incident?sysparm_query=number%3DINC0000001&sysparm_fields=resolved_by.user_name"
I've specified a query for a specific incident number is requested, but you can replace that with whatever your query is.The important part is sysparm_fields=resolved_by.user_name. You'll want to specify any other fields you need here, as well.
The JSON I get as a result of running this API call, is the following:
{
"result": [
{
"resolved_by.user_name": "admin"
}
]
}
Note the element name: "resolved_by.user_name".
Another option for doing this, would be to tell the API to return both display, and actual values by specifying the sysparm_display_value parameter and setting it to all to return both sys_id and display value, or just true to return only display values.
Your URI would then look like this:
https://dev12567.service-now.com/api/now/table/incident?sysparm_query=resolved_byISNOTEMPTY%5Enumber%3DINC0000001&sysparm_display_value=all
And your JSON would contain the following:
"number": {
"display_value": "INC0000001",
"value": "INC0000001"
},
"resolved_by": {
"display_value": "System Administrator",
"link": "https://YOUR_INSTANCE.service-now.com/api/now/table/sys_user/6816f79cc0a8016401c5a33be04be441",
"value": "6816f79cc0a8016401c5a33be04be441"
},
"sys_updated_by": {
"display_value": "admin",
"value": "admin"
},
This would be accessed by:
answer.result[n].resolved_by.display_value

MongoLab API Update: message: "Update object is missing."

Unable to update data in the data base. The above is a request link.
https://api.mongolab.com/api/1/databases/my-db/collections/my-coll/52f7b875e4b0e615e67f0a41?jsonbody=[{"_id":"52f7b875e4b0e615e67f0a41","like":"true"}]&apiKey=my_api_key
Got. 400 Bad Request error and message: "Update object is missing."
Or anyone can give an example to update mongodb via REST API in java would be very helpful.
Thanks.
It looks like you're missing the actual update spec, which should be the body of the PUT request. The MongoLab Data API docs include example of how to do that from jQuery, the key bits of which I've copied below for your convenience.
$.ajax( { url: 'https://api.mongolab.com/api/1/databases/my-db/collections/my-coll?apiKey=myAPIKey&q={"_id":1234}',
data: JSON.stringify( { "$set" : { "x" : 3 } } ),
type: "PUT",
contentType: "application/json" } );
Note that the $set update operator is not part of the url, but the body (which you specify in jQuery using the data field).

OData substringof or startswith returning all items

I'm trying to filter my results from a Rest Call.
$.ajax({
type: "GET",
headers: {
"Accept": "application/json;odata=verbose"
},
dataType: "JSON",
url: _spPageContextInfo.webServerRelativeUrl + "/_api/lists/getByTitle('Contacts')/items?$select=Title,Id&$startswith('Title','" + request.term + "') eq true",
success: function (data) {
},
error: function (ex) {
}
});
In my Contacts List i'm trying to retrieve the Title and the Id for Items which start with a String or which have the String somewhere in it, here for example it is the Name of somebody.
I also tried it with substringof:
"/_api/lists/getByTitle('Contacts')/items?$select=Title,Id&$substringof(" + request.term + ",'Title') eq true"
which delivers also the same result.
It gives me all List Items from the List and no Filtering is applied.
I build the Url for the Rest after looking here Programming using the SharePoint 2013 REST service
Like the Schema given there I think the Url looks ok, but it not seems so :)
Edit:
Applying the $filter like in the OData Uri Conventions gives me the following error:
{"error":{"code":"-1, Microsoft.SharePoint.SPException","message":{"lang":"en-US","value":"The query is not valid."}}}
Tried it with following Query Strings:
_api/lists/getByTitle('Contacts')/items?$select=Title,Id&$filter=substringof(m,'Title') eq true
_api/lists/getByTitle('Contacts')/items?$select=Title,Id&$filter=substringof('m','Title') eq true
_api/lists/getByTitle('Contacts')/items?$select=Title,Id&$filter=substringof('m',Title) eq true
I've managed to get the filter with substringof returning the correct results when I removed the "eq true".
Using one of your query strings, it should work like this:
_api/lists/getByTitle('Contacts')/items?$select=Title,Id&$filter=substringof('m',Title)
I haven't checked any other functions, but at least, the same happens with startswith function.
For anyone looking at this question, I can report that
/_api/web/lists/GetByTitle('Applications')/items?$filter=startswith(Title,'1AAJ')
IS working for me.
I tried your query URI on my endpoint and applied some changes:
- The second parameter of the substring shouldn't be a string, so I removed the apostropes
After this I get the results:
http://jaydata.org/examples/Northwind.svc/Products?$select=Product_ID,Product_Name&$filter=substringof('CH',Product_Name)
My endpoint is standard WCF Data Service, and the filter is working.
If changing the URI still returns all records, that would be a SherePoint trick I guess. What happens if you put 'zzz' or some random string in the filter?
Check http://www.odata.org/documentation/odata-v2-documentation/uri-conventions/ for the correct uri convention.
Should be
/_api/lists/getByTitle('Contacts')
/items?$select=Title,Id&$filter=substringof(" + request.term + ",'Title') eq true"
So with the $filter included
Also, the contains method works and I've had better compatibility with it. The syntax is:
api/People?$filter=contains(LastName,%27Smith%27)&$select=LastName,FirstName