PouchDB not able to insert multiple json files - storage
I am trying to store 3 different JSON Object's using PouchDB,
devices.json:
[
{"id":"001","name":"iPhone","brand":"Apple","tags":["Apple","IOS"],"os":"IOS","Description":"...."},
{"id":"002","name":"galaxy","brand":"Samsung","tags":["Samsung","android"],"os":"android","Description":"...."},
{"id":"003","name":"nexus","brand":"Google","tags":["Google","android"],"Description":"...."},
{"id":"004","name":"galaxy
s4","brand":"Samsung","tags":["Samsung","android"],"os":"android","Description":"...."}
]
brand.json:
[
{ "id": "001", "name": "Apple" },
{ "id": "002", "name": "Samsung" },
{ "id": "003", "name": "Google" } ]
And tags.json as
[
{ "id": "001", "name": "Apple" },
{ "id": "002", "name": "Samsung" },
{ "id": "003", "name": "Google" },
{ "id": "004", "name": "IOS" },
{ "id": "005", "name": "android" } ]
Here when i am inserting using db.bulkDocs() devices.json it's creating 7 tables in one database. Now am trying the same function to insert brands.json & tags.json. But its not able to insert to database.
My javascript code is
var db = new PouchDB('dev');
var toinsert = ["devices","brands","tags"];
toinsert.forEach(function(json){
insert(json);
})
function insert(json){
var param2 = {
url: json + '.json',
dataType: 'json',
cache: false,
type: 'GET'
};
$.ajax(param2)
.done(function(data){
db.bulkDocs(data).then(function (result) {
console.log('Row inserted Successfully');
}).catch(function (err) {
console.log('Unable to insert into DB. Error: ' + err.name + ' - ' + err.message);
});
});
}
Here when i am checking indexedDB i am getting only devices.json data, Others are missing. Here I am not sure weather PouchDB can insert multiple json files or not? If it's Possible using PouchDB, Please helm me to get it.
It seems that the second and third objects are not a valid json object. This could be the issue, check http://jsonlint.com/ to validate your json objects.
Related
How fetch "webParts" from site pages
I am trying to fetch Pages from Sharepoint sites using graph API. But when we make GET request with https://graph.microsoft.com/beta/sites/{site-id}/pages/{page-id} the response consists of webParts which only have type and data. Inside data we have an id(which same as type) and an instanceId that is unique for every webPart. Sample webPart: { "type": "d1d91016-032f-456d-98a4-721247c305e8", "data": { "id": "d1d91016-032f-456d-98a4-721247c305e8", "instanceId": "c54a74ef-86c1-44aa-9ba4-802e6841e3a7" } My goal is to fetch webPages with complete details and then backup them to a local drive in any format. The documentation of graph API shows that the responce would consist of complete details for the webPart, but it is not so. Documentation link: https://learn.microsoft.com/en-us/graph/api/sitepage-get?view=graph-rest-beta&tabs=http Sample request URL: https://graph.microsoft.com/beta/sites/m365x214355.sharepoint.com,c1e5444e-12d8-43d3-96b1-f2f66559ef58,b181bdf0-9680-4988-81f7-a24aee4afd6a/pages Webpart repsonse: "webParts": [ { "type": "rte", "data": { "innerHTML": "<p>Take a look at the team behind delivering amazing fashion events for Contoso.</p><p>Find out how the team uses the latest technology to plan amazing fashion shows and gather customer feedback for future events.</p><p>Meet the people behind Contoso's events, learn how to plan your own event, and find the necessary resources to run highly successful fashion shows, premiers, and extravaganzas!</p>" } }, { "type": "d1d91016-032f-456d-98a4-721247c305e8", "data": { "id": "d1d91016-032f-456d-98a4-721247c305e8", "instanceId": "c54a74ef-86c1-44aa-9ba4-802e6841e3a7" } }, { "type": "b7dd04e1-19ce-4b24-9132-b60a1c2b910d", "data": { "id": "b7dd04e1-19ce-4b24-9132-b60a1c2b910d", "instanceId": "75ccfeba-ad6c-416d-a859-4a6b114e156e" } }, { "type": "b7dd04e1-19ce-4b24-9132-b60a1c2b910d", "data": { "id": "b7dd04e1-19ce-4b24-9132-b60a1c2b910d", "instanceId": "f04e02fb-45e6-4e74-9f46-0c8d90e7fb8d" } }, { "type": "275c0095-a77e-4f6d-a2a0-6a7626911518", "data": { "id": "275c0095-a77e-4f6d-a2a0-6a7626911518", "instanceId": "c1a222b0-624e-4e30-b544-d2a67e8e1112" } } Expected Response format: "webParts": [ { "type": "rte", "data": { "innerHTML": "<p>Here are the team's upcoming events:</p>" } }, { "type": "d1d91016-032f-456d-98a4-721247c305e8", "data": { "title": "Events", "description": "Display upcoming events", "serverProcessedContent": { "htmlStrings": {}, "searchablePlainTexts": { "title": "" }, "imageSources": {}, "links": { "baseUrl": "https://www.contoso.com/sites/Engineering" }, "componentDependencies": { "layoutComponentId": "8ac0c53c-e8d0-4e3e-87d0-7449eb0d4027" } }, "dataVersion": "1.0", "properties": { "selectedListId": "032e08ab-89b0-4d8f-bc10-73094233615c", "selectedCategory": "", "dateRangeOption": 0, "startDate": "", "endDate": "", "isOnSeeAllPage": false, "layoutId": "FilmStrip", "dataProviderId": "Event", "webId": "0764c419-1ecc-4126-ba32-0c25ae0fffe8", "siteId": "6b4ffc7a-cfc2-4a76-903a-1cc3686dee23" } } } ] I want webParts in the format as per documentation. If the instanceId is unique then there might be some reference table to match these instanceIds and fetch the detailed webParts structure.
How to post special characters to Amazon SQS using WSO2
we are trying to post json data to Amazon SQS which has special characters. But we are receiving exception while inserting data stating json is malformed. Following is the payload we have tested. [{ "ns2:Operation": { "core": { "system": "Local", "parameters": [{ "name": "name", "value": "qwerty" }, { "name": "operation", "value": "test" }, ], "actionDate": "11/12/2018", }, "ns2:action": "TESTING", "#xmlns:ns2": "http://test-app/testwebservice", "#xmlns": "http://test-app/testwebservice", } }]
Webhook input not available in scripting step?
I have an internal app that uses a webhook listener and some scripting to manipulate the input data. I'm posting this to it: curl -X POST -d '{ "assignment_id": 12345, "updated_custom_fields": [{ "name": "RNVIDAYEBB", "value": "updated!" }, { "name": "QUFTXSIBYA", "value": "and me too" } ], "custom_fields": [{ "id": 981, "name": "RDEXDPVKRD", "fields": [ { "id": 4096, "name": "RNVIDAYEBB", "default": "EDJEAJICYW", "required": true, "value": "Blah" }, { "id": 4097, "name": "QUFTXSIBYA", "default": "", "required": true, "value": "" }] }] }' "https://hooks.zapier.com/hooks/catch/......" My script is as follows: update_custom_fields_by_name_pre_write: function(bundle) { var updatedFields = _.map(bundle.request.data.custom_fields, function(group) { return _.map(group.fields, function(field) { return _.extend(field, _.findWhere(bundle.request.data.updated_custom_fields, { name: field.name} )); }); }); bundle.request.data = updatedFields; return bundle.request; } I know that the merging logic is good, but it appears that the custom_fields and updated_custom_fields arrays are not present in the bundle.request.data object. Anyone know how to get access to them in the script?
It seems like you should be using update_custom_fields_by_name_catch_hook to capture the incoming static webhook data (instead of _pre_write). If you use that, you can capture the data within bundle.cleaned_request.custom_fields and bundle.cleaned_request.updated_custom_fields.
QuickBooks API POST using Google Apps Script
Does anyone have a working example of doing a POST to the QuickBooks API using Google Apps Script? I'm trying to create an estimate using the QuickBooks API, however although the request body below works in the API explorer, from within Apps Script I get: Error: Fetch failed, code: 400, message: {"Fault":{"Error":[{"Message":"Request has invalid or unsupported property","Detail":"Property Name:Unrecognized token 'Line': was expecting ('true', 'false' or 'null')\n specified is unsupported or invalid","code":"2010"}],"type":"ValidationFault"},"time":"2016-08-02T09:51:28.917-07:00"} (line 195, file "Tests") But I can't see why the API expects a boolean rather than the "Line" key. This is how I define it as a POST payload in the code: var payload = { "Line": [ { "Id": "3", "LineNum": 1, "Amount": 10, "DetailType": "SalesItemLineDetail", "SalesItemLineDetail": { "ItemRef": { "value": "2", "name": "Hours" }, "UnitPrice": 10, "Qty": 2 } }, { "Amount": 10, "DetailType": "SubTotalLineDetail", "SubTotalLineDetail": {} } ], "TxnTaxDetail": { "TotalTax": 0 }, "CustomerRef": { "value": "1", "name": "Mr Blobby" }, "CustomerMemo": { "value": "Thank you for your business and have a great day!" }, "TotalAmt": 31.5, "ApplyTaxAfterDiscount": false, "PrintStatus": "NeedToPrint", "EmailStatus": "NotSet", } var companyId = PropertiesService .getUserProperties() .getProperty('QuickBooks.companyId') var url = 'https://quickbooks.api.intuit.com/v3/company/' + companyId + '/estimate' var options = { headers: { 'Accept': 'application/json' }, contentType: 'application/json', method: 'post', payload: payload, muteHttpExceptions: true, } var service = OAuth1_.getService(); var response = service.fetch(url, options)
You need to stringify the whole payload before passing it to the OAuth.fetch() call. So var payload = JSON.stringify({ "Line": [ { "Id": "3", . . })
How to add data to a custom HighChart's HighMaps map? joinBy?
I created a custom map using Inkscape as described on the HighMaps docs pages at: http://www.highcharts.com/docs/maps/custom-maps Everything up to step 16 seems to go smoothly. Step 16 says that the only remaining thing to do is to add data or use the MapData option and this is where I am struggling. How does one link the custom shapes in the map to data points? Using the shape name in a JoinBy? http://jsfiddle.net/GeertClaes/aWJ2D/ $(function () { // Initiate the chart $('#container').highcharts('Map', { title:{text:''}, subTitle:{text:''}, credits:{enabled:false}, legend:{enabled: false}, series: [ { "type": "map", "data": [ { "name": "Status1-CurrentPeriod", "path": "M0,-695,0,-682C1,-682,2,-683,3,-683,15,-683,25,-672,25,-658,25,-645,15,-634,3,-634,2,-634,1,-634,1,-634L1,-622,108,-622,107,-694,0,-695z" }, { "name": "Status1-Period-1", "path": "M0,-684,1,-633C15,-635,26,-646,26,-658,26,-672,14,-682,0,-684z" }, { "name": "Status2-CurrentPeriod", "path": "M178,-695,178,-682C179,-682,180,-683,181,-683,193,-683,203,-672,203,-658,203,-645,193,-634,181,-634,180,-634,180,-634,179,-634L179,-622,286,-622,285,-694,178,-695z" }, { "name": "Status2-Period-1", "path": "M178,-684,179,-633C193,-635,204,-646,204,-658,204,-672,193,-682,178,-684z" }, { "name": "Status3-CurrentPeriod", "path": "M357,-695,357,-682C358,-682,359,-683,360,-683,372,-683,382,-672,382,-658,382,-645,372,-634,360,-634,359,-634,359,-634,358,-634L358,-622,465,-622,464,-694,357,-695z" }, { "name": "Status3-Period-1", "path": "M357,-684,358,-633C372,-635,383,-646,383,-658,383,-672,372,-682,357,-684z" }, { "name": "Status4-CurrentPeriod", "path": "M535,-695,535,-682C536,-682,537,-683,538,-683,550,-683,560,-672,560,-658,560,-645,550,-634,538,-634,537,-634,536,-634,536,-634L536,-622,643,-622,642,-694,535,-695z" }, { "name": "Status4-Period-1", "path": "M535,-684,536,-633C550,-635,561,-646,561,-658,561,-672,549,-682,535,-684z" }, { "name": "Status5-CurrentPeriod", "path": "M713,-695,713,-682C714,-682,715,-683,716,-683,728,-683,738,-672,738,-658,738,-645,728,-634,716,-634,715,-634,715,-634,714,-634L714,-622,821,-622,820,-694,713,-695z" }, { "name": "Status5-Period-1", "path": "M713,-684,714,-633C728,-635,739,-646,739,-658,739,-672,728,-682,713,-684z" }, { "name": "Status6-CurrentPeriod", "path": "M892,-695,892,-682C893,-682,894,-683,895,-683,907,-683,917,-672,917,-658,917,-645,907,-634,895,-634,894,-634,893,-634,893,-634L893,-622,1000,-622,999,-694,892,-695z" }, { "name": "Status6-Period-1", "path": "M892,-684,893,-633C907,-635,918,-646,918,-658,918,-672,907,-682,892,-684z" } ] } ] }); });
There's a couple of ways: 1.) The easiest is to add it into your data using the value property. This is discouraged because it hardcodes the value for the map paths: "data": [ { "name": "Status1-CurrentPeriod", "path": "M0,-695,0,-682C1,-682,2,-683,3,-683,15,-683,25,-672,25,-658,25,-645,15,-634,3,-634,2,-634,1,-634,1,-634L1,-622,108,-622,107,-694,0,-695z", "value": 6 // <-- here's a numerical value for this path } 2.) Seperate your mapData from your data. Map the values in mapData to the values in data with a joinBy. This makes your map paths reusable: series: [{ "type": "map", "joinBy": ['name', 'name'], // <- mapping 'name' in data to 'name' in mapData "data": [ { "name": "Status1-CurrentPeriod", "value": 6 } ], "mapData": [ { "name": "Status1-CurrentPeriod", "path": "M0,-695,0,-682C1,-682,2,-683,3,-683,15,-683,25,-672,25,-658,25,-645,15,-634,3,-634,2,-634,1,-634,1,-634L1,-622,108,-622,107,-694,0,-695z" } ... }] Update fiddle here.