I have a power app that wants to collect some data from a rest API, I am using Flow as this seems to be the recommended way.
I have a collection:
[
{id: 1,name: "test",lines: [
{id: 244,
StrategyId: 1,
TypeId: 0,
Weight: 10,
toWeight: 200
}
]
},
{id: 3,name: "test2",lines: [
{id: 262,
StrategyId: 3,
TypeId: 0,
Weight: 0,
toWeight: 200
}
]
}
]
When I enter this into a formula straight up, it works fine:
ClearCollect( CityPopulations, json...)
However, when I try to fetch the data from Flow it only returns a collection with one single entry that is the json data as string.
Set('CityPopulations','PowerApp->Sendmeamobilenotification'.Run());ClearCollect(NewTable, CityPopulations.testoutput);
In Microsoft flow I use PowerApps trigger and Respond to PowerApps.
Also note that there are no " on the propertynames in json structure, but this was the only way I could get Power Apps to actually accept typing in json manually. I have tried having the respons propper, as well as this way. I had to adjust the flow to remove the " around propertynames. Still same result.
This is how the table looks in collections:
This is how it looks when I am entering the data manually:
this is the direct output from :
{
"testoutput": "[{id:1,name:\"test\",lines:[{id:244,StrategyId:1,TypeId:0,fromWeight:10,toWeight:200}]},{id:2,name:\"tester\",lines:[{id:154,StrategyId:2,TypeId:0,fromWeight:10,toWeight:200}]}]"
}
The biggest difference is the escape characters added from flow.
This took me quite some time to solve so maybe will help others.
When you want to return an array (collection) form Flow to a Canvas App you need to use Response (Request), not Respond to PowerApps.
All the problems go away with that
Tip: Remember to provide a SCHEMA and to remove and re-add the flow in the canvas app
It looks like your Collecting a single column of Text from the API Response rather than collecting the entire response.
Try just using:
ClearCollect(colNewTable,'PowerApp->Sendmeamobilenotification'.Run())
If you want to set colNewTable as a variable, wrap it like:
Set(varNewTable,ClearCollect(colNewTable,'PowerApp->Sendmeamobilenotification'.Run())
Hope this helps!
Related
This is my source ( JSON)
{
"Price": {
"For": "840.040",
"From": "2.990"
},
"ArticleNumber": "71151004",
"ArticleNumberPartitionKey": "7115",
"ForStatus": "ACTIVE",
"id": "71151004",
}
My requirement is to get True in Logic apps( Condition) if the JSON file contains "ForStatus":"ACTIVE".
I tried with this command but not working.
json(base64ToString(triggerBody()?['Content']))?['ForStatus']?['ACTIVE']
According to your description, I don't know where your source(json) come from. I'm not sure if the expression json(base64ToString(triggerBody()?['Content'])) you provided can get the json data rather than get null value.
I assume the expression json(base64ToString(triggerBody()?['Content'])) can get the json data. To implement your requirement, you can use json(base64ToString(triggerBody()?['Content']))?['ForStatus'] is equal to ACTIVE, like below screenshot:
If the property ForStatus may not exist in your json data, you can use string(json(base64ToString(triggerBody()?['Content']))) contains "ForStatus":"ACTIVE", like below screenshot:
Please note, use "ForStatus":"ACTIVE"(remove blank space before "ACTIVE") after the "contains" because when you use json() method, it will remove the blank space.
I'm trying to batch upload photos and I keep getting a response back from Postman saying "Batch parameter must be a JSON Array" Does anyone see what is wrong with this because it looks like valid json to me. I've been rattling with this for a few hours making minor tweaks trying to get it to upload to no avail. I also have tried encoding the url.
https://graph.facebook.com/v2.11?batch=[{"method":"POST", "relative_url":"https://graph.facebook.com/v2.11/{pageid}/photos?access_token={access-token}", "body":"link_url":"https://{link-to-image}/wmphotos/999995/6d5cc4169bbf4e7dbe31f3739e025412/a572c29dff_640.jpg"}]&access_token={access-token}
Looking at your code, it seems that the JSON object in your batch array is actually malformed. body:link_url:link should be body: {link_url:link}
Bad:
[
{
"method":"POST",
"relative_url":"foo",
"body":"link_url":"link"
}
]
Good:
[
{
"method":"POST",
"relative_url":"foo",
"body":{"link_url":"link"}
}
]
I have an inconsistent issue with the JSON sent to highcharts. Highcharts does not always reject the JSON, but when it does, updating the JSON by hand to a proper format consistently fixes it:
Exmaple DotNet.Hightcharts output:
series: [{ data: [284, 49, 100, 19], name: 'some name' }, { data: [230, 250, 219, 878], name: 'some name 2' }]
when fixed to included quotes it works:
"series": [{ "data": [284, 49, 100, 19], "name": "some name" }, { "data": [230, 250, 219, 878], "name": "some name 2" }]
Is there a way to get DotNet.Hightcharts to output this format?
Looking at the DotNet.Highcharts source code, it seems it uses its own JsonSerializer which does not quote property names, and there's no option to change this behavior nor swap out the serializer for another one altogether. They have made it straight forward to change the formatting in code though, so it looks like changing the following lines in: DotNet.Highcharts/JsonSerializer.cs should do what you need:
const string JSON_PROPERTY_WITH_VALUE_FORMAT = "{0}: {1}";
const string JSON_STRING_FORMAT = "'{0}'";
to become:
const string JSON_PROPERTY_WITH_VALUE_FORMAT = "{\"0\"}: {1}";
const string JSON_STRING_FORMAT = "\"{0}\"";
So I'd say you options are:
Compile your own version of DotNet.Highcharts using the source code with the above alterations.
Convince the project developers to include such changes in the next release.
Use an alternative library such as Highcharts.Net which does quote names by default.
Use no library at all and just render your data into a literal placed inside the hand-coded Highcharts javascript, using a stand alone Json formatter like Newtonsoft.Json.
Before any of the above though, it does sound a bit odd that this problem only emerges as more data is added. It's not just a case of apostrophes in your data breaking the format is it? They don't appear to be being escaped in the formatter.
I have truly searched and I have not found a decent example of using the serializer to get objects from a differently formatted JSON response. My reason for not changing the format of the JSON response is outlined here http://flask.pocoo.org/docs/security/#json-security.
I'm not very good with javascript yet so I had a hard time understanding the hooks in the serialize_json.js or maybe I should be using mapping (I just don't know). So here is an example of my JSON response for many objects:
{
"total_pages": 1,
"objects": [
{
"is_completed": true,
"id": 1,
"title": "I need to eat"
},
{
"is_completed": false,
"id": 2,
"title": "Hey does this work"
},
{
"is_completed": false,
"id": 3,
"title": "Go to sleep"
},
],
"num_results": 3,
"page": 1
}
When ember-data tries to use this I get the following error:
DEBUG: -------------------------------
DEBUG: Ember.VERSION : 1.0.0-rc.1
DEBUG: Handlebars.VERSION : 1.0.0-rc.3
DEBUG: jQuery.VERSION : 1.9.1
DEBUG: -------------------------------
Uncaught Error: assertion failed: Your server returned a hash with the key total_pages but you have no mapping for it
Which totally makes when you look at my code for the data store:
Todos.Store = DS.Store.extend({
revision: 12,
adapter: DS.RESTAdapter.create({
mappings: {objects: "Todos.Todo"},
namespace: 'api'
})
});
My question is how do I deal with total_pages, num_results and page? And by deal, I mean ignore so I can just map the objects array.
All root properties you return in your JSON result are mapped to a DS.Model in Ember Data. You should not return properties that are not modelled or you should model them.
If you want to get rid of the error you should make an empty model for the properties you don't use.
Read more here
Why are you returning properties you don't want to use? Or is it out of your control?
The way to accomplish this is with a custom serializer. If all your data is returned from the server in this format you could simply create ApplicationSerializer like this:
DS.RESTSerilizer.extend({
normalizePayload: function(type, payload) {
delete payload.total_pages;
delete payload.num_results;
delete payload.page;
return payload;
}
});
That should allow Ember Data to consume your API seamlessly.
Ember is fairly opinionated about how things are done. Ember data is no exception. The Ember team works towards certain standards that it thinks is best, which is, in my opinion, a good thing.
Check out this post on where ember is going. TL;DR because there are so many varying implementations of api calls, they're setting their efforts towards supporting the JSON API.
From my understanding, there is no easy way to do what you're asking. Your best bet is to write your own custom adapter and serialized. This shouldn't be too hard to do, and has been done before. I recommend you having a look at the Tastypie adapter used for Python's Django Tastypie
I am a bit new to d3.js, but I'm having quite a bit of fun with it. So far, I have implemented a force-directed graph that is very close to many of the examples and tutorials out there.
Direct Concern
Like many of the examples, I have a JSON structure like this:
{"nodes": ["node1", "node2", ... ],
"links": [{source: 0, target: 1, "field1": 5, ...}, ... ]}
However, I think that it would be easier to construct my data sources like this:
{"links": [
{source: "node1", target: "node2", "field1": 5, ...},
{source: "node2", target: "node4", "field1": 1, ...},
{source: "node3", target: "node4", "field1": 8, ...}
]}
Instead of explicitly defining the nodes in my graph, they are implicitly defined in the link structures.
The Reason
I wanted to list the eventual goal of the project in case someone had some specific example code or idiomatic way of doing this of which I am unaware.
The goal for the project would eventually be a graph that is updating in real-time. The back-end is being developed and is subject to some change and revision.
At the moment, I'm imagining pulling down an update JSON feed every X seconds and updating the structure of that graph with the new information. The pulled feed would only contain the updated structures of the graph, so the script would need to maintain the all of the already pulled nodes and links and add any new ones, if necessary.
Thanks!
I apologize if this has been asked before. I did some searching and didn't find anything. Feel free to insult and berate me if I missed it.
I've had to do this a few times. The simplest approach I've found has been to simply compute the set of nodes base don the list of links and then turn it into an array for the force graph to use:
var links = [ .... ];
var nodeMap = {};
links.forEach(function(d, i) {
nodeMap[d.source] = true;
nodeMap[d.target] = true;
});
var nodes = [];
for (key in nodeMap)
nodes.push(key);
d3.layout.force()
.nodes(nodes)
.links(links);
I've done just this in the example "D3 Based Force Directed Radial Graph". I do this because I want to understand how the data is used, internally, independent of structures like JSON and CSV, which can always be layered in, later.
Anyhow, I hope the example helps you.
My Best,
Frank