can array of links be fetched / resolved in an Entry request - contentful

I am requesting a specific Entry and one of the fields of that Entry is an array of links. Is there a way to get those links to be resolved and returned in the resulting JSON response?
I am trying this via curl
curl -v https://cdn.contentful.com/spaces/o2bhdl4js7ak/entries/<entryID>?access_token=<accessToken>&include=2
The "include=n" parameter does not work in this particular case. should it?
Here's a snippet with the field I expect to be resolved / expanded
"lessons": [
{
"sys": {
"type": "Link",
"linkType": "Entry",
"id": "26hzvgmWtqOcKeoeMQOAoO"
}
}
],

Have another read of the Links page on Contentful Developer Documents.
Contentful Developer Documents - Links
to get a relationship link into the json you are requesting then you change the request link slightly as documented. instead of using the entryID where you have it after the entries/ in your link in the question, use it as demonstrated below.
https://cdn.contentful.com/spaces/oc3u7dt7mty5/entries?access_token=6cabb22c95d52aa7752fe70ae9b3271a1fc2decf7ae7d99ccd7dceba718980e6&content_type=3HjHXUYR3yyosUqAGmi8wu&fields.restaurantField.sys.id=2UmoQ8Bo4g4S82WmGiQIQE
It's been moved into the sys.id at the end of the URL.

Related

Couchdb how to get the timestamp of the last modified database?

