Zapier API Code assistance - extract data from JSON - javascript

I am trying to use a JSON response in a Zapier response. The data looks like this:
I'm trying to use the Induction and Site Suitability href value in a Zap, however, when I try to use this in Zapier, Zapier gives me this:
I was going to use a find of some sorts to find Induction and Site Suitability and then return the href after that, but because of the formatting, I can't do that. Does anyone know how I can do this with Formatter or Code (Python/Javascript) or something else in Zapier?
Thank you
Luke
Here is the API result in code:
{
"competencies": [
{
"competency": {
"name": "Forklift Operator Permit",
"href": "https://link/22059"
},
"status": {
"value": "Active",
"type": "active"
},
"expiryWarning": "2021-04-15T13:59:00Z",
"expiry": "2021-04-30T13:59:00Z",
"disabled": false,
"href": "https://link/1b1594d738"
},
{
"competency": {
"name": "Induction and Site Suitability",
"href": "https://link/24033"
},
"status": {
"value": "Active",
"type": "active"
},
"expiryWarning": "2021-04-15T13:59:00Z",
"expiry": "2021-04-30T13:59:00Z",
"disabled": false,
"href": "https://link/8e26b5ea4bbc800e"
}
]
}

Related

Amazon SP API Feeds API processing report: The Amazon product type specified is invalid or not supported

I have been working with the feeds API. I am using a client library in Nodejs. I have been able to create a feed document, encrypt and upload a payload to the returned URL, create the feed, and then check its status in the Amazon Seller Central and also in the json response . Once status reaches the DONE state, I was able to get the processing report from the seller central: The processing report looks like this:
{
"header": {
"sellerId": "XXXXXXXXXX",
"version": "2.0",
"feedId": "50013019401"
},
"issues": [
{
"messageId": 123,
"code": "4000003",
"severity": "ERROR",
"message": "The Amazon product type specified is invalid or not supported."
}
],
"summary": {
"errors": 1,
"warnings": 0,
"messagesProcessed": 1,
"messagesAccepted": 0,
"messagesInvalid": 1
}
}
My PlayLoad was this:
{
"header": {
"sellerId": "XXXXXXXXXXX",
"version": "2.0"
},
"messages": [
{
"messageId": 123,
"operationType": "UPDATE",
"productType": "SHOES",
"requirements": "LISTING",
"attributes": {
"item_name": [
{
"value": "Awesome shoes",
"marketplace_id": "A21TJRUUN4KGV"
}
]
},
"sku": "abc1234"
}
]
}
I have also try LUGGAGE in the productType because that was used in the use-case guide. But get the same error.
I have also try productType:"PRODUCT" I found this solution in slackOverFlow link
But by try this solution also i am getting an error like this:
{
"header": {
"sellerId": "XXXXXXXXXX",
"version": "2.0",
"feedId": "50014019401"
},
"issues": [
{
"messageId": 123,
"code": "4000004",
"severity": "ERROR",
"message": "Creating products is not supported with the \"PRODUCT\" Amazon product type. Either specify a specific Amazon product type or specify an offer-only requirements set."
}
],
"summary": {
"errors": 1,
"warnings": 0,
"messagesProcessed": 1,
"messagesAccepted": 0,
"messagesInvalid": 1
}
}
And also can anybody provide me a link where i can find what to fill inside attribute object what are the key value like how to put images,sizes all this thing
Thank you
Maybe try using the Product Type Definitions API to determine the correct product type.
Documentation

I need recommendation for structure to use Cytoscape js

