Snipcart add item via JS API - snipcart

I'm building a very small e-commerce website for selling customizable jewels, so I have a graphical configurator that lets you design the jewel and then you can add it to the cart. The product should have a custom field in JSON format that contains the item configuration. I see that Snipcart has data-item-custom{x} fields, but is populated only with dropdowns... is not suitable for me.
Do you think I can handle this situation with Snipcart? Can I simply update via JS the HTML data-item- fields content? Or add the item to the cart via JS?
addToCart({
name: 'Bracelet 1',
customField1: 'JSON HERE'
})

There's a Javascript API available for Snipcart.
It does allow to add product dynamically, however, the syntax for custom fields is slightly different. The example from the doc for Snipcart.api.items.add show how to use custom fields (removed unused fields for brevity):
Snipcart.api.items.add({
"id": "SMARTPHONE",
"name": "Smartphone",
"url": "/",
"price": "399.00",
"customFields": [{
"name": "Memory size",
"options": "16GB|32GB[+50.00]",
"value": "32GB"
}]
});
So instead of the flattened version with customFieldX, you can pass an array to customFields. The dropdown format is only used if you pass an options. For your use case this would become:
Snipcart.api.items.add({
"id": "SMARTPHONE",
"name": "Smartphone",
"url": "/",
"price": "399.00",
"customFields": [{
"name": "configuration",
"value": "{\"option1\":\"value1\"}" //...
}]
});
However, custom fields are shown to the customer which would not be ideal to show them the raw json data. To pass hidden data you can instead use metadata which already expect a JSON object:
Snipcart.api.items.add({
"id": "SMARTPHONE",
"name": "Smartphone",
"url": "/",
"price": "399.00",
"customFields": [{
"metadata": {
"configuration": "configuration data"
}
});

Related

Microsoft Graph API - List all Users who have access to a mail item?

I want to be able to have a list of all users who can view a certain mail item. As an admin on the frontend on exchange online, I can view all my users mail, but when i call to the API I only return my mail. I want to be able to make calls to see exactly who has permission to view each mail item, and cannot find a way through the api.
I can get a list of all users, and a list of all mail for each user, a list of all mailboxes, a list of all groups, but not permissions on each mail item
GET /users/{id | userPrincipalName}/messages
returns all the mail, but mail items come with the following structure:
{
"bccRecipients": [{"#odata.type": "microsoft.graph.recipient"}],
"body": {"#odata.type": "microsoft.graph.itemBody"},
"bodyPreview": "string",
"categories": ["string"],
"ccRecipients": [{"#odata.type": "microsoft.graph.recipient"}],
"changeKey": "string",
"conversationId": "string",
"createdDateTime": "String (timestamp)",
"flag": {"#odata.type": "microsoft.graph.followupFlag"},
"from": {"#odata.type": "microsoft.graph.recipient"},
"hasAttachments": true,
"id": "string (identifier)",
"importance": "String",
"inferenceClassification": "String",
"internetMessageHeaders": [{"#odata.type": "microsoft.graph.internetMessageHeader"}],
"internetMessageId": "String",
"isDeliveryReceiptRequested": true,
"isDraft": true,
"isRead": true,
"isReadReceiptRequested": true,
"lastModifiedDateTime": "String (timestamp)",
"parentFolderId": "string",
"receivedDateTime": "String (timestamp)",
"replyTo": [{"#odata.type": "microsoft.graph.recipient"}],
"sender": {"#odata.type": "microsoft.graph.recipient"},
"sentDateTime": "String (timestamp)",
"subject": "string",
"toRecipients": [{"#odata.type": "microsoft.graph.recipient"}],
"uniqueBody": {"#odata.type": "microsoft.graph.itemBody"},
"webLink": "string",
"attachments": [{"#odata.type": "microsoft.graph.attachment"}],
"extensions": [{"#odata.type": "microsoft.graph.extension"}],
"multiValueExtendedProperties": [{"#odata.type": "microsoft.graph.multiValueLegacyExtendedProperty"}],
"singleValueExtendedProperties": [{"#odata.type": "microsoft.graph.singleValueLegacyExtendedProperty"}]
}
this doesnt contain anything about the full permissions on the item. Does anyone know of a way to get this?
You can't get item level permission as item doesn't store ACL associated with it. You can, however, get Folder level permission by querying PR_NT_SECURITY_DESCRIPTOR (0x0E270102) on the folder.
I actually wrote script for this based on my old REST API client engine: Start-MailboxFolderPermissionReport
I can, if script isn't enough, write C# way of doing it through Graph Managed API
There doesn't appear to be a way to expose mailbox or folder permissions through the Graph API. These are available through the Exchange Online PowerShell module e.g. Get-MailboxFolderPermission.

How does one parse nested Avro records correctly in NiFi?

I have incoming Avro records that roughly follow the format below. I am able to read them and convert them in existing NiFi flows. However, a recent change requires me to read from these files and parse the nested record, employers in this example. I read the Apache NiFi blog post, Record-Oriented Data with NiFi
but was unable to figure out how to get the AvroRecordReader to parse nested records.
{
"name": "recordFormatName",
"namespace": "nifi.examples",
"type": "record",
"fields": [
{ "name": "id", "type": "int" },
{ "name": "firstName", "type": "string" },
{ "name": "lastName", "type": "string" },
{ "name": "email", "type": "string" },
{ "name": "gender", "type": "string" },
{ "name": "employers",
"type": "record",
"fields": [
{"name": "company", "type": "string"},
{"name": "guid", "type": "string"},
{"name": "streetaddress", "type": "string"},
{"name": "city", "type": "string"}
]}
]
}
What I hope to achieve is a flow to read the employers records for each recordFormatName record and use the PutDatabaseRecord processor to keep track of the employers values seen. The current plan is to insert the records to a MySQL database. As suggested in an answer below, I plan on using PartitionRecord to sort the records based on a value in the employers subrecord. I do not need the top level details for this particular flow.
I have tried to parse with the AvroRecordReader but cannot figure out how to specify the nested records. Is this something that can be accomplished with the AvroRecordReader alone or does preprocessing, say a JOLT Transform need to happen first?
EDIT: Added further details about database after receiving a response.
What is your target DB and what does your target table look like? PutDatabaseRecord may not be able to handle nested records unless your DB, driver, and target table support them.
Alternatively you may need to use UpdateRecord to flatten the "employers" object into fields at the top level of the record. This is a manual process (until NIFI-4398 is implemented), but you only have 4 fields. After flattening the records, you could use PartitionRecord to get all records with a specific value for, say, employers.company. The outgoing flow files from PartitionRecord would technically constitute the distinct values for the partition field(s). I'm not sure what you're doing with the distinct values, but if you can elaborate I'd be happy to help.

How do I get a user reference in Microsoft Graph Groups API?

From the Group API and /Conversations endpoint you can get a list of conversations and when looking in the Groups App you can see the user with image.
But data returned from API doesn't have any good data to use for a user lookup.
I would expect an email address at least, not just the name which is far from unique. Is there a efficient way to get the user without traversing all the threads and posts?
Data from API:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#groups('{id}')/threads",
"value": [{
"id": "{id}",
"topic": "Test main thread",
"hasAttachments": false,
"lastDeliveredDateTime": "2017-10-20T11:35:04Z",
"uniqueSenders": [
"Jonas Stensved"
],
"preview": "{message preview content}",
"isLocked": false
},
{
"id": "{id}",
"topic": "The new Test group is ready",
"hasAttachments": false,
"lastDeliveredDateTime": "2017-10-13T10:33:03Z",
"uniqueSenders": [
"Test"
],
"preview": "{message preview content}",
"isLocked": false
}
]
}
How a group in the Groups app looks:
[]
It might help to break down the object hierarchy here:
Group - parent to a collection of Conversation resources
Conversation - parent to a collection of Thread resources
Thread - parent to to a collection of Post resources
Post - the actual content sent to the Group by a User
In order to see which User resources map into a given Thread, you need to drill down another level to find the Post resources contained within the Thread.
You can do this using the $expand=posts parameter to expand the Posts collection. You can also a ($select=from) the $expand so you only return the properties you need to map back to the User resource.
So this query:
/v1.0/groups/{group-id}/threads?$expand=posts($select=from)
will provide you a Thread result like this:
{
"id": "{thread-id}",
"topic": "New Training Plans",
"hasAttachments": false,
"lastDeliveredDateTime": "2017-07-31T18:59:05Z",
"uniqueSenders": [
"HR Taskforce"
],
"preview": "{thread-preview}",
"isLocked": false,
"posts#odata.context": "https://graph.microsoft.com/v1.0/$metadata#groups('{group-id}')/threads('{thread-id}')/posts(from)",
"posts": [{
"#odata.etag": "W/\"CwAAABYAAADE9kXbLjqkSJUGeLzs6eumAAAAAA0/\"",
"id": "{post-id}",
"changeKey": "CwAAABYAAADE9kXbLjqkSJUGeLzs6eumAAAAAA0/",
"from": {
"emailAddress": {
"name": "HR Taskforce",
"address": "HRTaskforce#M365x214355.onmicrosoft.com"
}
}
}]
}
You can try this yourself using this Graph Explorer example.
You can get group members list and iterate over them. Depending on the size o the group this might require paging. You can find more information in the docs: https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/resources/group
I hope this helps.

Error in Google SDTT: "All values provided for url must point to the same page."

I am trying to create some JSON-LD structured data for a list of products on an ecom-site but I am getting an error when using Google's Structured Data Testing Tool.
So far, I have this:
{
"#context": "http://schema.org",
"#type": "OfferCatalog",
"name": "Fresh Fruit",
"itemListElement": [
{
"#type": "ListItem",
"position": 1,
"item":
{
"#type": "Offer",
"price": "1.20",
"priceCurrency": "GBP",
"availability": "http://schema.org/InStock",
"url": "http://example.com/green-apples/",
"itemOffered": {
"#type": "Product",
"name": "Green Apples",
"url": "http://example.com/green-apples/"
}
}
}
]
}
Mostly it validates, but the Google tool throws the following error:
All values provided for url must point to the same page.
The error highlights line 11 ("#type": "Offer",).
The URL fields seem to be clashing with the #context declaration, because if I change the context to either a non-url string or http://example.com, it validates (although, this obviously causes its own issues). (This has been shown to be a red-herring, in the comments below)
What am I missing here? It feels like something blindingly obvious.
I think it is connected with pushing of accelerated mobile pages and its structured data.
Please check my thoughts here: All values provided for URL must point to the same page. My guess was about the problem in Google’s SDTT
So, to fix the problem with your structure data, please use the correct version of ItemList (there are Separately and Combined marked up ItemLists, please check here):
If your items are on the same page, please use the version with items
inside, the Combined one.
Otherwise, if you point to different pages inside and your items are
not on one page, please DON’T put item element with type and other
description inside, the Separately marked up one.
Now it's 2018.
Answer by Yash Pal above is close, but not quite right.
This is not an error from Google validator tools.
The error is valid and you need to fix it.
You use the "Single Page" approach ( there are two approaches "Summary page" and "Single page" )
For "Single Page" approach, you need each URL to be exactly same, and each of them should have "an anchor".
The Google developer doc clearly mentioned it.
I wrote the explanation details there
If your page contains some links to another page, then you should use "Summary Page" approach and it had different data structure ( much simpler one, I think )
I think the issues occurs when we mix two list types i.e Summary page + multiple full details pages and A single, all-in-one-page list.
Google stated on page - https://developers.google.com/search/docs/guides/mark-up-listings
If this is a summary page, the ListItem should include only the type,
position, and url properties.
If this is an all-in-one-page list, the ListItem should include all the additional schema.org properties for the data type that it describes (for example, Recipe or Course objects).
But Google should consider eCommerce category's product listing where people display numbers of product with more than 3 properties on summery page and these are obvious for eCommerce, like price and image are 2 important item on product listing page except the 3 listed above.
So we need to raise this issue with Google to address the concern.
No, it is NOT an error in Google's SDTT,
I have helped many people fix their structured data, including dynamic arrays. Read the instructions. Google clearly states "All values for the URL must point to the same page". Think about it, Google is trying to tell you something.
That something means this "Hey you are using a different item list from the example we provided, your item list has more than two item".
The solution:
Use anchors! Voila!
Please use this example snippet and you cannot go wrong. And another tip; use the Fetch Url option from SDTT:
<script type="application/ld+json">
/*structerd data markup compiled by http://www.iwanross.co.za */
{
"#context": "http://schema.org",
"#type": "ItemList",
"itemListElement": [
{
"#type": "ListItem",
"position": 1,
"item": {
"#type": "Recipe",
"url": "https://www.smokingchimney.com/#beetroot",
"name": "Beetroot Side Salad for the braai",
"image": "http://www.smokingchimney.com/recipe-pages/images/1x1/Beetroot-Salad-
for-the-Braai-800x451.jpg",
"author": {
"#type": "Person",
"name": "Marna Ross"
},
"datePublished": "2018-10-05"
}
},
{
"#type": "ListItem",
"position": 2,
"item": {
"#type": "Recipe",
"url": "https://www.smokingchimney.com/#carrot",
"name": "Carrot Cake",
"image": "http://www.smokingchimney.com/recipe-pages/images/16x9/carrot-cake-
recipe-picture-1024x576.jpg",
"author": {
"#type": "Person",
"name": "Marna Ross"
},
"datePublished": "2018-10-05"
}
},
{
"#type": "ListItem",
"position": 3,
"item": {
"#type" : "Recipe",
"url":"https://www.smokingchimney.com/#overnight",
"name": "Overnight Steak Marinade",
"image": "http://www.smokingchimney.com/recipe-pages/images/1x1/Overnight-steak-
marinade-700x465.png",
"author": {
"#type": "Person",
"name": "Marna Ross"
},
"datePublished": "2009-10-05"
}
}
]
}
</script>
It is surely an error in the validator. I checked with the examples google provided: https://developers.google.com/search/docs/guides/mark-up-listings .
If you click on the 2nd example you will see that it has the same error.
The error is shown even if you use 1 item:
{
"#context": "http://schema.org",
"#type": "ItemList",
"itemListElement": [
{
"#type": "ListItem",
"position": 1,
"item": {
"#type": "Recipe",
"url": "http://example.com/desserts/pies/#apple-pie",
"name": "Apple Pie",
"image": "https://example.com/300px-Apple_pie.jpg",
"author": {
"#type": "Person",
"name": "Carol Smith"
},
"datePublished": "2009-11-05"
}
}
]
}
you don't need to anchor every URL, you can add parameters to the URL as well ?i=1
like:
https://website.com/d/link?i=1
https://website.com/d/link?i=2
....
Use type OfferCatalog instead of ItemList. https://schema.org/OfferCatalog

Ruby on rails: Substring with quotes search inside JSON object

I have retrieved a json object using typhoeus gem.
url = 'www.example.com' <br>
request = ::Typhoeus::Request.get(url,userpwd: username + ":" + pass)<br>
content = JSON.parse(request.body)
I would like to count the occurence of "Priority":"high" including the quotes inside the json response. How do I go about doing this?
Edit:
"priority":"high" is a key value pair. It is deeply nested inside the json tree.(Don't how deeply it is nested). All I need is count of occurence of "priority":"high"
Any and all suggestion is welcome.
Sample data:
"tickets": [{
"url": "https://.zendesk.com/api/v2/tickets/xxxx.json",
"id": xxxxx,
"external_id": null,
"via": {
"channel": "email",
"source": {
"from": {
"address": "#compli.com",
"name": ""
},
"to": {
"name": "organization Global Support",
"address": "support#organization.zendesk.com"
},
"rel": null
}
},
"created_at": "2016-08-04T16:23:13Z",
"updated_at": "2016-08-08T20:26:01Z",
"type": "problem",
"subject": "Problems with abc Connect",
"raw_subject": "Problems with abc Connect",
"description": "Hi – our Tenet ID is 5675.\n\n \n\nThe abc report is not providing the full data when I run the billing preview. I am running it using Chrome. Attached are snapshots of what I’m doing plus the report generated.\n\n \n\nA perfect example of the problem is shown at the bottom of the report generated. Garber Automotive Group, account number A00000490 does not display the data for all of their products. Their data is shown on rows 5658 thru 5712 on the excel file BillingPreviewResult_201620 report run 08.04.16.\n\n \n\nHowever the EXACT same report (all the parameters are the same) run on 07/01/16 included all of Garber’s information. The excel file abc report run 07.01.16 10.13 AM has the data for Garber on rows 6099 – 6182.\n\n \n\nThe report is cutting off a lot of data for some reason. As you can see by comparing the amount of data between the two excel reports there are much fewer lines on the report run on today as opposed to the one run on 07/01, 6182 rows vs 5712 rows.\n\n \n\nThis is a business critical report for us. It is used for cash forecasting, monthly financial reporting, rolling budgeting and ad hoc reporting.\n\n \n\nWe need this problem identified and fixed immediately. It is already causing a problem with finalizing our July results.\n\n \n\nLet me know if you have any questions or need any additional data.\n\n \n\n \n\nRegards,\n\n \n\n \n\n \n\n| Controller\ndesk: 503.963-4239 | fax: 503.294.1200 | \n\nCompli - Cool, Calm and Compliant. TM\n\nVisit() to learn more.\n\n \n\nFollow us on LinkedIn () and Twitter",
"priority": "normal",
"status": "open",
"recipient": "support#organization.zendesk.com",
"requester_id": 1336424406,
"submitter_id": 1336424406,
"assignee_id": null,
"organization_id": 224504969,
"group_id": 21606503,
"collaborator_ids": [560973773, 786229209, 421597631, 539566717, 707192615, 1336424406, 31365392, 719608577, 1817633993],
"forum_topic_id": null,
"problem_id": null,
"has_incidents": false,
"due_at": null,
"tags": ["1_price", "best_practice_advise", "engage_global_services__email_", "escalate", "hard", "internal_escalation", "p0", "yes_escalated", "xxxxx", "zhub"],
"custom_fields": [{
"id": 22024091,
"value": "p0"
}, {
"id": 24212576,
"value": "best_practice_advise"
}, {
"id": 22035048,
"value": "xxx and so on.....

Resources