JSON feed object/array specify root name? - fullcalendar

I just discovered and I am very excited about this product... I've had some luck getting my calendar populated... however, I need some more info I cannot explicitly find in the documentation... How do I point to the root JSON object key name "events" if I return an object instead of an array?
If I return an object from SQL like shown here, the events will not be rendered:
{ "events": [ { "id": 434, "title": "Slot 434", "start": "2020-05-20T09:00:00", }, { "id": 435, "title": "Slot 435", "start": "2020-05-20T09:30:00", } ] }
However, if I return an object from SQL like this, they WILL render.
[ { "id": 434, "title": "Slot 434", "start": "2020-05-20T09:00:00", }, { "id": 435, "title": "Slot 435", "start": "2020-05-20T09:30:00", } ]
When using a JSON feed, how to I specify the object root name?
I should mention I am using the events url object:
events: {
url: '[OUR INTERNAL API AND MSSQL SERVER THING]',
method: 'POST',
// extraParams: {
// custom_param1: 'something',
// custom_param2: 'somethingelse'
// },
failure: function () {
alert('there was an error while fetching events!');
},
// color: 'yellow', // a non-ajax option
// textColor: 'black' // a non-ajax option
},

Related

Firestore structured query search by document id

I'm trying to query a firestore collection by document id but not using firestore CLI but rather a structured query (because I'm using Zapier to automate some workflows). Is there a way to search by documented as the field? So far I've tried the below code and variations where I replace name with "documentId()", "documentId" and nothing seems to work. When I use name I get the following error:
"error":
"code": 400,
"message": "key filter value must be a Key",
"status": "INVALID_ARGUMENT"
"where": {
"fieldFilter": {
"field": {
"fieldPath": "__name__"
},
"op": "EQUAL",
"value": {
"stringValue": "THE ID I WANT TO LOOK FOR"
}
}
}
If you want to get a document by id using __name__, change the value type to referenceValue and provide the full path to the document instead of just the id for the query.
"where": {
"fieldFilter": {
"field": {
"fieldPath": "__name__"
},
"op": "EQUAL",
"value": {
"referenceValue": "projects/project_id/databases/database_id/documents/your_collection/doc_id"
}
}
}
Assuming that you want to get a specific document using a document id. You may want to refer to the code below:
axios.get(`https://firestore.googleapis.com/v1/projects/<Project-ID>/databases/(default)/documents/<Collection-Name>/<Document-ID>`)
.then(res => {
console.log(res);
})
.catch(error => {
console.log(error);
});
The code above will get a specific document that you want. If you want to get a document ID with a specific value of its field, then this line here: "fieldPath": "__name__" should be a fieldName not a document id. "fieldPath": "<FieldName>". and also, make sure the method you're using is POST. See code sample below for reference:
axios.post(`https://firestore.googleapis.com/v1/projects/<Project-ID>/databases/(default)/documents:runQuery`,
{
"structuredQuery": {
"from": [{
"collectionId": "<Collection-Name>"
}],
"where": {
"fieldFilter": {
"field": {
"fieldPath": "<FieldName>"
},
"op": "EQUAL",
"value": {
stringValue: "<FieldValue>"
}
}
}
}
}).then(res => {
console.log(res)
})
.catch(error => {
console.log(error)
})
All the codes above are for reference only which I used axios for fetching the data from Firestore.
For more information, checkout this documentation.

Logic App workflow creating or updating documents in CosmosDB fails with conflict

