In AEM, I want to add <sly></sly> tags inside a <script></script> tag. Multifield option inside a schema - seo

So I am building a multifield authoring option. Publishers can add values and and create more text fields if they need to. But the issue is that adding <sly> tags inside a <script> tag is giving me issues. For example:
<sly data-sly-use.FAQschemaObject="${'../../../clientlibs/clientlib-base/js/collection/multi-collection.js' # resourcePath = resource.path , multifieldName='FAQschemas'}"> </sly>
<script type="application/ld+json">
<sly data-sly-list.FAQschema="${FAQschemaObject}" data-sly-unwrap>
{
"#context": "https://schema.org",
"#type": "FAQPage",
"mainEntity": [{
"#type": "Question",
"name": "${FAQschema.properties.question # context = "html"}",
"acceptedAnswer": {
"#type": "Answer",
"text": "${FAQschema.properties.answer # context = "html"}"
}
}]
}
</script>
</sly>
So as you see, I would like to show this script only when there is values being filled in. And also giving author the option to add more Question and Answers values if they want to. I am tryng to implement and FAQ schema provided by google. https://developers.google.com/search/docs/data-types/faqpage
Therefore, I would like to implement something like googles example:
<script type="application/ld+json">
{
"#context": "https://schema.org",
"#type": "FAQPage",
"mainEntity": [{
"#type": "Question",
"name": "What is the return policy?",
"acceptedAnswer": {
"#type": "Answer",
"text": "Most unopened items in new condition and returned within <strong>90 days</strong> will receive a refund or exchange. Some items have a modified return policy noted on the receipt or packing slip. Items that are opened or damaged or do not have a receipt may be denied a refund or exchange. Items purchased online or in-store may be returned to any store.<br /><p>Online purchases may be returned via a major parcel carrier. <a href=http://example.com/returns> Click here </a> to initiate a return.</p>"
}
}, {
"#type": "Question",
"name": "How long does it take to process a refund?",
"acceptedAnswer": {
"#type": "Answer",
"text": "We will reimburse you for returned items in the same way you paid for them. For example, any amounts deducted from a gift card will be credited back to a gift card. For returns by mail, once we receive your return, we will process it within 4–5 business days. It may take up to 7 days after we process the return to reflect in your account, depending on your financial institution's processing time."
}
}, {
"#type": "Question",
"name": "What is the policy for late/non-delivery of items ordered online?",
"acceptedAnswer": {
"#type": "Answer",
"text": "Our local teams work diligently to make sure that your order arrives on time, within our normaldelivery hours of 9AM to 8PM in the recipient's time zone. During busy holiday periods like Christmas, Valentine's and Mother's Day, we may extend our delivery hours before 9AM and after 8PM to ensure that all gifts are delivered on time. If for any reason your gift does not arrive on time, our dedicated Customer Service agents will do everything they can to help successfully resolve your issue. <br/> <p><a href=https://example.com/orders/>Click here</a> to complete the form with your order-related question(s).</p>"
}
}, {
"#type": "Question",
"name": "When will my credit card be charged?",
"acceptedAnswer": {
"#type": "Answer",
"text": "We'll attempt to securely charge your credit card at the point of purchase online. If there's a problem, you'll be notified on the spot and prompted to use another card. Once we receive verification of sufficient funds, your payment will be completed and transferred securely to us. Your account will be charged in 24 to 48 hours."
}
}, {
"#type": "Question",
"name": "Will I be charged sales tax for online orders?",
"acceptedAnswer": {
"#type": "Answer",
"text":"Local and State sales tax will be collected if your recipient's mailing address is in: <ul><li>Arizona</li><li>California</li><li>Colorado</li></ul>"}
}]
}
</script>
Authors can create new fields by adding new values, but keeping the following structure. Any working examples?

A workaround to deal with this is to put all of the code that you need to be within the script tag into an HTML file of its own and include it on the script tag. With that, it should get picked up fine.
<script data-sly-include='read-multifield-partial.html'></script>
or
Create this JSON in a Sling model or Use JS and just dump it in sightly instead of looping over in sightly and building it.

Related

How to know the Shopify username who triggered a webhook?

