DynaWeb – Part 2

Amazing! DynaWeb – Part 2

Information about DynaWeb – Part 2

Phil Puccio

After a first article in which I introduced you both Air table and DynaWeb, we continue to use the web API with DynaWeb. In this post, we’ll see how to create more complex requests.

Get a specific record

If we want to get a specific row in our airtable, we need to add the ID of the row we are looking for to the URL. So in order to get a specific record we have to be in front of the list of all records with their ID. We need two requests, one for the list of records and one for the specific request.

Get a specific record

A request can be slow, so we have to wait for the first one before using its result (the list of records) to execute the second. To do this, we use the DataStream.Await node from the orchid package. This way we can wait for the first request to complete before executing the second.

Wait for the request to complete

We then get the selected node, still as a JSON file:

 "id": "rec05TzOsAsrWLXD4",
 "fields": {
   "Code": "201",
   "Material": "Steel",
   "Width": 915,
   "Height": 2134,
   "Fire Rating": "3/4 Hours",
   "Level": "02 - Floor",
   "Frame Finish": "Polyester powder coated",
   "Doorstop": "Floor mounted door stop"
 "createdTime": "2020-06-26T14:50:25.000Z"

The full definition can be found here.

Create records

In the previous two examples, we only received information from Airtable. Now let’s see how to add new rows to our airtable table. To do this, we now have to send information to Airtable with a new method: POST. This type of request not only has a URL, but also a payload, the “body”, that is sent to that URL.

I’m going to add two rows to my table, two steel doors coded “328” and “328”. These two lines are encoded as Json text in the main part of my query.

To create such a request in Dynamo, we first need a list of dictionaries that represent these two lines. We’ll first create a dictionary for each door and then manually add it to a new list. The Airtable API documentation states that this list must be nested in a “Records” object. We create the corresponding dictionary:

Create the request text

Then add this dictionary to the request using the WebRequest.AddParameter node:

Add the JSON text to the request

“Application / json” (1) means that the body is a JSON string. The “Data.StringifyJSON” converts the dictionary into a JSON string (2). The “RequestBody” node allows us to define the added parameter as the main part of the request (3).

When we go back to Airtable we can see the newly created lines:

Lines created in Airtable

The full definition can be found here.

The complete mail request

Update records

Using the PATCH or PUT method on the request allows us to edit a specific line. This requirement is very similar to the POST requirement previously described, with the expectation that the ID of the row to be updated must be in the body.

To do this, we need to add the ID to the dictionary that was used to create the previous body with a Dictionary.ByKeysValues ​​node:

Add the ID to the body

We then use this updated body with the WebRequest.AddParameter node, set the method to PATCH, and rerun the request. The corresponding row in our table is updated, we see the change in the “Activity” field in Airtable:

The result of the PATCH request

Since we are using a PATCH method, the only updated columns are those given in the body of our query. If we use the PUT method, the request will delete any unspecified cell values:

The result of the PUT request

The full definition can be found here.

The complete update request

Delete records

To delete a row, we use the DELETE method on a specific row. We just create the request url with the line id and apply the method to the request:

delete a line

The full definition can be found here.

A few more tips

As you work with DynaWeb, you may need these few additional tips.

Debug request

In order to debug your solution, you need to analyze the resulting request with a proxy server application. Such an application lists and logs all requests sent from your computer. You can then see the details of your request and troubleshoot any issues. I use Violinist it’s free and really nice.

Restart the dynamo

Dynamo uses a cache system to store the result of each unchanged node in memory. Although this feature is generally very useful, it can cause problems with DynaWeb. If your request remains unchanged after editing your Dynamo definition, simply close and restart that definition to clear the cache and resubmit the request.

Write the answer

I’m used to writing the answer to my query in a text file that I keep open in a text editor. I’m using Visual Studio Code, but you can use any code editor. This gives me a nice view of that answer that I can easily parse and format without having to look in the Watch node’s small window.

The DynaWeb package gives you access to a completely new ecosystem of web-based applications via Dynamo. By using them in your workflows, you can integrate solutions such as Office 360, Dropbox or Airtable with desktop-based CAD applications such as Revit. Since I use DynaWeb more and more, I wanted to add a little more to this great package with this post, in the hope that it will be known and used by many of you.

Breaking Story – DynaWeb – Part 2

The Latest News on DynaWeb – Part 2

Original Source: https://www.bim42.com/2020/07/dynaweb-2
Category – BIM

© 2022 welcometoabode.com - WordPress Theme by WPEnjoy