API waterservices.usgs.gov and “Auto Refresh API Ajax”

Challenge: Display the data from https://waterservices.usgs.gov/nwis/iv/?format=json&sites=01407600&parameterCd=72279&siteStatus=active

Simply displaying data is easy – create a Plugin template with the above URL and this Twigcode (Shortcode: [jsoncontentimporterpro id=NO_OF_TEMPLATE])

Location:  {{value.timeSeries.0.sourceInfo.siteName}}<br>
Date: {{value.timeSeries.0.values.0.value.0.dateTime | date("Y-m-d",   "America/New_York") }} <br>
Time: {{value.timeSeries.0.values.0.value.0.dateTime | date("H:i",  "America/New_York") }}<br>
Water Level: {{value.timeSeries.0.values.0.value.0.value}}

In Action:

Location:Shrewsbury River at Sea Bright NJ
Water Level:1.85

Display this data with the “Auto Refresh API Ajax” Plugin- Way 1:

  • Install the Plugin
  • Create a HTML-Div like <div id="araatest">load data</div>
  • Go to the “Auto Refresh AA” menu and insert this:
  • URL: See above
  • What: value.timeSeries.0.values.0.value.0.value
  • Where: div[id="araatest"]

Display this data with the “Auto Refresh API Ajax” Plugin- Way 2:

Create a new JSON-Feed by adding a new plugin-template:
URL: https://waterservices.usgs.gov/nwis/iv/?format=json&sites=01407600&parameterCd=72279&siteStatus=active

{"data": "Location:  {{value.timeSeries.0.sourceInfo.siteName}}, Date: {{value.timeSeries.0.values.0.value.0.dateTime | date("Y-m-d",   "America/New_York") }}, Time: {{value.timeSeries.0.values.0.value.0.dateTime | date("H:i",  "America/New_York") }},Water Level: {{value.timeSeries.0.values.0.value.0.value}}"}

Put [jsoncontentimporterpro id=NO_OF_TEMPLATE] on a new page. This page should be something like this:
Adding “?show=oc” removes the template and gives pure JSON:
http://api.json-content-importer.com/json-waterservices-usgs-gov/?show=oc http://api.json-content-importer.com/json-waterservices-usgs-gov/?show=oc
This JSON we use in “Auto Refresh API Ajax”

API cryptopanic.com with PRO plugin

How to get access to the data in
https://cryptopanic.com/api/v1/portfolio/?auth_token=… (auth_token needed for real access).

For that create a new Plugin-Template with these data
URL: see above

portfolio.totals.BTC: {{portfolio.totals.BTC}}<br>
{% for e in portfolio.entries %}
id: {{e.id}}, currency: {{e.currency.title}}, amount_usd: {{e.amount_usd}}<br>
{% endfor %}

Shortcode: [jsoncontentimporterpro id=NO_OF_TEMPLATE]

Live in action:

id:99547, currency:Bitcoin, amount_usd:3517.23513915
id:99550, currency:Ren, amount_usd:107.086342464
id:99548, currency:BitShares, amount_usd:105.932669292
id:99549, currency:Gifto, amount_usd:101.704387806
id:99591, currency:Request, amount_usd:75.675883161

Shownotes: Generate Custom Post Types for meetup.com API

Here you find the Code for Copypasting to the Video created to show how the JCI-plugin can generate Custom Post Types out of JSON.

1. Link to JSON:

2. Plugin-Settings for Custom Post Tpyes:

3. Overview-Page: twig-cod

{% for m in _parent %}
{{(m.time/1000) | dateformat('%A %m/%d/%y %H:%M:%S ', 'Europe/Berlin', 'en_EN') }}<br>
{{m.venue.address_1}}, {{m.venue.city}}<br>
<a href="/meetup2/id{{m.id}}/">more</a>
{% endfor %}

4. Custom Post Types: twig-code

<a href="https://www.google.com/maps?q={{venue.lat}}+{{venue.lon}}" target="_blank">{{venue.address_1}}, {{venue.city}}</a>
Anmerkung: {{how_to_find_us}}
<a href="{{link}}" target="_blank">more on meetup.com</a>
<a href="/list-of-meetups/">overview on current meetups</a>

5. Shortcode for generating page:

