Microsoft Flow: How to Concatenate Data from JSON Object - json

I have a REST Web Services Call that is returning data in the following format:
{
"Id": "0497cee4-45dc-47d8-97a8-b45ad8018775",
"Status": "OK",
"ProviderName": "MyApp",
"DateTimeUTC": "/Date(1508348383277)/",
"Contacts": [
{
"ContactID": "1efa0ea1-de5c-4172-869c-816e27c3c825",
"ContactStatus": "ACTIVE",
"Name": "Company",
"FirstName": "Joe",
"LastName": "Bob",
"EmailAddress": "mainguy#here.com",
"BankAccountDetails": "",
"ContactPersons": [
{
"FirstName": "Operations",
"LastName": "",
"EmailAddress": "there#here.com",
"IncludeInEmails": true
},
{
"FirstName": "Another",
"LastName": "Contact Email",
"EmailAddress": "here#there.com",
"IncludeInEmails": true
}
],
"HasAttachments": false,
}
]
}
Within Microsoft Flow I would like to grab the main contact email (Contacts.EmailAddress) as well as all of the secondary Contacts Emails (Contacts.ContactPersons[x].EmailAddress); and use that for the too field of down-flow email.
ContactPersons will not always be defined in every case, but Contacts.EmailAddress should be.
What is the best way to do this with a flow? Is there a way to concatenate data over a loop or something? I can't seem to find a way to do it.