I'm in the process of creating a Logic App which should copy all documents from specific containers in the database to a different database and its corresponding collections.
For this, I've created a workflow which retrieves all documents, loops through them and tries to do a Create or Update document on the target location.
As you can see on the image, this looks fairly straightforward.
I've specified the PartitionKey in the header and Upsert is set to true, so if a document already exists it'll be updated, otherwise created.
Originally, the body was filled with #items('[blurred]_-_For_each_document').
However, I got an error stating there was a conflict on the id.
I've also tried to remove all 'system' properties like so:
#removeProperty(removeProperty(removeProperty(removeProperty(removeProperty(items('[blurred]_-_For_each_document'), 'id'), '_rid'), '_self'), '_ts'), '_etag')
but it appears not having an id in place isn't valid, so now I've got this as I'm only interested in having the contents of the 'actual' document:
#removeProperty(removeProperty(removeProperty(removeProperty(items('[blurred]_-_For_each_document'), '_rid'), '_self'), '_ts'), '_etag')
This still fails.
The raw input looks a bit like this:
{
"method": "post",
"headers": {
"x-ms-documentdb-raw-partitionkey": "1050",
"x-ms-documentdb-is-upsert": "True"
},
"path": "/dbs/[myDatabase]/colls/[myCollection]/docs",
"host": {
"connection": {
"name": "/subscriptions/[subscriptionGuid]/resourceGroups/[resourcegroup]/providers/Microsoft.Web/connections/[connectionName]"
}
},
"body": {
"id": "2faee185-4a51-4797-bff9-3ce23a603690",
"MyPartitionKeyNumber": 1050,
"SomeValue": false,
}
}
With the following response:
{
"code": "Conflict",
"message": "Entity with the specified id already exists in the system., ... ResourceType: Document, OperationType: Upsert ..."
}
I know for a fact, the id doesn't exist, but changed the step to do a PUT anyway.
{
"method": "put",
"headers": {
"x-ms-documentdb-raw-partitionkey": "1050",
"x-ms-documentdb-is-upsert": "True"
},
"path": "/dbs/[myDatabase]/colls/[myCollection]/docs",
"host": {
"connection": {
"name": "/subscriptions/[subscriptionGuid]/resourceGroups/[resourcegroup]/providers/Microsoft.Web/connections/[connectionName]"
}
},
"body": {
"id": "2faee185-4a51-4797-bff9-3ce23a603690",
"MyPartitionKeyNumber": 1050,
"SomeValue": false,
}
}
With a response I'm expecting to see:
{
"statusCode": 404,
"message": "Resource not found"
}
I've also tried to do a Delete document before running the Create or Update document step, but got the same error(s).
There's some post here on Stack Overflow stating the x-ms-documentdb-raw-partitionkey should be x-ms-documentdb-partitionkey (without the raw-part), but doing so results in the following error message:
PartitionKey extracted from document doesn't match the one specified in the header
For completeness sake, these are the relevant steps of my workflow:
"[blurred]_-_Get_all_documents": {
"type": "ApiConnection",
"inputs": {
"host": {
"connection": {
"name": "#parameters('$connections')['documentdb_3']['connectionId']"
}
},
"method": "get",
"path": "/v2/dbs/#{encodeURIComponent('myDatabase')}/colls/#{encodeURIComponent(items('[blurred]_-_For_each_collection'))}/docs"
},
"runAfter": {}
},
"[blurred]_-_For_each_document": {
"type": "Foreach",
"foreach": "#body('[blurred]_-_Get_all_documents')?['value']",
"actions": {
"[blurred]_-_Create_or_Update_document_on_blurred2": {
"type": "ApiConnection",
"inputs": {
"host": {
"connection": {
"name": "#parameters('$connections')['documentdb_4']['connectionId']"
}
},
"method": "post",
"body": "#removeProperty(removeProperty(removeProperty(removeProperty(items('[blurred]_-_For_each_document'), '_rid'), '_self'), '_ts'), '_etag')",
"headers": {
"x-ms-documentdb-raw-partitionkey": "#{items('[blurred]_-_For_each_document')['MyPartitionKeyNumber']}",
"x-ms-documentdb-is-upsert": true
},
"path": "/dbs/#{encodeURIComponent('myDatabase')}/colls/#{encodeURIComponent(items('[blurred]_-_For_each_collection'))}/docs"
},
"runAfter": {}
}
},
"runAfter": {
"[blurred]_-_Get_all_documents": [
"Succeeded"
]
}
}

How to decode this json in Firebase realtime Database?