[jsoncontentimporterpro url=http://api.json-content-importer.com/extra/json/meetup/1.json id=NUMBER_OF_TEMPLATE_POINT_3 DEAKdebugmode=10 mode=create createoptions='{"type":"meetup1", "loop":"", "title":"{{name}}", "slugname": "id{{id}}", "deleteold":"yes","customfields": #BRO# {"field1":"value1"}, {"field2{{id}}":"date{{#SQM#now#SQM#|date(#SQM#mdY#SQM#)}}"}#BRC#}']

6. WordPress.org Plugin Repository: Cron-Plugins

API: santannaenergyservices.com

A Job for the PRO plugin is displaying and selecting data from the santannaenergyservices.com API.

Step 1 is creating a plugin-template with this twig-template (instead of concatenating the output you might push it directly)

{% set txt = "" %}
{% for m in model %}
{% set txt = txt ~ "<br>productId: " ~ m.productId%}
{% for r in m.rateScheduleList %}
{% set txt = txt ~ "<br>rateScheduleId: " ~ r.rateScheduleId%}
{% for rsl in r.rateSegmentList if  (rsl.rateSegmentTerm matches '/18 Months/i' ) %}
{% set txt = txt ~ "<br>rateSegmentId: " ~ rsl.rateSegmentId %}
{% for rsdl in rsl.rateSegmentDetailList%}
{% set txt = txt ~ "<br>segmentDetailId: " ~ rsdl.segmentDetailId ~ ", " ~ rsdl.chargeType %}
{% endfor %}
{% endfor %}
{% endfor %}
{% set txt = txt ~ "<hr>" %}
{% endfor %}



Save the plugin-template and remember the number of the template.
Add this shortcode to an page:

[jsoncontentimporterpro id=NUMBER_OF_TEMPLATE]

This should show you that:

productId: 74
rateScheduleId: 306
rateSegmentId: 306
segmentDetailId: 532, Electric Charges
segmentDetailId: 533, Service Account Charge

productId: 58
rateScheduleId: 164
rateScheduleId: 165
rateScheduleId: 166
rateScheduleId: 167
rateScheduleId: 168
rateScheduleId: 169
rateScheduleId: 170

Free Plugin with JSON-example

One user asked for hints on using a JSON like this. The solution is quite simple:

Install the free JSON Content Importer Plugin and use this Shortcode:

[jsoncontentimporter url=http://api.json-content-importer.com/extra/json/blog/blockchain_2.json basenode=consumer_reviews_api]{subloop:params:-1}
params: {params.username}
trader: {trader.company_name}
review: {reviews.comments}<br>

See it in action:

The Block settings for that:

How to: urlparam4twig

You can define a urlparam4twig-list like “one#two” via the shortcode “urlparam4twig ” or (preferrably) the plugin-template.

This gives you the most flexible way to put a dynamic URL together for the API-call.

Create a template with this twig-code:

this is a template: <br>
time: {{ "now"|date("m.d.Y") }}<br>
urlparam "one": {{urlparam.one}}<br>
urlparam "two": {{urlparam.two}}


http://api.json-content-importer.com/extra/json/1.json?t={{ "now"|date("mdY") }}&a={{urlparam.one}}&b={{urlparam.two}}



Save this template and remember the no of the template, use this shortcode:

[jsoncontentimporterpro id=ID_OF_TEMPLATE]

Click here and see the change in the following paragraph. You might change the values for the parameters.
In the back the twig code in the URL is executed and the values for “one” and “two” are used.

this is a template:
urlparam "one":
urlparam "two":

API: raw.githubusercontent.com

Via wordpress.org the question came in on how to use raw.githubusercontent.com… (see also here) with the free plugin.

Here we go:

[jsoncontentimporter url=https://raw.githubusercontent.com/signorejambo/tank-stock/master/tank-life.json numberofdisplayeditems=-1 basenode=tank]
fish: {subloop-array:fish:-1}quantity: {fish.quantity}<br>{/subloop-array:fish}
plants: {subloop-array:plants:-1}species: {plants.species}<br>{/subloop-array:plants}

If you use the pro plugin this is the twig-template for that:

Continue reading “API: raw.githubusercontent.com”

API: clearmls.io – Sorting, Bearer

A request asked me, how to display data from the API clearmls.io sorted. One thing here is how to get access to the data. The other how to display that data.

Authentication at docs.clearmls.io
What the API expects is described here. At the free plugin you can set the API_KEY at the plugin setup. The free plugin can’t sort the json-data, but together with the Plugin TableSorter a sortable Table is possible, see here.

Authorization: Bearer API_KEY

With the pro plugin it’s like this:
Create a new pro plugin template with the following settings.
The “curloptions” set the http-header. “sortbyjsonfield” sorts for the latitude-values. When saving the template you get a TEMPLATE_ID of this template:

{% for i in properties | sortbyjsonfield("latitude,desc,num") %}
latitude: {{i.latitude}}, postal_code: {{i.postal_code}}<br>
{% endfor %}




Use the new TEMPLATE_ID in the shortcode on a page or post:

[jsoncontentimporterpro  id=TEMPLATE_ID]