Try using Data Operations (https://learn.microsoft.com/en-us/flow/data-operations).
You can start off with a Select, picking the EmailAddress field in the Map, and then redirecting that to a Join and using that output.

Related

replace "key" name in whole JSON python for bulk data in efficient way

Actually i am pushing data to other system but before pushing i have to change the "key" in the whole JSON. JSON may contain 200 or 10000 or 250000 data.
sample JSON:
{
"insert": "table",
"contacts": [
{
"testName": "testname",
"ContactID": 212121
},
{
"testName": "testname",
"ContactID": 2146354564
},
{
"testName": "testname",
"ContactID": 12312
},
{
"testName": "testname",
"ContactID": 211221
},
{
"testName": "testname",
"ContactID": 10218550
}
]
}
I need to change contacts array Keys. These contacts may be in bulk. So i need to work with this efficiently with minimal complexity.
The above JSON to be converted as below
{
"insert": "table",
"contacts": [
{
"name": "testname",
"phone": 212121
},
{
"name": "testname",
"phone": 2146354564
},
{
"name": "testname",
"phone": 12312
},
{
"name": "testname",
"phone": 211221
},
{
"name": "testname",
"phone": 10218550
}
]
}
here is my code trying by loop
ini_dict = request.data
contact_data = ini_dict['contacts']
for i in contact_data:
i['name'] = i.pop('testName')
print(contact_data)
Please suggest me how can i change the key names efficiently for bulk data. i mean for 50000 lists in contacts. "for loop" will be leading a performance issue. So please let me know the efficient way to achieve this
I dont know how fast you need it to be nor how you are choosing to store your json. One simple solution is just store it as a string and then replace all the instances of your attributes.
# Something like this using a jsonstring
jsonstring.replace("'testName':", "'name':")
jsonstring.replace("'ContactId':", "'phone':")
If you want to do this in bulk you, may need to create some batch process to be able to fetch multiple existing records and make changes at once. I have done this before with the java equivalent of https://pypi.org/project/JayDeBeApi/ but, that was more for modifying existing records in a database.

How can I see logs of the JSON post bodies sent by zapier to my CRM (Current RMS) via the Webhook zap during setup and testing?

I'm trying to send new users / new customres of my WooCommerce store into the rental management app current-rms.com as new Organisations / new contacts. Since Current RMS does not have a native Zap, I am trying to use the generic Webhook zap that Zapier maintains.
Specifically, I'd like to see the sent JSON body in Zapier posts that I make during the setup and testing of the Zap after clicking "Make a Zap!". The Task History is not detailed enough nor does it show hits during test and setup, since it's not live yet.
My trigger is a WooCommerce New Customer. This is working with Zapier WooCommerce Plugin and webhooks OK.
My action is the generic Zapier "Webhooks" Zap. The label "instant" appears next to it in the list at /app/zaps and it is "off".
One version uses JSON PAYLOAD as the action.
Another version uses CUSTOM PAYLOAD as the action.
Wrap request in array is YES.
Unflatten is YES.
My API key and subdomain are in the app URL as query strings and working OK.
When I hit test I get:
We had trouble sending your test through.
The app returned "Invalid JSON - missing or invalid entry for 'member'". This usually happens when your Zap is missing a required field or a field value isn't in a recognized format.
We made a request to api.current-rms.com and received (400) Bad Request.
Official docs are at: https://api.current-rms.com/doc#members-members-post
Logging available at Current RMS side
Part of the authentication of Current RMS involves knowing the domain of the account you are trying to access, in my case its therockfactory due to it being an account for my company https://therockfactory.net/
https://api.current-rms.com/api/v1/members?apikey=APIKEYCENSORED&subdomain=therockfactory
which returns the following when I use the correct API key:
{"webhook_logs":[],"meta":{"total_row_count":0,"row_count":0,"page":1,"per_page":20}}
Maybe if I could see the actual hit that Zapier is posting to Current I could wrap my confused brain around it better? What me worry.
The hit should look somewhat similar to this example, but I've not been able to locate it so far... (in Zapier)
Headers
Content-Type: application/json
Body
{
"member": {
"name": "Chris Bralton",
"description": "Pictures and leaned back was strewn at one would rather more. People don't want of his own means of one hand! Unless it from our pioneer has he fallen tree but that ever stronger and a. Hid among us against the full of verdure through by my eyes.",
"active": true,
"bookable": false,
"location_type": 0,
"locale": "en-GB",
"membership_type": "Contact",
"lawful_basis_type_id": 10001,
"sale_tax_class_id": 1,
"purchase_tax_class_id": 1,
"tag_list": [
"[\"Red\", \"Blue\", \"Green\"]"
],
"custom_fields": {},
"membership": {},
"primary_address": {
"name": "Chris Branson",
"street": "16 The Triangle",
"postcode": "NG2 1AE",
"city": "Nottingham",
"county": "Nottinghamshire",
"country_id": "1",
"country_name": "United Kingdom",
"type_id": 3001,
"address_type_name": "Primary",
"created_at": "2015-06-29T10:00:00.000Z",
"updated_at": "2015-06-29T10:30:00.000Z"
},
"emails": [
{
"address": "abigail.parker#ggmail.co.uk",
"type_id": 4001,
"email_type_name": "Work",
"id": 1
}
],
"phones": [
{
"number": "+44 115 9793399",
"type_id": 6001,
"phone_type_name": "Work",
"id": 1
}
],
"links": [
{
"address": "www.facebook.com/profile.php?id=566828251",
"type_id": 5002,
"link_type_name": "Facebook",
"id": 1
}
],
"addresses": [
{
"name": "Chris Branson",
"street": "16 The Triangle",
"postcode": "NG2 1AE",
"city": "Nottingham",
"county": "Nottinghamshire",
"country_id": "1",
"country_name": "United Kingdom",
"type_id": 3002,
"address_type_name": "Billing",
"created_at": "2017-06-29T10:00:00.000Z",
"updated_at": "2017-06-29T10:30:00.000Z",
"id": 1
}
],
"service_stock_levels": [
{
"item_id": 10,
"store_id": 1,
"member_id": 1,
"asset_number": "Chris Bralton",
"serial_number": "",
"location": "",
"stock_type": 3,
"stock_category": 60,
"quantity_held": "1.0",
"quantity_allocated": "0.0",
"quantity_unavailable": "0.0",
"quantity_on_order": "0.0",
"starts_at": "",
"ends_at": "",
"icon": {
"iconable_id": 85,
"id": 1,
"image_file_name": "abigail.jpeg",
"url": "https://s3.amazonaws.com/current-rms-development/64a0ccd0-5fbd-012f-2201-60f847290680/icons/46/original/abigail.jpeg",
"thumb_url": "https://s3.amazonaws.com/current-rms-development/64a0ccd0-5fbd-012f-2201-60f847290680/icons/46/thumb/abigail.jpeg",
"created_at": "2015-06-29T10:00:00.000Z",
"updated_at": "2015-06-29T10:30:00.000Z",
"iconable_type": "StockLevel"
},
"custom_fields": {},
"id": 487,
"item_name": "Sound Engineer",
"store_name": "Nottingham",
"stock_type_name": "Service",
"stock_category_name": "Resource"
}
],
"day_cost": "",
"hour_cost": "",
"distance_cost": "",
"flat_rate_cost": "",
"icon": {
"image": ""
},
"child_members": [
{
"relatable_id": 317,
"relatable_type": "Member",
"related_id": 25,
"related_type": "Member"
}
],
"parent_members": [
{
"relatable_id": 317,
"relatable_type": "Member",
"related_id": 25,
"related_type": "Member"
}
]
}
}
UPDATE: After reading my chosen answer I was able to see what Zapier was sending:
[
{
"member[emails_attributes][0][address]": "test#test.co.nz",
"member[membership_type]": "Organisation",
"member[name]": "Testafari Testing"
}
]
You can send your webhook to a tool like this one to inspect the payloads that are being sent from anywhere on the internet: https://requestbin.com/
You can find more help in regards to using Webhooks by Zapier and other ideas on how you can troubleshoot issues stemming from its use: https://zapier.com/apps/webhook/help#inspect-the-requests

How to retrieve only immediate child object from a JSON response using Spring 5

I have build a small microservice using SpringBoot2 and Spring 5 which has a REST service exposed (HTTP GET Method) and which internally consumes another REST GET service (third party API). Using Postman when I call my service (GET), then I get a JSON response but the problem is I get a complete whole object in response like below :-
[
{
"id": "1",
"name": "Open Catalogue",
"subcategories": [
{
"id": "106",
**"name": "Components",**
"subcategories": [
{
"id": "816",
"name": "Power Supplies",
"subcategories": [
{
"id": "814",
"name": "Rechargeable Batteries",
"subcategories": [],
"sample": {
"empty": true,
"lazy": false,
"async": false
}
},
{
"id": "829",
"name": "Battery Chargers",
"subcategories": [],
"samples": {
"empty": true,
"lazy": false,
"async": false
}
},
My service URL used in post man is like this :-
http://localhost:8080/test-search?searchKey=ball
So my requirement is whenever a user consume this service by a sub-category name then only that sub-category details along with its immediate child details should be returned and not the child of child.
Here searchKey in URL is nothing but a free text to search for a sub-category. For instance when I say :-
http://localhost:8080/test-search?searchKey=Components
then only below details should be returned like this :-
"id": "106",
"name": "Components",
"subcategories": [
{
"id": "816",
"name": "Power Supplies",
Response should not have sub-categories of Power Supplies i.e. "subcategories": [ "id": "814",
"name": "Rechargeable Batteries",
Is there any efficient way to do the filtering while preparing the JSON response or first fetch whole object and then start filtering?
Please advise, thank you

JSON-Path Combining Expression With Index

Given the following sample JSON where we will not always know the order...
{
"contacts": [
{
"id": 287997,
"type": "P",
"relationship": "Mother",
"firstName": "Sara",
"lastName": "Johnson"
},
{
"id": 300982,
"type": "EC",
"relationship": "Aunt",
"firstName": "Janet",
"lastName": "Smith"
},
{
"id": 287200,
"type": "P",
"relationship": "Father",
"firstName": "William",
"lastName": "Johnson"
},
{
"id": 287997,
"type": "EC",
"relationship": "Friend",
"firstName": "Harold",
"lastName": "Johnson"
}
]
}
I want to retrieve the first contact which is of type 'EC'. The following retrieves all 'EC' type contacts just fine...
$.contacts[?(#.type == 'EC')]
But, I want only the first EC contact. I tried...
$.contacts[?(#.type == 'EC')][0]
But this did not work. I tried a few other variations with no luck. I would like to be able to achieve this without going outside of the JSON-Path approach if possible.
I know I can combine expressions like this...
$.contacts[?(#.type == 'EC' && #.firstName == 'Janet')]
But, I need to get the first contact that matches the 'EC' expression. So, after the 'EC' expression is evaluated, get the first of the filtered contacts.
I appreciate any help I can get! Thanks!
Kevin - yesterday I released a JS-lib I've been working on (DefiantJS) that solves your problem exactly the way you want it, and with the standardised XPath instead of JSONPath. At this page, there is a tool I've written XPath evaluator.
http://www.defiantjs.com/#xpath_evaluator
By clicking "Edit", I have pasted your JSON structure, and clicked "Edit" again (so that the structure is parsed by the tool). Now, entering the XPath below will filter the selection you want:
//contacts[./type="EC"][1]
To put this in Javascript code:
var obj = {
"contacts": [
{
"id": 287997,
"type": "P",
"relationship": "Mother",
"firstName": "Sara",
"lastName": "Johnson"
},
{
"id": 300982,
"type": "EC",
"relationship": "Aunt",
"firstName": "Janet",
"lastName": "Smith"
},
{
"id": 287200,
"type": "P",
"relationship": "Father",
"firstName": "William",
"lastName": "Johnson"
},
{
"id": 287997,
"type": "EC",
"relationship": "Friend",
"firstName": "Harold",
"lastName": "Johnson"
}
]
};
var sel = JSON.search(obj, '//contacts[./type="EC"][1]');
// sel[0] will contain your filtered object
DefiantJS extends the global object with a new method; "search". Since the function "search" always returns an array of matching elements, the handle to your selection is "sel[0]". Another Xpath for selecting contacts with the lastName "Johnson" is:
//contacts[./lastName="Johnson"]
The XPath evaluator tool have example XPath as well - which is meant to ease in developers not familiar with XPath. The source code of DefiantJS can be found at Github:
https://github.com/hbi99/defiant.js

How to merge JPA entity structure on a POST/PUT RESTful webapp

I am starting to implement a REST layer to an existing JSF-webapp (using RESTEasy, with a Jettison provider). Since tutorials for Java REST layers are quite basic (simple objects) I am facing the question how existing JPA entity relations can be easily exposed to/consumed from the client. A simple "/user" REST-method already gives me successfully the output below, which is a good start. But my main question is - how to deal with this kind of structures. Is it common to use such structures through REST?
I don't want to expose all details or the whole entity-tree, wether it is because of irrelevance, saving traffic or security issues. Using #XmlTransient works fine for the #Procudes, but merging these entities on a #POST/#PUT all #XmlTransient properties are merged to NULL. What is right way of doing that?
Since #XMLTransient is a global and permanent setting - what is the right approach to dynamically decide which depth of entity-tree I want to expose?
thanks
Example JSON of User-entity:
{
"user": {
"id": ..,
"uuid": "1521ccad69ba4579bbe49e75181fefc1",
"image": "",
"contact": {
"id": ..,
"uuid": "8eb429dcca994834ae5c8cf07cba62a2",
"cellphone": "",
"city": "",
"country": "",
"email": "mail#foo.bar",
"fax": "",
"phone": 555,
...
},
"name": "...",
"account": {
"id": ...,
"uuid": "80b331f9e6644449bb3600b0e5145253",
"confirmed": true,
"profile": {
"id": ...,
"uuid": "e172bdcafe2645d7975852ca5685c98c",
"locale": "en",
"notifyMessage": false,
"notifyNews": true,
"notifyTask": true,
"timeZone": "Europe/Berlin"
},
"roleProfiles": {
"id": ..,
"uuid": "f1713758f3f2416faed3e68350f2d759",
"active": true,
"assemblies": [
{
"id": ..,
"uuid": "13d72449833a4eb0b5b4f62c729ee44f",
"image": "",
"commercialRegisters": [
123,
456
],
"contact": {
"id": ...,
"uuid": "bef3802297344e3c8c3619b6c91c345a",
"city": "",
"country": "",
...
},
"thumbnail": ""
},
{
...
}
],
},
"userName": "..."
},
"displayName": "...",
"firstName": "Foo",
"lastName": "Bar",
"salutation": "",
"title": ""
}
}
Hi references in your Java classes should be serialized to JSON as links and not as values.
This is how Spring REST does it.
The good thing is : That way you have a kind of lazy loading
The bad thing is that the client needs additional requests to get the values of the references.
I developed a complete solution for that, but that was a hard piece of work.
The client (in javascript) creates proxies for those references and resolves them on demand.
I have a demo of that at demo.appdriver.com
In the upper right corner you see a link 'REST API' click it and you can see the REST API of a rather complex domain model.
Now you can start to click on the user interface , create, change, delete etc.
and have a look at the traffic between client and server.
Hope it helps !