How can I manage sitemaps in Kentico Cloud? - sitemap

There used to be sitemaps functionality but it got deprecated. Taxonomies are suggested as a replacement but when I request items from the API, the taxonomy elements lack the hierarchical structure. How do I search for an item that represents a parent page in website structure? Thank you.

You can still do that with Delivery API. First, you need to create and and organize your taxonomy group the same way you would organize your sitemap. Consider following sitemap as an example:
Home
About
Our team
Management
Contact us
Mission&Values
This is what the taxonomies would look like in Kentico Cloud:
Models for your items need to be created with taxonomy element, that would serve as a sitemap location selector. When you retrieve this element from the item, it will give you a list of terms that the item is associated with. If you tick two terms with the item (Contact us, Our team), this is what the element would look like in the API:
{
"item": {
"system": {
"id": "8a9e7010-c79b-41c5-a0bc-4f20c9c233b8",
"name": "Example item - contact form",
"codename": "example_item___contact_form",
"language": "default",
"type": "example_content_model",
"sitemap_locations": [],
"last_modified": "2019-05-13T08:20:50.3173519Z"
},
"elements": {
"sitemap": {
"type": "taxonomy",
"name": "Sitemap",
"taxonomy_group": "sitemap",
"value": [
{
"name": "Contact Us",
"codename": "contact_us"
},
{
"name": "Our team",
"codename": "our_team"
}
]
}
}
},
"modular_content": {}
}
As you can see you get information about taxonomy group codename and a flat list of name and codename pairs of each ticked term. To get the hierarchical structure, you need to make second call to retrieve the taxonomy group, which will yield following:
{
"system": {
"id": "0b4e3da2-8699-4b4d-961c-1fe912c91570",
"name": "Sitemap",
"codename": "sitemap",
"last_modified": "2019-05-13T08:01:34.6109452Z"
},
"terms": [
{
"name": "Home",
"codename": "home",
"terms": []
},
{
"name": "About",
"codename": "about",
"terms": [
{
"name": "Our team",
"codename": "our_team",
"terms": [
{
"name": "Management",
"codename": "management",
"terms": []
},
{
"name": "Contact Us",
"codename": "contact_us",
"terms": []
}
]
},
{
"name": "Mission & Values",
"codename": "mission___values",
"terms": []
}
]
}
]
}
Which reflects needed hierarchy. You can compare the codenames you got from your item to the position of the taxonomy term in your group - to get the parent taxonomy term just get the parent JSON node. If you need to figure out the parent item itself, you can call Delivery API again and use one of the array filters to get all the items marked with the parent sitemap location.

Related

Craft CMS category count by slug

I created categories in craft and I'd like to get total amount of entries related to individual category. Right now I have a query that returns my categories:
query categoriesQuery {
categories(group: "projectCategories") {
id
slug
title
}
}
but I would also like for each category to return the amount of related entries.
So I would like to add another field that counts related entries - I wanted to do somethings like this, but it won't work:
query categoriesQuery {
categories(group: "projectCategories") {
id
slug
title
_count(relatedToEntries(section: "projects"))
}
}
Is there any way to get amount of entries related to single category? The result that I'm trying to achieve would look somethings like this:
{
"data": {
"categories": [
{
"id": "1",
"slug": "Category-1",
"title": "Category 1",
"amountOfRelatedEntries": 1
},
{
"id": "2",
"slug": "Category-2",
"title": "Category 2",
"amountOfRelatedEntries": 2
},
{
"id": "3",
"slug": "Category-3",
"title": "Category 3",
"amountOfRelatedEntries": 3
},
]
}
}

I would like to use Blocks instead of Attachments in my Slack App but the app fails to return the message