I have a product/update Shopify webhook. When the webhook event comes, I see the JSON payload but I don't get any clue about who updated the product. I need the username or email or whatever to identify the user who triggered the webhook. Is that even possible ? If yes, how ?
As per Shopify Documentation, product/update hook does not contain any information regarding the user who triggered the action. However, if it is extremely important for you to find out the user, a workaround is to use the Shopify Events API. As you already have the Product ID in the recieved webhook, you may issue another call to
GET /admin/products/#{product_id}/events.json
and in the response
{
"events": [
{
"id": 677313116,
"subject_id": 921728736,
"created_at": "2008-01-10T08:00:00-05:00",
"subject_type": "Product",
"verb": "create",
"arguments": [
"IPod Touch 8GB"
],
"body": null,
"message": "Product was created: IPod Touch 8GB.",
"author": "Shopify",
"description": "Product was created: IPod Touch 8GB.",
"path": "/admin/products/921728736"
}
]
}
you will have the author field. You may further filter the result using verb and created_at fields.
The supported events are
But I am also only able to get the created, published and unpublished events.

Social Tables API: Event field values for Industry and Type are lost in browser UI

I create an event using the POST /4.0/legacyvm3/teams/{team}/events function with the following data:
{
"name": "My Event",
"category": "event",
"type": "Conference",
"industry": "Corporate",
"start_time": "2017-05-10T10:00:00.000Z",
"end_time" : "2017-05-10T11:00:00.000Z",
"spaces": [
{
"name": "My Room"
}
]
}
and get the following response:
{"id":2474582,"user_id":138947,"team_id":"49992","name":"My Event","category":"event","venue_mapper_version":2,"start_time":"2017-05-10T10:00:00.000Z","end_time":"2017-05-10T11:00:00.000Z","uses_metric":false,"public":false,"attendee_management":true,"spaces":[{"id":4696516,"name":"My Room","event_id":2474582,"space_order":0}]}
All good. But when editing the event in my browser using the URL:
https://app.socialtables.com/?event=2474582
I am prompted to select a value for Industry and Type. Also, the start and end times are both appear as 11:00. Why is this?
Start and end times look correct given that our API assumes you're using UTC (I see 6 and 7am EDT) when I open your event. It also was 10 and 11 in the response you posted.
Probably more importantly, you're using our legacy API and are therefore being pushed to our legacy product. There is a 4.0/events endpoint available to use. If you're writing your integration now I strongly recommend using these endpoints: https://developer.socialtables.com/api-console#!/Events/post_4_0_events

Square REST API: Error issuing refund

Every time I try to refund a card, I get the JSON pasted below. This happens after I authorize a card, then capture the charge, then want to issue a partial refund. For “tender_id” I have tried both the transaction ID and the ID I am handed during the authorization. Of course for the capture there is no tender_id or id because a successful capture returns just “{}”.
I am also using sandbox credentials. The charge was done with a nonce generated with sandbox credentials as well.
What’s wrong?
Thanks...
POST to:
https://connect.squareup.com/v2/locations/CBASEHHNorL75TjuSOAvKQLnuNYgAQ/transactions/a2905f34-c8e8-5534-7676-82e8c580e9bf/refund
With this JSON:
{
"idempotency_key":"6464dc19-1703-47c0-81f9-4f0f1361eada",
"tender_id":"291d56b3-1e73-5bff-6e8e-719fd134b83f",
"reason":”Partial refund",
"amount_money":{
"amount":4500,
"currency":"USD"
}
}
Gives this reply:
{
"errors": [
{
"category": "INVALID_REQUEST_ERROR",
"code": "NOT_FOUND",
"detail": "Location `CBASEHHNorL75TjuSOAvKQLnuNYgAQ` does not have a transaction tender with ID `291d56b3-1e73-5bff-6e8e-719fd134b83f`."
}
]
}
UPDATE: The result from the requested GET call (in the comments to the answer) is:
{
"transaction":{
"id":"a2905f34-c8e8-5534-7676-82e8c580e9bf",
"location_id":"CBASEHHNorL75TjuSOAvKQLnuNYgAQ",
"created_at":"2017-02-21T22:08:10Z",
"tenders":[
{
"id":"a18b98c7-5ac7-51c1-618c-3b95ee124c1b",
"location_id":"CBASEHHNorL75TjuSOAvKQLnuNYgAQ",
"transaction_id":"a2905f34-c8e8-5534-7676-82e8c580e9bf",
"created_at":"2017-02-21T22:08:10Z",
"note":"Online Transaction",
"amount_money":{
"amount":12500,
"currency":"USD"
},
"processing_fee_money":{
"amount":372,
"currency":"USD"
},
"type":"CARD",
"card_details":{
"status":"CAPTURED",
"card":{
"card_brand":"VISA",
"last_4":"5858"
},
"entry_method":"KEYED"
}
}
],
"reference_id":"63614ae8-539a-4339-b5c7-554bae64fbed",
"product":"EXTERNAL_API"
}
}
After you capture, have you tried listing/retrieving the transaction to get the full details, including tender ids? Could you post your response from GET /v2/locations/CBASEHHNorL75TjuSOAvKQLnuNYgAQ/transactions/a2905f34-c8e8-5534-7676-82e8c580e9bf if that doesn't work?

