Returning Revit elements data as JSON in Forge API - autodesk-forge

Within a web client using the Forge API, I would like to get a JSON array of Revit elements in a model. Using the Design Automation API, I am creating an Activity that uses FilteredElementCollector to retrieve the elements, but once I have the elements I'm not sure the best way to retrieve those results in my web service. This Activity does not need to write back to an .rvt file.
The CountItApp tutorial writes the results to a results.txt file in cloud storage, and the web app then downloads that results.txt file and parses the results. On my web client I want to display these results, but file I/O does not seem like a very good solution for JSON data. A couple alternatives I've considered:
Write results to an external database and query that database in my web application once the WorkItem completes. As far as I know this is not possible due to Forge's restrictions on network access within an Activity.
Pass the results with the onComplete callback. I don't know if this is possible.

Design automation allows you to post a workitem with output arguments with POST callback. This allows you to receive the output data as application/json if your output file generated by your activity is a json file.
Design automation also allows you to specify a variable workitem.id in your output url. When your workitem completes we shall call this url with the variable expanded to the id of that workitem. This dynamic variable path allows you to determine the workitem id associated with that callback.
Here is how you could go about. First define an activity with such an output parameter (verb: post) with a hardcoded local name result.json:
"results": {
"zip": false,
"ondemand": false,
"verb": "post",
"description": "Results",
"required": true,
"localName": "results.json"
}
In your appbundle code save the json contents in a file with hardcoded name result.json to the current working folder.
using (StreamWriter sw = File.CreateText("result.json"))
{
sw.WriteLine(JsonConvert.SerializeObject(data, Formatting.Indented));
sw.Close();
}
Then you can post a workitem like so:
"result": {
"verb": "post",
"url": "https://www.yourserver.com/results/$(workitem.id)"
}
In your server implementation of the callback you will get the json contents as the payload. You may read the results and communicate back to the client corresponding to the workitem id, using sockets or any other means of communication you may have with your client.

Related

Compass Search request through slate - Palantir Foundry

I'm trying to create a Slate application which uses the compass search endpoint.
I've managed to connect to the endpoint trough postman just fine using <host>/foundry-search/api/compass/v0/search, and get the desired results.
However in Slate I'm unable to get a 200 response with the same query, using search in the path, example:
{
"path": "search",
"method": "POST",
"bodyJson": {
"query": {},
"limit": 5
},
"extractors": {
"results": "$"
},
"headers": {
"Content-Type": "application/json",
"Content-Length": 64
}
}
Other compass endpoints work fine, its just the search one I cant manage to work out. For this query in particular I get 500, with errorCode INTERNAL. Is there any magic trick one needs to do for search?
From the layout of the request, it looks like the Compass datasource being queried has been configured with an HttpJson type. It's generally not recommended to query Foundry services through the HttpJson configuration as certain endpoints may only be considered internally supported, and liable to change at any time (which could possibly break your Slate application without warning).
Slate datasources that point to Foundry services should be configured as a ServiceApi type as they provide an easy editor layout that displays available supported endpoints, endpoint parameter inputs (with Handlebar support), and the expected parameter types.
Please contact your Palantir rep and ask for the Compass service to be configured as a ServiceApi with the search Compass endpoint enabled. Doing so will allow you to query any supported Compass endpoint without needing to worry about correctly formatting the HttpJson structure, or guessing which endpoint parameters are required.

Retrieving forecast data from OpenWeatherMap in FIWARE ORION

