Unable to fetch lookup field values using REST api - rest

I am using REST api to fetch data from a SharePoint list.
I am able to get the lookup fields data using this query:
requestUri = "/_api/lists/GetByTitle('Data')/items?$select=ID,Title,Department/Title&$expand=Department.
However when I use this query requestUri = "/_api/lists/GetByTitle('Data')/items(6)" or this query requestUri = "/_api/lists/GetByTitle('Data')/items?$select=ID,Title,Department/Title&$expand=Department&$filter=ID eq 6" I am not getting the data from the lookup fields.
What could be going wrong here?

I tested with the endpoint, it works:
/_api/web/lists/GetByTitle('ListName')/items(1)?$select=ID,Title,Department/Title&$expand=Department
Compared the url with yours in original question, only append web behind /_api, it should be working.

The issue was found.
Figured out that I was fetching an item for which all the lookup fields were blank.
I fetched another item, and data was returned as expected.

Related

How to define id in POST request using Ravendb

Hello there
I'm having a trouble when I try to insert a document into a Ravendb Server which is running in my other computer. I can retrieve documents easily, but when I try to use REST API with POST request I get this error
"System.ArgumentException","Message":"Query string value 'id' must have a non empty value","Error":"System.ArgumentException: Query string value 'id' must have a non empty value
even though I have my Id defined like this:
{
"id":"adawd",
"name":"genereicname",
"password":"something"
}
Originally I'm making a flutter application but currently I'm just testing the API with Postman.
I messed around with id's (String, int) tried to leave it empty but no luck, does anyone know how to define Id for raven db to send me that sweet 200 response code...
According to the documentation you should use PUT to upload a new document or modify an existing one.
See: https://ravendb.net/docs/article-page/5.2/csharp/client-api/rest-api/document-commands/put-documents

CosmosDB pagination with requestContinuation not returning results

I'm using JPA with CosmosDB to fetch entries from containers.
I have to implement pagination and, according to the documentation, it should rely on the requestContinuation string, which is null on the first request and not null afterwards.
To make things more simple, I created a basic app which calls the repository, takes the requestContinuation object and then makes a new request using it's value.
I have 8 objects in the CosmosDB container and the page size is 5. The first request returns 5 elements and the requestionContinuation value
{"compositeToken":"{\"token\":null,\"range\":{\"min\":\"\",\"max\":\"FF\"}}","orderByItems":[{"propertyBag":{"item":[2021,5,20,14,13,52,716826900]},"item":[2021,5,20,14,13,52,716826900],"map":{"item":[2021,5,20,14,13,52,716826900]}}],"rid":"7eYNAKj8mAMIAAAAAAAAAA==","inclusive":true}
I use it, AS IT IS, to make a new request
Pageable pageable = new CosmosPageRequest(0, size, requestContinuation, Sort.by(sort));
return repo.findAllByUserId(userId, pageable);
The result is empty and the new requestContinuation is null. The page object correctly states that the total number is 8 but never returns the missing 3.
The value of the requestContinuation is not a valid JSON, if you analyze it. I also tried replacing the \ from the compositeToken part of the JSON, which made it a valid JSON. If the invalid JSON is accepted by CosmosDB but the result is empty, the valid JSON is rejected as being INVALID :)
I looked into various sources and I saw something about encoding. I tried to URLEncoder class but it didn't work.
Does anybody have an idea?
Thanks.
UPDATE
The query is also sorting by the creation date. If sorting is removed, the new token works. It's structure is different.
Old token - with sorting:
{"compositeToken":"{\"token\":null,\"range\":{\"min\":\"\",\"max\":\"FF\"}}","orderByItems":[{"propertyBag":{"item":[2021,5,20,14,13,52,716826900]},"item":[2021,5,20,14,13,52,716826900],"map":{"item":[2021,5,20,14,13,52,716826900]}}],"rid":"7eYNAKj8mAMIAAAAAAAAAA==","inclusive":true}
New token - no sorting:
{"token":"+RID:~7eYNAKj8mAMKAAAAAAAAAA==#RT:1#TRC:5#ISV:2#IEO:65567#QCF:4#FPC:AQoAAAAAAAAADQAAAAAAAAA=","range":{"min":"","max":"FF"}}
The second request, with the continuationToken, was returning an empty response because the ordering field was a LocalDateTime field, which in CosmosDB is serialized as an array. I fixed the issue by adding this to the LocalDateTime field:
#JsonFormat(pattern="yyyy-MM-dd'T'HH:mm:ss'Z'")
This way, the sorting field is a string and can be used for ordering.
Just Encode the Request Token and it will work like charm

