We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

GET REST API Info into template

How Do I?

jeffmace's avatar
jeffmace
120 posts
2 years ago
jeffmace's avatar jeffmace

I am not a php developer so I can’t really save a template as php and do php code. I am not sure what the REQUEST function does and if that is a solution. This is a new site and I am using EE7. If I need to make a simple call to get info via a REST GET on a product ID and want to parse it in my template, what is the best way to do this?

       
jeffmace's avatar
jeffmace
120 posts
2 years ago
jeffmace's avatar jeffmace

Anyone have any suggestions on how to do this in the template? Do a simple GET that returns some JSON that can then be parsed directly in the template?

       
bthx79's avatar
bthx79
9 posts
2 years ago
bthx79's avatar bthx79

Hello!

I have been using an old json plugin that was designed for EE version 3. So far it has been working very well on EE Version 7

https://github.com/ahmmadsaleh86/Json-Plugin (After downloading, you need to put the plugin files in the correct folder structure for the newer versions of EE:)

/system/user/addons/json/pi.json.php
/system/user/addons/json/addon.setup.php

Here is a quick example of how I am using it:

My remote JSON Data - via a public GET URL/endpoint:

{
"ref": "14300",
"field12": "1993-02-23 00:00",
"field8": "title content in here",
"field10": "the author",
"field3": "",
"order_by": "50",
"total_hit_count": "1844"
},

EE Template Code:

{exp:json ref='https://myremoteapiurlhere/api/collection_recent/153/' fields="ref field8 field10 field12" limit="6"}
     <div class="col-lg-2 col-sm-6 sm-mb-30">
         <div class="about-mission-box white-bg h-100">
         <a href="/resources/pages/view.php?ref={ref}">_            <div class="content">_              <h6>{field8}</h6>_              <?php $date='{field12}'; if ($date) { echo date("F j, Y", strtotime($date)); } ?>_            </div>_            </a>
         </div>
     </div>
{/exp:json}

Note how you tell the plugin which key-value pairs to fetch from the payload, you then use those as variables in your code which is really handy! I enabled PHP in my template so I could modify the date to suit my needs.

Template caching helps with performance if you need to parse and render many items.

A newer, more advanced json plugin is also available. I haven’t had any personal experience with it yet.

https://devot-ee.com/add-ons/ee-json-output (I haven’t had any experience with it yet)

Best Regards,

Brian

       
Scigigive's avatar
Scigigive
2 posts
about 2 years ago
Scigigive's avatar Scigigive

If you are using ExpressionEngine 7 and want to make a REST GET request to retrieve information on the product ID and parse that information in your template, you can consider using the ExpressionEngine add-on, check if there are any existing EE7 compatible add-ons that support making REST API calls. The ExpressionEngine community and the official add-ons directory bitlife are good places to start looking.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.