I have two content models in Contentful, an "Article" and a "Tag". Articles have a one-to-many relationship with tags. Is it possible using either the Contentful REST or GraphQL APIs to fetch articles based on multiple related tags?
Below is a cURL request taken from their documentation that demonstrates a way in which items can be retreived via a single related item.
curl --request GET "https://cdn.contentful.com/spaces/$SPACE\
/environments/$ENVIRONMENT/entries\
?access_token=$ACCESS_TOKEN\
&links_to_entry=$PRIMARY_ENTRY_ID"
My immediate thinking to retrieve items based on multiple related items was doing:
curl --request GET "https://cdn.contentful.com/spaces/$SPACE\
/environments/$ENVIRONMENT/entries\
?access_token=$ACCESS_TOKEN\
&links_to_entry=$PRIMARY_ENTRY_ID,$SECONDARY_ENTRY_ID"
This results in an error stating that multiple values for a filter CANNOT be used. Is there another way to accomplish this? If so, can someone provide an example using the REST and GraphQL APIs?
Thoughts, suggestions and/or solutions appreciated!
Related
We have added 2 required custom_fields to our Envelopes that we create through DocuSign.
Now we are trying to fetch these Envelopes and filter them by the value of said Custom fields.
This is working well if we are filtering for 1 value, like in this example:
https://demo.docusign.net/restapi/v2.1/accounts/ACCOUNT_ID_NUMBER/envelopes?status=sent&custom_field=FIELD1%3DVALUE1
Like I mentioned, this works, but we are struggeling to find a way to filter for 2 custom_fields.
We tried some of the usual approaches by using square brackets or using the 'AND' and 'OR' keywords between the filter queries, but none of them seem to be working.
Anyone has an Idea how this could be solved?
Unfortunately the product doesn't support this currently.
Therefore you'll need to make two API calls, one for each custom field. Then your application can compute the intersection of the response envelope ID sets.
I want to create relations between Post and Tag as follows.
Post has many Tags (one-to-many)
Tags have and belongs to many Posts (many-to-many)
I created collection types for Post and Tag.
Set them accessible for public user.
I created 1 post with 3 tags.
Now, when I try to see them at http://localhost:1337/api/posts
I don’t see nested elements, i.e. tags…
Am I missing anything ?
And lastly, I was not able to create Many-to-Many relations between Post and Tag with the following error.
I understand that Tags field already exists, but I thought this is how supposed to be set.
I got reply from Strapi forum, so decided to share here.
https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/rest/populating-fields.html
According to the docs above, to pull (in my case) 1st level nested elements I have to add populate[0] parameter like so:
http://localhost:1337/api/posts?populate[0]=tags
Within Contentful i have the content type "post". The post can have multiple categories (another content type). Now i'm trying to query the posts but filter them on category. My query looks something like this:
https://cdn.contentful.com/spaces/$space/entries?access_token=$token&include=3&fields.categories.fields.slug=features&limit=3&skip=0&content_type=post
The error returned:
You are trying to search on a reference to an unsupported type. You can only search on references to single entries
So basically i can only reference 1 category, but i need many not only in this use case but on a lot more. Any idea how to achieve this?
You could flip the query around and ask for entries that link to a certain category.
curl --include \
--request GET \
https://cdn.contentful.com/spaces/$SPACE_ID/environments/master/entries?access_token=$TOKEN&links_to_entry=7fYxxN67JKyUiYuE4Cq8sI&content_type=post
https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/links-to-entry
Is it possible to get a list of all the views of a database in couchdb using [dscape/nano][1]? The closest I can get with just curl request is this:
http://URL/DBNAME/_all_docs?key=_design/views&include_docs=true.
The above returns all the views including the javascript functions. But I would like to extract only the view names.
In newer CouchDB versions, you can use "_design_docs" to only list the views:
GET /dbname/_design_docs
This will get you the wanted list much faster than if you'd have to go through all the docs (_all_docs).
See 1.3.3. /{db}/_design_docs of the official documentation.
Note: The documentation as of today states this is new in CouchDB version 2.2, but I successfully tested it on 2.1.
Unfortunately the only possible way of doing this is by extracting view names from the result of the query you've included in your question. Futon is doing it this way when populating drop-down list of views, so I think it is safe to assume this is the only solution.
You may also want to change your query to the following to include all design documents, instead of just the one named views:
GET /dbname/_all_docs?startkey="_design/"&endkey="_design0"&include_docs=true
I need to fetch couchdb documents by a bunch of ids. Is there an request / API to do it ?
I don't want to create a view (id, docs) and then do a find by keys.
when the id b-tree already exists
You should use the bulk API documented here.
It could look something like below.
Pass in the keys as part of the body via a POST
Pass in the name of the db (in the example below, it's demodb)
in the url, use the _all_docs for the view
if you want the entire documents returned (and not just the rev), be sure to pass include_docs=true
curl -d '{"keys":["docId1","docId2","docId3"]}' -X POST http://127.0.0.1:5984/demodb/_all_docs?include_docs=true
If you want to fetch a range of documents, you can also use startkey_docid and limit parameters like you would in a view.
What you do is a GET request to a URL like
http://127.0.0.1:5984/demodb/_all_docs?startkey_docid="docId1"&limit=5
Once you have your set of results, you can use the last returned it as the next startkey and run the request again. This has the benefit of skipping view indexing processes (which can be a pain in the ass for large databases).
Documented in the CouchDB API, here.
If you're using the python-couchdb library, you can use:
_, _, response = <your_db>.resource.post_json('_bulk_get', {'docs': [{'id': '<1st_doc_id>'}, {'id': '<2nd_doc_id>'}]})
Your results will be in response['results'].