Bypass random id in Firebase Realtime REST - firebase

If my data structure looks like this:
documents.json:
{
"-NG8qzvgs46A5gojZbJO": {
"-NG8r-2q1-47MWK35aT2": {
"description": "My Description",
"title": "My Title"
},
"author": "jim",
"date": "05/11/2022"
},
"-NG8ta4xpHGZxA4JRUQZ": {
"-NG8ta9e90ChdMQclirn": {
"description": "My Description",
"title": "My Title tom"
},
"author": "tom",
"date": "04/11/2022"
},
"-NG8tjfP_TYJHZcjouY8": {
"-NG8tjiryoxnWbb4wwQQ": {
"description": "My Description ccc",
"title": "My Title jim"
},
"author": "jim",
"date": "05/11/2022"
}
}
How to get all the entries where author="jim"?
This does not work:
https://testing-11f41-default-rtdb.firebaseio.com/documents.json?orderBy="author"&equalTo="jim"
Is it possible using Firebase REST API?
Thanks in advance.

When I access the URL you give, I get this response:
{
"error" : "Index not defined, add ".indexOn": "author", for path "/documents", to the rules"
}
As this message says, you need to add an index to allow this query.
In your rules:
{
"rules": {
...
"documents": {
".indexOn": "author"
}
}
}

Related

How to find the parent keys of a jsonpath result