How to replace session with stateless rest apis?

So, I am trying to make a shopping cart web architecture on rest framework where I am struggling to use browser storages to use as an alternative to maintaining the state.
I tried the window.localStorage and window.sessionStorage() APIs but it failed in the case of the private browsing mode in Safari and Opera.
So can anyone help out in the figuring other methods by which I can maintain states in rest based architecture?
You don't need sessions to store application state. User resources.
On approach would be to model every shopping cart as a resource with a unique ID:
/shop/shoppingcarts/E73AC56C-BDF7-11E5-81F1-8E2EDB915C80
The client application in the browser would read this resource:
GET /shop/shoppingcarts/E73AC56C-BDF7-11E5-81F1-8E2EDB915C80
It would add an item to the cart:
POST /shop/shoppingcarts/E73AC56C-BDF7-11E5-81F1-8E2EDB915C80/items
{
"itemId": "1234",
"quantity": 1
}
It would list the contents of the shopping cart:
GET /shop/shoppingcarts/E73AC56C-BDF7-11E5-81F1-8E2EDB915C80/items
[
{
"itemId": "1234",
"title": "Some nice item",
"quantity": 1,
"price", 12.34,
"priceTotal": 12.34
},
{
"itemId": "9876",
"title": "Some other nice item",
"quantity": 2,
"price", 0.99,
"priceTotal": 1.98
}
]
The web application would remove an item from the cart:
DELETE /shop/shoppingcarts/E73AC56C-BDF7-11E5-81F1-8E2EDB915C80/items/9876
I think you get the idea.

REST pattern create, update and delete same endpoint

I have a page where I list the books of a school. The user can update a book, add a new book or delete an existing book. All actions must be saved when the form is submitted.
How can i map a rest API for that? I could take advantage of the endpoints i already have.
UPDATE
PUT /schools/1/books
{
"books": [
{
"id": "1",
"name": "Book 1"
}
]
}
CREATE
POST /schools/1/books
{
"books": [
{
"name": "Book 2"
},
{
"name": "Book 3"
}
]
}
DELETE
DELETE /schools/1/books
{
"books": [
{
"id": 2
}
]
}
But I need everything to run on the same transaction, and wouldn't make sense to submit 3 requests.
I also thought of creating a new endpoint where I would create books that doesn't exists, update books that exists, and remove books that are not present on the request.
So if this school has Book 1 and Book 2, I could update Book 1, create New Book and remove Book 2 with:
PUT /schools/1/batch-books
{
"books": [
{
"id": "1",
"name": "Updated Book 1"
},
{
"name": "New Book"
}
]
}
Do you guys have other options?
I would separate things into different resources:
/books and /books/{id} for books. They gives book details and allow to manage them.
/schools and /schools/{id} for schools. They gives school details and allow to manage them.
/schools/{id}/books to associate books in schools. I mean books that are available within a school. This resource provides methods to manage a list of links to books.
Let me detail the last resource. In fact, this is related to hypermedia. In the following, I'll use JSON-LD but you're free to use other hypermedia tools.
A GET method will return the list of associated books:
GET /schools/1/books
[
{
"#id": "http://api.example.com/books/1895638109"
},
{
"#id": "http://api.example.com/books/8371023509"
}
]
You can notice that you can implement mechanisms to allow to get more details if needed. Leveraging the Prefer header seems to be a great approach (see the link below for more details).
In addition, you could provide the following methods:
POST to add a link to the school. The request payload would be: {"#id": "http://api.example.com/books/1895638109"}. The response should be a 201 status code.
DELETE to delete a specific link from a school. A query parameter could be used to specify which link to remove.
PATCH to allow to do several operations in one call and actually provide some batch processing. You can leverage at this level JSON-PATCH for the request processing. Within the response, you could describe what happens. There is no specification at this level so you're free to use what you want... Here is a sample for the request payload:
PATCH /schools/1/books/
[
{
"op": "add", "value": "http://api.example.com/books/1895638109"
},
{
"op": "remove", "path": "http://api.example.com/books/8371023509"
}
]
Reading the following links could give you some hints on the way to design such use case:
Implementing bulk updates within RESTful services: http://restlet.com/blog/2015/05/18/implementing-bulk-updates-within-restful-services/
On choosing a hypermedia type: http://sookocheff.com/post/api/on-choosing-a-hypermedia-format/
Creating Client-Optimized Resource Representations in APIs: http://www.freshblurbs.com/blog/2015/06/25/api-representations-prefer.html
Hope it helps you,
Thierry