void readData() {
databaseReference
.child("data")
.child("chapters")
.once()
.then((DataSnapshot snapshot) {
print('Data : ${snapshot.value}');
});
This is my read data function and I got the following JSON output.
[
{
"name": "Global Village",
"videolists": [
{
"title": "Binary to decimal",
"link": "http://..........",
"duration": "5:3"
},
{
"title": "Binary to decimal",
"link": "http://..........",
"duration": "5:3"
}
]
},
{
"name": "Data Communication and Networking",
"videolists": [
{
"title": "Binary to decimal",
"link": "http://..........",
"duration": "5:3"
},
{
"title": "Binary to decimal",
"link": "http://..........",
"duration": "5:3"
}
]
}
]
I have tried to decode the JSON using this code
var lists= json.decode(snapshot.value) as List<dynamic>;
But I got an error like this
Unhandled Exception: type 'List' is not a subtype of type
'String'
How can I decode the JSON?
You can try the following:
Iterable lists = json.decode(result);
List<dynamic> map = lists.toList();
map.forEach((res){
print(res["videolists"][0]);
});
json.decode() takes a String and returns a dynamic, therefore we can assign it to class Iterable and then we can use toList() to create a list and iterate using forEach(). The above should give you:
{title: Binary to decimal, link: http://.........., duration: 5:3}
{title: Binary to decimal, link: http://.........., duration: 5:3}

Alexa: The requested skill did not provide a valid response on LauchRequest

I have started Alexa development very recently. Today I have suddenly started getting
which I did not encounter before.
The lambda function (index.js):
"use strict";
const Alexa = require("ask-sdk-core");
const http = require("http");
exports.handler = async (event, context, callback) => {
try {
if (event.request.type === "LaunchRequest") {
var welcomeMessage = '<speak>Hi</speak>';
callback(null, buildResponse(welcomeMessage, false));
}
else if (event.request.type === "AMAZON.CancelIntent") {
var msg2 = "<speak>Stopped!</speak>";
callback(null, buildResponse(msg2, true));
}
} catch (e) {
context.fail("Exception: ${e}");
}
};
function buildResponse(response, shouldEndSession) {
return {
version: "1.0",
response: {
outputSpeech: {
type: "SSML",
ssml: response
},
shouldEndSession: shouldEndSession
},
sessionAttributes: {}
};
}
package.json file:
{
"name": "third-test-skill",
"version": "1.0.0",
"description": "...",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Subrata Sarkar",
"license": "ISC",
"dependencies": {
"ask-sdk-core": "^2.5.2",
"ask-sdk-model": "^1.15.1"
}
}
Steps I followed to create the skill:
Crated a skill from AWS Alexa console
Created skill
Added sample utterances
Selected Lamda as end point Created a function called movieFacts
Uploaded .zip file containing the following file structure.
node_modules
|- ask-sdk-core
|- ask-sdk-model
|- ask-sdk-runtime
index.js
package.json
package.json.lock
When I say movie facts, I am getting the following message:
The requested skill did not provide a valid response
And this is the JSON output I am receiving:
{
"version": "1.0",
"session": {
"new": false,
"sessionId": "amzn1.echo-api.session.beca8832-50fe-4d17-96a4-30c855b18a4f",
"application": {
"applicationId": "amzn1.ask.skill.bdb88b1b-5a4a-4b37-9b63-71e78337bbca"
},
"user": {
"userId": "amzn1.ask.account.AEG2YALM6KQANVKR3YSUWKVN5DCKE66NJKN23SZIKRKZCVTU67E2JBZ5STPFIN325WNGGO5Z73FMVVL5X2SVEM27YEPD5VFNMPVDQSQK5XYW3NXOXSEIK6YPHE5HTZLGLCWW4VVQHLYECL6YBLG4XOTM2HTV5VCCQMPLVCIATFRSNS4DLHJFLY32JHD5N5MAPFBNRVN3YV7B53A"
}
},
"context": {
"System": {
"application": {
"applicationId": "amzn1.ask.skill.bdb88b1b-5a4a-4b37-9b63-71e78337bbca"
},
"user": {
"userId": "amzn1.ask.account.AEG2YALM6KQANVKR3YSUWKVN5DCKE66NJKN23SZIKRKZCVTU67E2JBZ5STPFIN325WNGGO5Z73FMVVL5X2SVEM27YEPD5VFNMPVDQSQK5XYW3NXOXSEIK6YPHE5HTZLGLCWW4VVQHLYECL6YBLG4XOTM2HTV5VCCQMPLVCIATFRSNS4DLHJFLY32JHD5N5MAPFBNRVN3YV7B53A"
},
"device": {
"deviceId": "amzn1.ask.device.AFXLD474IMHMD5V35NT2ZNUD5YLK2LTEJZUMO6DS2MY7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RGUlNOUzRETEhKRkxZMzJKSEQ1TjVNQVBGQk5SVk4zWVY3QjUzQSJ9fQ.UyCg4MXlOe16SlOyJnjAIiHzVpdLkRjd-izoKkUnGqiyZ0L_5eUpg8tKvVrCvTLNMtJS6ElksxgVfuLcNeOIwSbXtYCOXcSLRYbpcpgFI6oeamOZ2Yo-UMDEjzYi75fABuJyUJyZxp-Pieer8PMZO4G9-5zJXCVY2x3M_dmlpX23UBJDpW0DKddvAOzConmwgdaf3v_EWfc2q8BaCQIM950rEUbejOa08_AwE5CsqjNA9sD22QduE5hs09RV4-F-kU1zKvwwyDVDKyOkdFZQFEmCTC11_jI64re9c22e-hYR4leIE5XntNApMgtwaL-tHyjsJzVDVDfZd2q3w6wxYA"
},
"Viewport": {
"experiences": [
{
"arcMinuteWidth": 246,
"arcMinuteHeight": 144,
"canRotate": false,
"canResize": false
}
],
"shape": "RECTANGLE",
"pixelWidth": 1024,
"pixelHeight": 600,
"dpi": 160,
"currentPixelWidth": 1024,
"currentPixelHeight": 600,
"touch": [
"SINGLE"
],
"video": {
"codecs": [
"H_264_42",
"H_264_41"
]
}
}
},
"request": {
"type": "SessionEndedRequest",
"requestId": "amzn1.echo-api.request.c7b1b910-6309-48aa-af35-10ac0a20b5da",
"timestamp": "2019-05-07T14:55:10Z",
"locale": "en-US",
"reason": "ERROR",
"error": {
"type": "INVALID_RESPONSE",
"message": "An exception occurred while dispatching the request to the skill."
}
}
}
I think removing the <speak> and </speak> tags around the welcome message should do. They are by default generated by Alexa, so you don't need to provide them in your response.
What happened in my case (and definitely worth to check) is that I was using Serverless Framework to deploy Lambda and I changed the configuration in the serverless.yml but forgot to update the Lambda ARN in the Alexa Endpoint.
Updating the Endpoint to the correct ARN and rebuilding solved the issue.

Google Tag Manager - Python - Creating a custom event trigger

I am trying to automate some GTM tasks. The below code to create a "All Pages" trigger for Google Analytics works.
def CreateGATrigger(service, workspace):
"""Create the GA Trigger.
Args:
service: the Tag Manager service object.
workspace: the workspace to create the trigger within.
Returns:
The created trigger.
"""
GA_trigger = {
'name': 'All Pages',
'type': 'PAGEVIEW'
}
return service.accounts().containers().workspaces().triggers().create(
parent=workspace['path'],
body=GA_trigger).execute()
However, the below code gives me the below error. The goal of the below code is to create a custom event trigger that fires when the event variable contains "formSubmit".
def CreateformSubmitTrigger(service, workspace):
formSubmit_trigger = {
"name": 'formSubmit',
"type": 'customEvent',
'customEventFilter': [
{
'parameter': [
{
'type': 'template',
'key': 'arg0',
'value': '{{event}}'
},
{
'type': 'template',
'key': 'arg1',
'value': 'formSubmit'
}
],
'type': 'contains'
}
]
}
return service.accounts().containers().workspaces().triggers().create(
parent=workspace['path'],
body=formSubmit_trigger).execute()
Error: ( X'd out the account and container )
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/tagmanager/v2/accounts/XXXXXXXXXX/containers/XXXXXXX/workspaces/1/triggers?alt=json returned "Bad Request">
I got this to work using the below code.
def CreateformSubmitTrigger(service, workspace):
formSubmit_trigger = {
"name": "formSubmit",
"type": "customEvent",
"customEventFilter": [
{
"type": "equals",
"parameter": [
{
"type": "template",
"key": "arg0",
"value": "{{_event}}"
},
{
"type": "template",
"key": "arg1",
"value": "formSubmit"
}
]
}
],
"filter": [
{
"type": "contains",
"parameter": [
{
"type": "template",
"key": "arg0",
"value": "{{Event}}"
},
{
"type": "template",
"key": "arg1",
"value": "formSubmit"
}
]
}
],
}
return service.accounts().containers().workspaces().triggers().create(
parent=workspace['path'],
body=formSubmit_trigger).execute()

Resources