Does anyone know how to get the last timestamp that a specific database was modified?
The API _changes does not provide that information. Thank you.
UPDATE
How to retrieve the last date /time that the database had anew document inserted or a modified one.
CouchDB does not record the time that each change occurred, so if you need this functionality you need to a add a timestamp into the document e.g.
{
"_id": "myid",
"name": "Bob",
"email": "bob#aol.com",
"timestamp": 1657614546263
}
Then a MapReduce view will allow you to query documents by timestamp:
function(doc) {
emit(doc.timestamp)
}
To get a the latest change you would query the resultant view with ?descending=true&limit=1 to get the most recently modified document:
GET /mydb/_design/myview/_view/myview?descending=true&limit=1&include_docs=true`
Alternatively, you can use a document id that has a timestamp encoded within it. See this blog post which shows how documents with time-sortable ids allow easy querying of the latest documents to be added.

How To Retrieve Custom Columns For DriveItems in MS Graph

I'm trying to use the Graph API to retrieve a hierarchy of files in a Sharepoint document library. Since document libraries are stored in "drives" (is it technically correct to call it OneDrive?), I'm using the /drives endpoint to fetch a list of files, like this:
https://graph.microsoft.com/beta/drives/{driveid}/root/children
I would like to get information from some of the custom columns that exist when viewing these items through Sharepoint. Using ?expand=fields doesn't work because fields only exists in listItem object of the /sites endpoint, not in the driveItem object of /drives endpoint. If I try obtaining the listItem from a single driveItem (traversing the Graph from OneDrive to Sharepoint), and then expanding the fields, like
https://graph.microsoft.com/beta/drives/{driveid}/items/{driveItemId}/listItem?expand=fields
this retrieves built-in columns (Author, DocIcon, and some others) but doesn't seem to retrieve the custom columns.
I've also tried getting the list of files from the /sites endpoint, and using ?expand=fields will get the custom columns, but it gets every file from every subfolder, rather than the current folder path. But I feel that deserves its own SO question.
Is it possible to retrieve custom column information from driveItems?
I spent a lot of time digging around with the different syntax possibilities and was finally able to get custom library properties using this query format. This is the only one that has produced my custom/user-defined fields for a document library.
https://graph.microsoft.com/v1.0/drives/insert_drive_id_here/root/children?expand=listItem
Shortened result:
{
"#odata.context": "...",
"value": [
{
"#microsoft.graph.downloadUrl": "...",
"listItem#odata.context": "...",
"listItem": {
"#odata.etag": "...",
"fields#odata.context": "...",
"fields": {
"#odata.etag": "...",
"Title": "...",
"Other_Custom_Property": "..."
}
}
}
]
}
I did some testing. What SHOULD work is:
https://graph.microsoft.com/beta/drives/{driveid}/root/children?$select=id,MyCustomColumnName
However, when I did that, it just returned that id field. In my opinion, that is a bug in the graph because this same type of query does work in the SharePoint REST api.
If this helps, you can accomplish this by using the SharePoint REST api. Your endpoint query would be something like:
https://{yoursite}.sharepoint.com/sites/{sitename}/_api/web/lists/(' {DocumentLibraryID}')/items?$select=id,MyCustomColumnName
There are other ways to do the same query.
Try the list endpoint then expand driveItem and fields. You now have both custom column fields and drive item fields.
/beta/sites/[site-id]/lists/[list-id]/items?expand=driveitem,fields&filter=(fields/customColumn eq 'someValue')

Why doesn't Cloudant / CouchDB compress HTML from the show function?

I have a database in Cloudant, and a show function in my design document which generates hefty HTML files:
function(){
return {
body : doc.bunchOfHTML,
headers : {
"Content-Type" : "text/html"
}
}
}
And I've noticed that accessing this page will give back uncompressed HTML. At the same time, when I access my CSS files as attachments of the document, I notice that they are compressed.
Why isn't the output of the show function compressed, and how can we make it so?
It's probably an overlooked / not yet implemented feature.
However, if your documents do not depend on query parameters and are static documents, you could store the HTML as an attachment and use routing to access them. Refer to Cloudant's blog post on the _rewrites array for more information (tip: pay special attention to the 'relative paths' section at the end):
[{
"from": "/mydocs/:docid",
"to": "/../../:docid/show.html",
"query": {}
}]
Drawback to this method is that your 404s will be ugly, unless you have so little documents that you can route them individually.

CouchDB view default options in design document not working

The problem is simple: I have written map functions in a design document of a CouchDB database, which emits something {"_id":doc._id}. Together with include_docs=true query option, I will get the desired results with the linked documents. Because the map functions are designed to work with include_docs=true, I put this option in the design document and make it default:
{...
"options":{"include_docs":true}
...}
However, when I query the view, the results are still those without the linked documents, and I need to specify the option explicitly in the query. I also tried to pu other query option (e.g. limit=200) into the design document, they did not work either.
I am using CouchDB 1.5, and cannot find any discussion, issue or bug regarding this. Does anyone have any idea? Thanks in advanced!
Edit: I have reported the issue in Apache, and I am told that the statement about this was removed.
_design/ddoc/options cannot do that.
According to couchdb's docs, a design doc's options object properties only affect view indexing, not view querying. (The only two settings being local_seq and include_design).
_design/ddoc/rewrites can!
If you want to set query options server side, you can do so by specifying a rewrites array in your design document.
Let's say you want to expose a query to _view/myview that has include_docs set to true, you add the following rewrites array to your design document:
{ "_id": "_design/myddoc"
, "views": { "myview": { "map": "function(doc) { ... }" } }
, "rewrites":
[ { "from": "allmyviews/myview"
, "to": "_view/myview"
, "query":
{ "include_docs": "true"
}
}
]
}
Now, when you request http://localhost:5984/mydb/_design/myddoc/_rewrite/allmyviews/myview without the include_docs parameter, couchdb will respond as if you had included it.

Finding the content element of a gdata entry

The Google Documents List API (v3) references a "content element" several times. In the content element there is a URI to export the file and the mime type of the file.
How can I find the content element and extract that information?
Thank you!
i used google oauth playground to make a sample request - posted response on pastebin...
Following the 'title' element, you can see the 'content' element you requested with the URI containing a node=export.
"content":{
"type":"text/html",
"src":"https://docs.google.com/feeds/download/documents/export/Export?id\u003d1mCHy6rcaqFoyZaJ-3qwRBZyirxnmew1m4CfEtOWAhjw\u0026v\u003d3"
},
once i authenticated to the playground , i used the following request for this example:
https://docs.google.com/feeds/default/private/full?v=3&alt=json&max-results=1
Using playground and json prettyprint instructions in my answere here

Resources