Fetch the name of Linked Entry in Contentful API - contentful

I'm using Contentful API to get the details of all the entries in a Space, is there a way to fetch the name of 'linked entry/entries' to a particular entry? In this case, i'm fetching all the entries with the content_type = HorizontalImageCard and then that each entry has link to other entries(could be a link to an Asset or link to different Contentul entry), and i would like to get the name of such entries, attaching the screenshot of what i'm looking for, in the screenshot there's a Linked Entry called 'Jennifer Test', how do i fetch that name?
let fetchRes = fetch("https://preview.contentful.com/spaces/{space_id}/environments/ca/entries/{entry_id}?access_token=vOKxCDyhU8gLUsU4FR5tgdwQVe3arwfJzFTCloi2sjM&content_type=HorizontalImageCard");

Did you try with the GraphQL API? I didn't get a chance to try it out with the REST API, but I was able to get the result with the GraphQL API. Here's an example query:
{
userCollection(preview:true) {
items {
name
linkedFrom {
blogArticleCollection {
items {
title
}
}
}
}
}
}
The User content type is linked in the Blog Article content type. This method allows me to list all those references. Hope this helps :)

Related

Create custom API with strapi

I've a content type called continent. Which we the name suggests contains all the information about each continents. Strapi already created API endpoints for me like
continents/:id
But I want to search the continent by it's name since the general user won't be able to search by id
I've created the endpoint
continents/:continent_name
I've also created custom controller following documentation
const { sanitizeEntity } =
requiree('strapi-utils');
module.exports = {
async findOne(ctx) {
const { continent_name } = ctx.params;
const entity = await
strapi.services.continent.findOne({
continent_name
});
return sanitizeEntity(entity, { model:
continents });
And also exposed the API to public
But doesn't seem to anything
Just returns error
How am I supposed to do it
For your use case, you don't need to extend the model controller. You can just pass the continent name as a query param . For example, your url could be something like base_url/continent?continent_name=Asia.
For the code mentioned in the question, there is an issue, the model name should be strapi.models.continent and not continents. Also in the first line requiree('strapi-utils'), you have an extra e in the require. I am assuming that was just a typo.

Can't access unique identifier for Bixby using code from docs

To access a unique identifier for Bixby, I'm trying to access the contactId field within the contact library (which is also viv.self I think?). I tried using the code snippet found in the docs here, but I'm getting some errors.
Code Snippet (Source)
text (Name) {
extends (contact.StructuredName)
}
Errors
ERROR: invalid capsule alias contact
ERROR: unknown super-type: contact.contactId
I would ultimately like to do something like this
integer (Identifier) {
extends (contact.ContactId)
}
Would appreciate any help on accessing this data!
I ended up finding another way to get a device identifier from these docs. There's also a sample capsule here.
In your corresponding JavaScript file, access the $vivContext.locale parameter to return the locale information.
module.exports.function = function accessVivContext (dummyInput, $vivContext) {
var result = "Testing Access vivContext..."
// See docs for all the properties of $vivContext
result = $vivContext.userId
return result
}
You would then need to configure your endpoints for this action like below, including making sure that you set up the proper accepted-inputs for your endpoint:
action-endpoint (AccessVivContext) {
accepted-inputs (dummyInput, $vivContext)
local-endpoint ("AccessVivContext.js")
}

Get GitHub avatar from email or name

I'm trying to get the GitHub user picture (avatar) from users of GitHub.
I've found these API:
https://avatars.githubusercontent.com/<username>
https://avatars.githubusercontent.com/u/<userid>
But I can't find a way to get the avatar from the user email or the user display name.
I can't find documentation about that.
Is there some similar URL API to get what I'm looking for?
You can append .png to the URL for the User's profile to get redirected to their avatar. You can add the query param size to specify a size smaller than the default of 460px wide (i.e. it won't allow larger than 460).
Examples:
https://github.com/twbs.png
https://github.com/npm.png?size=200
https://github.com/github.png?size=40
https://developer.github.com/v3/users/#get-a-single-user
Use the /users/:user endpoint. Should be under avatar_url in the returned json.
For example, my avatar_url can be found by hitting this url.
Edit
There is another way I can think of that is kind of roundabout. Since GitHub uses Gravatar, if you know the email associated with the account, do an md5 hash of the lowercase, stripped email address and construct a url like http://www.gravatar.com/avatar/[md5_here].
This is an old post but nobody has proposed Github Search Users API with scope field :
using in:email : https://api.github.com/search/users?q=bmartel+in%3Aemail
using in:username : https://api.github.com/search/users?q=Bertrand+Martel+in%3Ausername
Or using new Graphql API v4 :
{
search(type: USER, query: "in:email bmartel", first: 1) {
userCount
edges {
node {
... on User {
avatarUrl
}
}
}
}
}
Using GraphQL API v4, this will work too
Query (for username)-
{
user(login: "username") {
avatarUrl
}
}
Response -
{
"data": {
"user": {
"avatarUrl": "https://avatars1.githubusercontent.com/u/..."
}
}
}
GitHub avatar can be accessed through https://avatars.githubusercontent.com/u/YOUR_USER_ID
Optionally, you can modify the size at the end like so https://avatars.githubusercontent.com/u/YOUR_USER_ID?s=460

how to get "my pull requests" from github api?

If you look at: http://developer.github.com/v3/pulls/ it shows you how to get pull requests for a given repository.
How do we get "my pull requests" from the GitHub API similar to the data displayed on the GitHub dashboard?
I asked Github directly. A rep told me to use the search endpoint. Search for issues owned by you that are open and of type pr.
https://api.github.com/search/issues?q=state%3Aopen+author%3Adavidxia+type%3Apr
If you're using a python client lib like Pygithub you can do
issues = gh.search_issues('', state='open', author='davidxia', type='pr')
You can also use GraphQL API v4 to get all your pull requests :
{
user(login: "bertrandmartel") {
pullRequests(first: 100, states: OPEN) {
totalCount
nodes {
createdAt
number
title
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
Try it in the explorer
or using viewer :
{
viewer {
pullRequests(first: 100, states: OPEN) {
totalCount
nodes {
createdAt
number
title
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
First you have to realize that you must authenticate using either Basic Authentication or a token. Next you have to realize that there is no simple way to do this so you will have to be clever.
To be specific, if you probe https://api.github.com/issues, you'll notice that the issues there have a hash called pull_request which should have 3 URLs: html, diff, and patch. All three will be non-null if the issue is also a Pull Request. (Pro-tip: They're the same thing as far as GitHub is concerned…sort of.)
If you iterate over your issues and filter for ones where those attributes are not null, then you'll have your pull requests.

The right pattern for returning pagination data with the ember-data RESTAdapter?

I'm displaying a list of articles in a page that are fetched using the Ember Data RESTAdapter. I need to implement a bootstrap'esque paginator (see: http://twitter.github.com/bootstrap/components.html#pagination) and cant seem to find a sane pattern for returning pagination data such as, page count, article count, current page, within a single request.
For example, I'd like the API to return something like:
{
articles: [{...}, {...}],
page: 3,
article_count: 4525,
per_page: 20
}
One idea was to add an App.Paginator DS.Model so the response could look like:
{
articles: [{...}, {...}],
paginator: {
page: 3,
article_count: 4525,
per_page: 20
}
}
But this seems like overkill to hack together for something so trivial. Has anyone solved this problem or found a particular pattern they like? Is there a simple way to manage the RESTAdapter mappings to account for scenarios such as this?
Try to use Ember Pagination Support Mixin and provide your own implementation of the following method. Instead of loading all the content, you can fetch the required content when the user is navigating the pages. All what you need initially is the total account of your records.
didRequestRange: function(rangeStart, rangeStop) {
var content = this.get('fullContent').slice(rangeStart, rangeStop);
this.replace(0, this.get('length'), content);
}
With ember-data-beta3 you can pass a meta-property in your result. The default RESTSerializer looks for that property and stores it.
You can access the meta-data like this:
var meta = this.get("store").metadataFor("post");
If you are not able to change the JSON returned from the server you could override the extractMeta-hook on the ApplicationSerializer (or any other Model-specific serializer).
App.ApplicationSerializer = DS.RESTSerializer.extend({
extractMeta: function(store, type, payload) {
if (payload && payload.total) {
store.metaForType(type, { total: payload.total }); // sets the metadata for "post"
delete payload.total; // keeps ember data from trying to parse "total" as a record
}
}
});
Read more about meta-data here

Resources