I have this json obj
{
"abc": {
"some_field": {
"title": "Token",
"type": "password"
},
"some_field_2": {
"title": "Domain",
"type": "text"
},
"some_field_3": {
"title": "token2",
"type": "password"
}
}
}
And I want to get a list of keys [some_field,some_field_3] where type=password
This jsonpath $..[?(#.type=='password')] returns:
[
{
"title": "Token",
"type": "password"
},
{
"title": "token2",
"type": "password"
},
]
What should I do?
Thanks.
You are almost there, just need to add a ~ to the end to get the key(s) instead of the value(s):
$..[?(#.type=='password')]~
Note: this might not work depending on your jsonpath engine. It works on https://jsonpath.com.

Graph API search by metadata / column value

I'm developping an application using MS Graph API on a sharepoint site.
I'm trying to build the URL that allow me to find a drive item in a library with a colum param.
Actually I built this get URL to retrieve the drive items in the library:
https://graph.microsoft.com/v1.0/sites/{mainSite}:/sites/{subsite}:/lists/{libname}/items
I obtain a JSON with all files.
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.list)('myLib')/items",
"value": [
...
{
"#odata.etag": "\"7773c0de-bed1-425b-9065-2310c600757b,6\"",
"createdDateTime": "2019-11-21T09:19:57Z",
"eTag": "\"7773c0de-bed1-425b-9065-2310c600757b,6\"",
"id": "24",
"lastModifiedDateTime": "2020-05-27T09:09:05Z",
"webUrl": "https://xxxx.sharepoint.com/sites/SUBSITE/myLib/Cartouche.docx",
"createdBy": {
"user": {
"email": "xxx#xxx.fr",
"id": "5fe24d57-1357-4fef-9cae-bfd79b0bf831",
"displayName": "David Vera"
}
},
"lastModifiedBy": {
"user": {
"email": "dvera#dsidiff.fr",
"id": "5fe24d57-1357-4fef-9cae-bfd79b0bf831",
"displayName": "David Vera"
}
},
"parentReference": {
"id": "1836034d-8a35-4488-995e-a7fe9cd30b4c",
"siteId": "xxx.sharepoint.com,82a2327c-e2cf-4d30-b529-31c3bcdcda5e,fbi3zrs9-b07a-4777-945b-3b42c5c876d"
},
"contentType": {
"id": "0x010100E4AD49D3A8873645A2803D49D2A4BF60"
}
},
...
]
}
I tried to use filter :
https://graph.microsoft.com/v1.0/sites/{mainSite}:/sites/{subsite}:/lists/{libname}/items?expand=fields(select=CODE_ANNONCEUR,val)&filter=fields/val eq 'myself'
It returns me :
{
"error": {
"code": "-1, Microsoft.SharePoint.Client.InvalidClientQueryException",
"message": "The expression « fields (select ») is not valid.",
"innerError": {
"request-id": "c3edc510-2d63-4f21-86cd-a377fb02d324",
"date": "2020-05-27T09:44:23"
}
}
}
I solved the issue this way :
https://graph.microsoft.com/v1.0/sites/xxx.sharepoint.com:/sites/yyy:/lists/zzz/items?expand=fields/CODE_ANNONCEUR&filter=fields/CODE_ANNONCEUR eq 'stringExpected'

"Invalid content entity type!" when posting to Linkedin v2/shares

Followed this doc: https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/rich-media-shares to upload images to reference in a organization share in LinkedIn.
Successfully uploaded the image using Assets API. The URN is in this format - urn:li:digitalmediaAsset:XXX
Retrieving asset information using the Asset ID from the digitalmediaAsset URN shows the following status:
{
"serviceRelationships": [
{
"identifier": "urn:li:userGeneratedContent",
"relationshipType": "OWNER"
}
],
"recipes": [
{
"recipe": "urn:li:digitalmediaRecipe:feedshare-image",
"status": "AVAILABLE"
}
],
"mediaTypeFamily": "STILLIMAGE",
"created": 1579015000150,
"lastModified": 1579015039823,
"id": "XXX",
"status": "ALLOWED"
}
But when I write a share using Assets URN -
POST https://api.linkedin.com/v2/shares
{
"content": {
"contentEntities": [
{
"entity": "urn:li:digitalmediaAsset:XXX"
}
],
"description": "content description",
"title": "Test Share with Content"
},
"distribution": {
"linkedInDistributionTarget": {}
},
"subject": "Test Share Subject",
"text": {
"text": "Test Share!"
},
"owner":"urn:li:organization:YYY"
}
I get the following error:
{"message":"Invalid content entity type!","status":400}
Any idea what I am doing wrong?
Add shareMediaCategory field here like this:
POST https://api.linkedin.com/v2/shares
{
"content": {
"contentEntities": [
{
"entity": "urn:li:digitalmediaAsset:XXX"
}
],
"description": "content description",
"title": "Test Share with Content",
"shareMediaCategory": "IMAGE"
},
"distribution": {
"linkedInDistributionTarget": {}
},
"subject": "Test Share Subject",
"text": {
"text": "Test Share!"
},
"owner":"urn:li:organization:YYY"
}
See the documentation for details: https://learn.microsoft.com/en-us/linkedin/marketing/integrations/community-management/shares/share-api#using-images-for-shares

OneDrive API search based on a keyword gives only section information and doesnot give any information about page details

I want to know the page id or page url which has paternity in the content. When i use search functionality, i get the section details but i don't get any information about page.
Query:
https://graph.microsoft.com/v1.0/me/drive/root/search(q='paternity')
Result:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(driveItem)",
"value": [
{
"#odata.type": "#microsoft.graph.driveItem",
"createdDateTime": "2018-07-11T11:06:28Z",
"id": "dfhsdfkhfklsdfsdkjf",
"lastModifiedDateTime": "2018-07-11T11:20:26Z",
"name": "Section1.one",
"webUrl": "https://microsoft-my.sharepoint.com/personal/abcd_contoso_com/_layouts/15/WopiFrame.aspx?sourcedoc=%7B7E1C4305-983D-4CE2-A15E-DBAF1B961423%7D&file=Section1.one&action=default&DefaultItemOpen=1",
"size": 390328,
"createdBy": {
"user": {
"email": "abcd#contoso.com",
"displayName": "abcd"
}
},
"lastModifiedBy": {
"user": {
"email": "abcd#contoso.com",
"displayName": "abcd"
}
},
"parentReference": {
"driveId": "b!QqRkFzhjsdgjkdhfkjdhXiDBfhDiNEmqz4NJGbg-Gcv-NrFDvVRJca8R9-3ylQ",
"driveType": "business",
"id": "01QsdjhdkjhdsdkjhHGT4FXINN2A"
},
"file": {
"mimeType": "application/msonenote"
},
"fileSystemInfo": {
"createdDateTime": "2018-07-11T11:06:28Z",
"lastModifiedDateTime": "2018-07-11T11:20:26Z"
},
"searchResult": {}
}
]
}
Please advise on how to get page level information
The OneNote API has search - you may try using that one:
https://blogs.msdn.microsoft.com/onenotedev/2014/11/17/introducing-the-onenote-search-api-beta-powered-by-bing/

No self href in embedded HAL resource collection

I use the self href from my HAL resources on the client side to find the right path for the CRUD operations. In single(ton) resources this is working fine (see the address resource below, the _links containing the self href is included in the embedded resource) but when it comes down to collections this is a different story. The _links of a collection are not rendered when the collection is in _embedded.
Earlier I worked around this problem by reading the url form the first child. But this is not sufficient. In case the collection is empty I only have
an empty array with no possibility to extract the url like that. If I want to create a new item in the collection I would like that my client knows where to send data using POST by reading the self href from _links. Is it a good idea to include the _links to my collection like this:
{
"_links": {
"self": {
"href": "http://example.com/api/v1/users/1"
}
},
"_embedded": {
"contacts": {
Now I have access to the self href here:
"_links": {
"self": {
"href": "http://example.com/api/v1/users/1/contacts"
}
},
"_embedded": {
"contacts": [
{
"_links": {
"self": {
"href": "http://example.com/api/v1/users/1/contacts/2"
}
},
"id": "2",
"name": "John Smith"
},
{
"_links": {
"self": {
"href": "http://example.org/api/v1/users/1/contacts/3"
}
},
"id": "3",
"name": "Jane Doe"
}
],
}
},
"address": {
"_links": {
"self": {
"href": "http://example.com/api/v1/addresses/1"
}
},
"street": "Bakerstreet 11",
"postal code": "123456",
"city": "Some city",
"country": "Some country",
}
},
"id": "1",
"name": "John Doe"
}
EDIT (one year later)
In the end I solved this by always adding the links of embedded resources to the parent resource. So in the example above my response object would look like this:
{
"_links": {
"self": {
"href": "http://example.com/api/v1/users/1"
},
"contacts": {
"href": "http://example.com/api/v1/users/1/contacts"
},
"address": {
"href": "http://example.com/api/v1/addresses/1"
}
},
"_embedded": {
"contacts": [
{
"_links": {
"self": {
"href": "http://example.com/api/v1/users/1/contacts/2"
}
},
"id": "2",
"name": "John Smith"
},
{
"_links": {
"self": {
"href": "http://example.org/api/v1/users/1/contacts/3"
}
},
"id": "3",
"name": "Jane Doe"
},
],
"address": {
"_links": {
"self": {
"href": "http://example.org/api/v1/addresses/1"
}
},
"street": "Bakerstreet 11",
"postal code": "123456",
"city": "Some city",
"country": "Some country",
}
},
"id": "1",
"name": "John Doe"
}
So no matter whether I embedded the resources or not I always know where they are located. And for the contacts collection I will have the link to my collection endpoint in the _links array and the contacts themselves in _embedded.
Yes. It's not only good practice to do so; it's recommended by the HAL spec:
Each Resource Object SHOULD contain a 'self' link that corresponds with the IANA registered 'self' relation (as defined by RFC5988) whose target is the resource's URI.
A collection of resources is itself a resource, don't forget.

Resources