I am trying to get weather forecasts data from OpenWeatherMap and integrate them in Orion by performing a registeration request.
I was able to register and get the API key from OpenWeatherMap, however, the latter returns a JSON file with all the data inside, which is not supported by ORION.
I have followed the step by step tutorial https://fiware-tutorials.readthedocs.io/en/latest/context-providers/index.html#context-provider-ngsi-proxy where they have acquired the data from OpenWeatherMap using NGSI proxy, an API key is required to be indicated in the docker-compose file as an environment variable, however, the data acquired is the "current data" and not forecast and also specific to Berlin.
I have tried to access the files inside the container "fiware/tutorials.context-provider" and try to modify and match the parameters to my needs but I feel like I am taking a long blocked path.
I don't think that's even considered as good practice but I have run out of ideas :(
Can anyone suggest how I could bring the forecast data to Orion and register it as a context provider?
Thank you in advance.
I imagine you aim to implement a context provider, able to speak NGSI with Orion.
OpenWeatherMap surely doesn't implement NGSI ...
If you have the data from OpenWeatherMap, as a JSON string, perhaps you should parse the JSON and create your entities using some select key-values from the parsed OpenWeatherMap? Save the entity (entities) locally and then register those keys in Orion.
Alternatively (easier but I wouldn't recommend it), create local entities with the entire OpenWeatherMap data as the value of an attribute of the entity:
{
"id": "id-from-OpenWeatherMap",
"type": "OpenWeatherMap",
"weatherData": {
"value":
...
}
...
}
Then you register id/weatherData in Orion.

In Google Apps Script is the command “AdminDirectory.Groups.insert(group)” considered to be a post request?

In Google Apps Script I am calling the G Suite Admin SDK Directory API using the command AdminDirectory.Groups.insert(group). Is this considered to be a POST request? I’m wondering because I know there are implicit ways of making POST requests where POST is not specified explicitly such as urlfetch(). In the project that I am working on, I am trying to avoid using HTTP requests for security reasons.
I did some research online, but I am having some difficulty finding the answer to this question. I'm thinking that since a JavaScript object rather than a JSON object was passed into insert(), it would not be considered a POST request since JSON notation is typically used when sending data to a server or retrieving data from a server. Because group is a JavaScript object and not a JSON object, I am thinking the command AdminDirectory.Groups.insert(group) would not be a POST request. Am I on the right track here?
For some context, here is the function I wrote to create a group:
function createAGroup() {
var group = {
email: "test-group#test.com",
name: "Test Group",
description: "This is a test group."
};
group = AdminDirectory.Groups.insert(group);
Logger.log('Group %s created.', group);
}
The function createAGroup() created a group successfully. However, was the command AdminDirectory.Groups.insert(group) using a POST request to create the group or not?
If you are not sure which kind of request you are looking at - you can find it out in the Google Developers Reference.
In your case:
If you go to the Apps Script Reference for the admin directory:
https://developers.google.com/apps-script/advanced/admin-sdk-directory
It will link you to the reference documentation for the specific methods for the Admin SDK Directory API where you can find the reference for the specific method Groups:insert
https://developers.google.com/admin-sdk/directory/v1/reference/groups/insert
It tells you:
HTTP request
POST https://www.googleapis.com/admin/directory/v1/groups
This syntax is translated one to one into Apps Script, which you can prove as following:
If you test the method in “Try this API” with your request body, the outcome will be:
200
{
"kind": "admin#directory#group",
"id": "03oy7u293zlw6l7m",
"etag": "\"zPBZh0mDALCYqI567HUiXii8qQjpg/VckrVGnV8Hs56iDrqRt7j4XT5eRyM\"",
"email": "test-group#test.com",
"name": "Test Group",
"description": "This is a test group",
"adminCreated": true
}
Now if you run it in Apps Script your Looger.lo output will be:
Group {kind=admin#directory#group, name=Test Group, description=This is a test group., etag="zPBZh0mDALCYqI7HMkUiXii8qQjpg/gIcr9tsZMDRRrDJECvLtNT66KBc", id=00ha3apch11zp6hh, adminCreated=true, email=test-group#test.com} created.
You can see that in both cases the response retrieves the data in the same way and gives you an equivalent feedback. Thus, it is safe to say that the method used in App Script, uses indeed the POST request.
As a general rule:
Anything that is creating a new object at the backend (like inserting users or groups) is a POST request, anything that is updating existing objects (e.g. change personal data of a user) is a PUT request, anything that retrieves data (e.g. listing users) is a GET request and DELETE is pretty self-explaining.
App Script is a “tool” that takes away the need to implement the request manually. But always check the reference how to implement a specific method.
If you do want to make an explicit JSON request - you can convert the JavaScript notation into a JSON string with JSON.stringify() as explained here:
https://developers.google.com/apps-script/guides/services/external#work_with_json

How to update json field in Firebase DB with JMeter HTTP Request

I'm working with JMeter to make some HTTP Requests to my Firebase Database. I am able to create json data with a regular request, as well as with a CSV file. I'm wondering if it's possible to update, or add to, a json object.
My json data looks something like what is below. Let's say I wanted to add a boolean node called "sold", to which I could make equal to true or false. Could I create it within that json object? If so, could I also make it so that only fields with a specific "name" get updated?
{
"Price": "5.00",
"name": "buyer#gmail.com",
"seller_name": "seller#gmail.com",
"time": 1496893589683,
}
Looking into Updating Data with PATCH chapter of Saving Data article you can update a single field using HTTP PATCH Method.
JMeter supports HTTP PATCH method since version 2.8 so you should be in a position to use it as well in your test.

Can't extract data from my json response-Web Java EE Application

I developed a web service that extracts messages from a database and returns an object containing a table and a string, as a json response.
The problem is that I can't extract data from the client application when I consume the web service.
This is the reponse I get when I run the web service
{
"msgTabl":
{
"list":
[
{"contenu":"aid mabroukk","dateEnvoi":"2014-07-30","frommm":"voeuxmsg","id":0,"idu":0,"numExp":50840749},
{"contenu":222222222222,"dateEnvoi":222222,"frommm":222222222222,"id":0,"idu":0,"numExp":2222222},
{"contenu":3333333333,"dateEnvoi":3333333333,"frommm":333333333,"id":0,"idu":0,"numExp":33333333333}
],
"test":"ok"
}
}
I tried to take the json content from my client application, but I couldn't because of the structure of my json reponse. I don't know why this "msgTabl" is shown at the beginning.
You can use
reponse['msgTabl']
in your client application to get the right structure you want