We are using Cytoscape + neo4j + spring boot + REST. We've tried to use some formats pass to frontend, however didn't work that well. So looking for best structure to use Cytoscape js.
========
Added later.
For example response from neo4j apoc export json query would be like this:
{
"application": {
"type": "node",
"id": "hhj354",
"labels": [
"Application"
],
"properties": {
"appid": "A90378",
"name": "hkjgj",
"status": "In Production"
}
},
"changes": [
{
"node": {
"type": "node",
"id": "fdsf324",
"labels": [
"Change"
],
"properties": {
"type": "gjhk",
"startdate": "2019-11-21 02:11:32"
}
},
"group": "2019-11",
"relation": sfd
},
{
"node": {
"type": "node",
"id": "fdsf324",
"labels": [
"Change"
],
"properties": {
"type": "gjhk",
"startdate": "2019-11-21 02:11:32"
}
},
"group": "2019-11",
"relation": sfd
},
{
"node": {
"type": "node",
"id": "fdsf324",
"labels": [
"Change"
],
"properties": {
"type": "gjhk",
"startdate": "2019-11-21 02:11:32"
}
},
"group": "2019-11",
"relation": 453
}
]
}
I need some detailed parsing codes. Parsing in backend or front end both ok as long as short enough.
Thanks in advance.
As far as I'm concerned, the front-end should do the less calculations as possible.
Therefore, try to send a JSON as close as possible to the format specified in the specs of cytoscape.js
The basic idea of graph is that it's composed of nodes and edges, those elements (as cytoscape calls them) have ids that can help you select them in a easier way.
No Calculation in Back-End
If you want to use built-in format .json from CALL apoc.export.json.all("all.json",{useTypes:true})then you will have for example to do some transformation in the front-end:
responseJson => {
responseJson.map(element => {
return {
group: element.type,
data : {
id: `${element.type}${element.id}`,
myFavouriteProperty: element.property
}
}
}

Blockly restrict input_value to another block

In my Blockly project, I have two 3 blocks rcm_a, rcm_b and rcm_c.
Blockly.defineBlocksWithJsonArray([{
"type": "rcm_c",
"message0": "Requirement block- rcm_a: %1 rcm_b: %2",
"args0": [
{
"type": "input_value",
"name": "rcm_a"
},
{
"type": "input_value",
"name": "rcm_b",
"check": ["rcm_b"]
}
],
"output": "Text",
"colour": "%{BKY_LOOPS_HUE}"
}]);
As you can see the above code of rcm_c, I am trying to restrict the second input to be of block rcm_b, and that apparently doesn't seem to be working. The same input will not accept any input type. Here's rcm_b's code:
Blockly.defineBlocksWithJsonArray([{
"type": "rcm_b",
"message0": "rcm_b %1",
"args0": [
{
"type": "input_value",
"name": "VALUE1",
"check": "String"
}
],
"output": "Text",
"colour": "%{BKY_LOOPS_HUE}"
}]);
I tried following this guide's Statement Stacks section (I am aware that I am trying to type check inputs and not statements) to achieve type-checking. What am I doing wrong?
Help is much appreciated!
Ah, seems like the 'output' of rcm_b needed to be rcm_b!

Working With Dynamic Multidimensional key-value pairs in JSON

Having a thorny problem and only see similar but also simpler solutions on SO.
Is is possible to generate a dynamic key AND dynamic values using JS/JSON?
For instance, let's say I have JSON like this:
{
"email": "user#someco.com",
"firstname": "Bob",
"lastname": "Smith",
"company": "ACME",
"custom": {
"services": [
{
"name": "svc1",
"desc": "abcdefg",
"selected": "true",
"status": "None"
},
{
"name": "svc2",
"desc": "abcdefg",
"selected": "true",
"status": "None"
},
{
"name": "svc3",
"desc": "abcdefg",
"selected": "false",
"status": "None"
},
{
"name": "svc4",
"desc": "abcdefg",
"selected": "false",
"status": "None"
}
],
"fields": [
{
"name": "Products",
"desc": "abcdef",
"type": "multi",
"values": [
{
"name": "Product1",
"desc": "abcdef"
},
{
"name": "Product2",
"desc": "abcdef"
}
],
"services": [
"svc1",
"svc2",
"svc3"
]
},
{
"name": "Wines",
"desc": "abcdef",
"type": "multi",
"values": [
{
"name": "Wine 1",
"desc": "abcdef"
}
],
"services": [
"svc4"
]
},
{
"name": "Fruits",
"desc": "abcdef",
"type": "multi",
"values": [
{
"name": "Fruit 1",
"desc": "abcdef"
},
{
"name": "Fruit 2",
"desc": "abcdef"
}
],
"services": [
"svc4"
]
}
]
}
};
I need to go into the fields and for each field (products, wines, fruits) see if a given service is contained within so that I can go back and generate a product or wine or fruit for each service that requires it. But I don't want to repeat the services names more than once. The resulting JSON should look something like this:
{"svc1":["Products"], "svc2":["Products"], "svc3":["Products"], "svc4":["Fruits", "Wines"]}
The hope would be that to generate a dynamic list in Angular I can just turn and loop back through this JSON, pulling out the values for each product, fruit, wine, whatever.
I've been trying a lot of nested for loops and the like but whenever I get more than one layer down the dynamism seems to stop. I'm guessing that for this to work I need to move between JS Objects and JSON?
Right now I'm trying something like this, which isn't quite working, stringify or no. And maybe I'm flip-flopping too much between JSON and JS Objects:
var outObj = [];
var fieldItems;
$.each(jsonObj.custom.fields, function(key, item) {
fieldItems = item;
fieldItems.name = item.name;
$.each(fieldItems.services, function(key, item) {
var serviceName = item;
//check to see if the serviceName already exists
if (outObj.indexOf(serviceName) > -1) {
outObj.serviceName.push(fieldItems.name);
} else {
outObj.push(serviceName);
}
});
});
JSON.stringify(outObj);
console.log("outObj " + outObj);
I get "can't read property 'push' of undefined" errors and the like. Seems this should be possible from a single nested loop, but maybe I need to just do two passes? Any other suggestions?
To me it sounds like overcomplicated solution. You can use basic array methods of javascript to filter out required structure. I am not sure what profiling_value in the presented snippet, so I started from the object structure in OP
var desiredResult = jsonObj.custom.services.reduce(function(result, service){
result[service.name] = jsonObj.custom.fields.filter(function(field){
return field.services.indexOf(service.name) >= 0;
}).map(function(field){ return field.name; });
return result;
}, {});
This gives the expected result for mentioned object.
reduce is required to iterate over all services and accumulate result in one object. Then for each service fields are iterated to filter out only those that contain link to this service. And finally list of filtered fields is transformed (map) into list of strings - their names - and inserted into accumulator

TypeError: Object [object Array] has no method 'getProperty'

I'm kind of new to this whole posting a question thing, so please be gentle!
I am using Breeze as part of the "Hot Towel" SPA stack and retrieving data from a custom WebApi endpoint written in PHP. It's not a full implementation, I've just written enough to give me what I need.
The metadata my endpoint is generating is as follows:
{
"shortName": "Project",
"namespace": "WebApi.ORM.Cartesius",
"autoGeneratedKeyType": "Identity",
"defaultResourceName": "Project",
"dataProperties": [
{
"name": "id",
"isPartOfKey": true,
"isNullable": false,
"dataType": "Int32"
},
{
"name": "title",
"isNullable": false,
"maxLength": 256,
"dataType": "String"
},
{
"name": "date",
"isNullable": false,
"dataType": "DateTime"
},
{
"name": "review_date",
"isNullable": true,
"dataType": "DateTime"
},
{
"name": "summary",
"isNullable": true,
"dataType": "String"
}
],
"navigationProperties": [
{
"name": "Team",
"entityTypeName": "Team:#WebApi.ORM.Cartesius",
"isScalar": true,
"associationName": "team_project_id_fkey",
"invForeignKeyNames": [
"project_id"
]
},
{
"name": "ProjectAuthor",
"entityTypeName": "ProjectAuthor:#WebApi.ORM.Cartesius",
"isScalar": true,
"associationName": "project_author_project_id_fkey",
"invForeignKeyNames": [
"project_id"
]
},
{
"name": "Itinerary",
"entityTypeName": "Itinerary:#WebApi.ORM.Cartesius",
"isScalar": true,
"associationName": "itinerary_project_id_fkey",
"invForeignKeyNames": [
"project_id"
]
},
Everything is working fine until I try and do an expand on my query:
var query = new breeze.EntityQuery()
.from("Project")
.where("id","eq",project.id)
.expand("ProjectAuthor");
This query returns the following from my endpoint:
[
{
"$id": 1,
"$type": "WebApi.ORM.Cartesius.Project",
"id": 2,
"title": "teat",
"date": "2013-11-04 14:00:00+07",
"review_date": null,
"summary": null,
"ProjectAuthor": [
{
"$id": 2,
"$type": "WebApi.ORM.Cartesius.ProjectAuthor",
"id": 1,
"account_id": 1,
"project_id": 2,
"Project": [
{
"$ref": 1
}
]
},
{
"$id": 3,
"$type": "WebApi.ORM.Cartesius.ProjectAuthor",
"id": 3,
"account_id": 2,
"project_id": 2,
"Project": [
{
"$ref": 1
}
]
}
]
}
]
Then Breeze chokes on it throwing:
TypeError: Object [object Array] has no method 'getProperty'
Debugging points to line 5059 in Breeze where it tries to getProperty on an array of entities rather than a single entity I assumed this had something to do with whether the navigation property was set to scalar or not but switching them around made no difference.
I'm sure I'm doing something massively wrong, but I can't figure out what it is and I've kind of hit a brick wall. I've read the docs from top to bottom and am implementing this as best as I can understand but it's possible I'm a little confused.
Thanks in advance for any help and apologies if I have not made myself clear or provided enough info
I think your problem is in the metadata
"name": "ProjectAuthor",
"entityTypeName": "ProjectAuthor:#WebApi.ORM.Cartesius",
"isScalar": true,
"associationName": "project_author_project_id_fkey",
"invForeignKeyNames": [
"project_id"
]
},
On that nav property Project->ProjectAuthor your telling it that its a scalar but its not in the data set..
"ProjectAuthor": [
{
..........
I've had this problem aswell .. 99% time its a metadata problem, if not there then start cutting metadata apart until you isolate the error .. though I'm sure thats the problem.. you need a hasMany there and an isScalar on the inverse navigation

Categories

Resources