Filtering data using rest api fetched from Document library in SharePoint

I am able to fetch the documents that are uploaded into the document library of SharePoint online. Now I want to filter the contents that are getting fetched based on a Lookup column and Choice column. But filter is not working in rest api. Can anyone help here? Below is the part of the url I am using.
/items?$select=,FieldValuesAsText/FileRef&$expand=FieldValuesAsText&$
filter=FieldValuesAsText eq ‘Workbook.xlsx'",
If you want to filter data by file name, we can use the rest api below.
/_api/web/lists/getbytitle('DL')/items?$select=*,FieldValuesAsText&$expand=FieldValuesAsText&$Filter=FileLeafRef eq 'Workbook.xlsx'
If you want to filter data base on lookup field and choice file, we can use this. In my test, the lookup field is "MyLookup" and choice field is "MyChoice".
/_api/web/lists/getbytitle('DL')/items?$select=*,FieldValuesAsText,MyLookup/Title&$expand=MyLookup&$Filter=MyChoice eq 'Choice1' and MyLookup/Title eq 'lookup1'
you can try this one:
/_api/web/Lists('ListGUID')/items?$select=FieldValuesAsText/FileRef&$expand=FieldValuesAsText&$filter=FileLeafRef eq 'filename.txt'

Query related Rest Api in ErpNext

I am trying to fetch data and filter data from erpnext customized site.
When i fetch the fields of the doctype i use the url:- https://runga.rungamatteegroup.com/api/resource/Tea%20Invoice?fields=["name","grade","status","invpr","invsuf","estatename","dop"]
I get the data absolutely fine.
When i fetch the data with filtration, using the url:- https://runga.rungamatteegroup.com/api/resource/Tea%20Invoice/?filters=[["Tea%20Invoice",%20"status",%20"=",%20"Sold%20&%20Delivered"]]
I get the data absolutely fine.
When i try to merge the fields and filter in the url as querystring , i am not able to get it together. the url is :-
https://runga.rungamatteegroup.com/api/resource/Tea%20Invoice/?fields=["status","name","dop"]?filters=[["Tea%20Invoice",%20"status",%20"=",%20"Sold%20&%20Delivered"]]
I am trying this to get the fields of the filtered data only.Because fetching all the data and then filtering will be very hectic.
https://runga.rungamatteegroup.com/api/resource/Tea%20Invoice/?fields=["status","name","dop"]&filters=[["Tea%20Invoice",%20"status",%20"=",%20"Sold%20&%20Delivered"]]
This will work

How to get more than 100 query results with Azure DocumentDB REST API

I am following a sample for Azure DocumentDB below. In the sample, C# code queries for documents in the DocumentDB.
https://github.com/Azure/azure-documentdb-dotnet/blob/master/samples/rest-from-.net/Program.cs
Line 182:
var qry = new SqlQuerySpec { query = "SELECT * FROM root" };
var r = client.PostWithNoCharSetAsync(new Uri(baseUri, resourceLink), qry).Result;
The problem is the result 'r' only contains the first 100 documents. If I use the Client SDK, I can get more than 100. I tried using stream, but had no luck so far. Any help would be appreciated!
For a SQL query the results are returned in segments if the result set is too large. The results are returned in chunks of 100 items or 1 MB (whichever limit is hit first) by default.
You can either use continuation tokens to get each segment after another. Or you set the x-ms-max-item-count custom header in a request to increase the limit to an appropriate value.
You can have a look the the REST API for further details.
For the sample program you have to add the line
client.DefaultRequestHeaders.Add("x-ms-max-item-count", "1000");
in order to get 1000 documents instead of 100.
I'm just guessing here, but it might be worth a shot. Here's the documentation from MSDN that describes the List action:
https://learn.microsoft.com/en-us/rest/api/documentdb/list-documents
In the "Headers" section under "Response" it is mentioned that you might get an optional token in the header "x-ms-continuation". Based on the description you have to issue another GET request with this token specified to get the other elements of the result set.
Can you check whether you get a header like this in the response? If so, you can issue another get request with this token specified (see the same documentation page under "Request").