I recently made my first Slack app - a sort of Tech Support FAQs tool for my workplace workspace.
I originally wanted the responses to be much more complex using the Slack Block Kit, and having trawled the documentation on the Slack API site it looked like I could simply exchange Attachments for Blocks:
function respondWithFaq(text, callbackId, respond, choice) {
frequentlyAskedQuestions.callback_id = callbackId
frequentlyAskedQuestions.text = 'What are you trying to do?'
respond({
text: text,
attachments: [frequentlyAskedQuestions[choice]], //All different choices are saved in a .json array and then saved at the top in a variable called frequentlyAskedQuestions
replace_original: true
})
}
However, when I swap that tag out the messages never print. I have used the Block Kit builder to try and construct more complex and useful responses using multiple sections but it doesn't seem to like more than 1 section in it's responses.
My .json files are structured in arrays depending on which choice was made in the previous select menu like so:
[
{
"fallback": "Upgrade your Slack client to use messages like these.",
"color": "#3AA3E3",
"attachment_type": "default",
"callback_id" : "slack_help",
"actions": [
{
"name": "subject_list",
"text": "Select one",
"type": "select",
"options": [
{
"text": "Add somebody to a channel",
"value": "addToChannel"
},
{
"text": "Find an old message",
"value": "oldMessageThread"
},
{
"text": "Fix my camera",
"value": "cameraBroken"
},
{
"text": "Fix my audio",
"value": "audioBroken"
},
{
"text": "Add a new workspace",
"value": "addWorkspace"
},
{
"text": "Submit a support ticket",
"value": "submitTicket"
}
]
}
]
},
{
"fallback": "Upgrade your Slack client to use messages like these.",
"color": "#3AA3E3",
"attachment_type": "default",
"callback_id" : "box_help",
"actions": [
{
"name": "subject_list",
"text": "Select one",
"type": "select",
"options": [
{
"text": "Fix Box Tools",
"value": "boxTools"
},
{
"text": "Unable to open a file from Box",
"value": "microsoftOnline"
},
{
"text": "Find a file or folder",
"value": "findFile"
},
{
"text": "Edit a file that has been shared with me",
"value": "editFile"
},
{
"text": "Merge my Box accounts",
"value": "accountMerge"
},
{
"text": "Submit a support ticket",
"value": "submitTicket"
}
]
}
]
},
and so on...
I wondered if this was something to do with the Response URL formatting but having read that documentation it appears that Blocks can be used within that.
Any advice or documentation that could help me with this?
I recognise that I am quite new to coding and perhaps I've done something really obvious - please point it out so I can learn!
I followed this tutorial online to create the app, and as they used attachments so did I. Then I tried to adapt from there.

How to edit nested data with admin on rest?

I don't know how to handle nested data with admin on rest.
My GET request returns the full object without additional calls for filters and thumbnails (see below).
Example object:
{
"id": "58bd633e4b77c718e63bf931",
"title": "Project A",
"description": "Blabla",
"image": "https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=350&h=150",
"disable": false,
"filters": [
{
"id": "58c662aa4ea73e3d4373dad7",
"filterValue": {
"label": "Filter value",
"color": "#0094d8",
"id": "58c7999162700623b4aac559"
},
"isMain": true
}
],
"thumbnails": [
{
"id": "58bfeac780021c56cc71bfac",
"image": "http://lorempixel.com/1024/768/",
"description": "Bla",
"device": "desktop"
},
{
"id": "58bfeacf80021c56cc71bfad",
"image": "http://lorempixel.com/800/600/",
"description": "Bla",
"device": "laptop"
}
]
}
My first idea was to create custom Input Components but I don't know if it's the best solution? Any ideas or examples?
Admin-on-rest relies on redux-form, which supports nested attributes. Just set the source of your input as the path to the nested property, with dot separator:
<TextInput source="foo.bar" />
For your filters and thumbnails, you'll have to use redux-form's <Fields> component, and create a custom input component with it.

Google People API - Is it possible to get custom fields?

I need to import google contacts to my application. For that I try to use the Google People API but I didn't find an option to get the contacts custom fields.
Is it possible to get contact custom fields with the new Google People API?
Should I use the old Google Contacts API for that?
Thanks!
Request the userDefined projection with your personFields.
String url = "https://people.googleapis.com/v1/people/me/connections" +
"?personFields=names,emailAddresses,userDefined";
The response looks like this:
"userDefined": [
{
"metadata": {
"primary": true,
"source": {
"type": "CONTACT",
"id": "5629e24b082d1a66"
}
},
"key": "label1",
"value": "foo"
},
{
"metadata": {
"source": {
"type": "CONTACT",
"id": "5629e24b082d1a66"
}
},
"key": "label2",
"value": "bar"
}
]
For more details, see https://developers.google.com/people/api/rest/v1/people#Person.UserDefined
You can also update custom fields even though the documentation does not currently list userDefined as a valid field for updatePersonFields as the field mask.
https://developers.google.com/people/api/rest/v1/people/updateContact

how to restrict price range in google shopping API

I'm using the Google Shopping API to try to retrieve products that have an "order" of magnitud of a certain number, or approximation to this. For example If I would to select products that are between th $40 - $60 price range : $50 +/- $10. What should I add in the URL search string?
I know I can rank by price like this (according to the API):
GET https://www.googleapis.com/shopping/search/v1/public/products?key=key&country=US&q=%22mp3+player%22%7Cipod&rankBy=price%3Adescending
Nevermind, the correct way to do this was using flask and jinja2 along with ajax. One has to be aware of using JSON and how it maps correctly to its equivalent python objects, when using the google shopping API main 'items' objects :
"product": {
"googleId": "9243781955569725518",
"author": {
"name": "CompUPlus.com",
"accountId": "1209120"
},
"creationTime": "2010-03-04T09:51:45.000Z",
"modificationTime": "2010-11-25T09:24:08.000Z",
"language": "en",
"country": "US",
"title": "Logitech Squeezebox Radio, black",
"description": "Logitech Squeezebox Radio brings a world of free Internet radio subscription
services and your personal digital music collection to any space in your home
over your Wi-Fi network.",
"link": "http://www.compuplus.com/Radios/LOGITECH-Squeezebox-Radio-BLK-930-1115160.html",
"gtin": "00097855063601",
"gtins": [
"00097855063601"
],
"brand": "Logitech",
"mpn": "930-000101",
"condition": "new",
"images": [
{ "link": "http://content.etilize.com/300/1014430207.jpg" }
]
"inventories": [
{
"channel": "online",
"availability": "inStock",
"currency": "usd",
"price": 183.19
}
],
}

Resources