Working on ranging over a remote data file in a shortcode. Here’s the shortcode.
{{ $reviews := getJSON "https://api.app.outscraper.com/maps/reviews-v3?query=ChIJU7-Ou0Mp1IcReeTe5L195C4&reviewsLimit=3&async=false" (dict "X-API-KEY" "APIKEY") }}
<div class="reviews-slider disable-scrollbars">
{{ $reviewsData := $reviews.data }}
{{ range $reviewsData.reviews_data}}
<div id="_review8" itemprop="review" itemscope itemtype="http://schema.org/Review" class="review">
<p class="rev-text "> <span itemprop="reviewBody"> {{ .review_text }} </span> </p>
<div class="rating">
<img src="/images/star.svg" alt="star rating">
<img src="/images/star.svg" alt="star rating">
<img src="/images/star.svg" alt="star rating">
<img src="/images/star.svg" alt="star rating">
<img src="/images/star.svg" alt="star rating">
</div>
<span itemprop="author" itemscope itemtype="http://schema.org/Person"><span itemprop="name"><h5 class="rev-name"> {{ .author_title }} </h5></span></span>
<p class="rev-date"> {{ .review_timestamp }} </p>
<p hidden> {{ .review_rating }}</p>
</div>
{{end}}
</div>
</div>```
Here's the JSON that is returned from the API.
{
“id”: “f198f77d-dbed-439b-bddc-e5b7f7eeaa01”,
“status”: “Success”,
“data”: [
{
“query”: “ChIJU7-Ou0Mp1IcReeTe5L195C4”,
“name”: “Foothills Overhead Doors LLC”,
“full_address”: “135 Leggett St, Jonesboro, AR 72401, United States”,
“borough”: null,
“street”: “135 Leggett St”,
“postal_code”: “72401”,
“area_service”: false,
“country_code”: “US”,
“country”: “United States of America”,
“city”: “Jonesboro”,
“us_state”: “Arkansas”,
“state”: “Arkansas”,
“plus_code”: “867FR8V5+JQ”,
“latitude”: 35.8441166,
“longitude”: -90.690511,
“time_zone”: “America/Chicago”,
“popular_times”: null,
“site”: “https://foothillsoverheaddoors.com/”,
“phone”: “+1 870-275-9899”,
“type”: “Garage door supplier”,
“logo”: “https://lh3.googleusercontent.com/-6ri2MEKBlDw/AAAAAAAAAAI/AAAAAAAAAAA/5YxOuumrRKA/s44-p-k-no-ns-nd/photo.jpg”,
“description”: “garage door and overhead door sales and service”,
“located_in”: “Citadel Mini Storage”,
“located_google_id”: “0x87d42943c315daa1:0xc4b81ceb52fc7a59”,
“category”: “Garage door supplier”,
“subtypes”: “Garage door supplier, Home improvement store”,
“posts”: null,
“reviews_tags”: [
“price”,
“job”
],
“rating”: 5,
“reviews”: 34,
“reviews_data”: [
{
“review_id”: “ChdDSUhNMG9nS0VJQ0FnSURPMGNYNXRBRRAB”,
“author_link”: “Google Maps”,
“author_title”: “Scott Levins”,
“author_id”: “100324155557654257023”,
“author_image”: “https://lh3.googleusercontent.com/a-/ACNPEu_Fr-7510S3Bs-1zS-NkGcPjAdx8V7l-PhSnQbT=s120-c-c0x00000000-cc-rp-mo-br100”,
“review_text”: “Called Foothills with my problem, which was a bit more involved than I initially thought. Was told however it could still be fixed. Tony came out, and in no time had it fixed, and fixed what caused the problem. And he did it for less than the initial estimate. Professional, quick, and great price. I highly recommend!”,
“review_img_url”: “https://lh3.googleusercontent.com/a-/ACNPEu_Fr-7510S3Bs-1zS-NkGcPjAdx8V7l-PhSnQbT”,
“owner_answer”: “Happy to be of service!”,
“owner_answer_timestamp”: 1665843455,
“owner_answer_timestamp_datetime_utc”: “10/15/2022 14:17:35”,
“review_link”: “Google Maps”,
“review_rating”: 5,
“review_timestamp”: 1657221109,
“review_datetime_utc”: “07/07/2022 19:11:49”,
“review_likes”: 0
},
{
“review_id”: “ChdDSUhNMG9nS0VJQ0FnSUMyMS1lSnZBRRAB”,
“author_link”: “Google Maps”,
“author_title”: “Amber Stokes”,
“author_id”: “116704952676373942948”,
“author_image”: “https://lh3.googleusercontent.com/a-/ACNPEu8S7a8qSqeBsngia1SY9MuQcZqbJeOONBg7VRKh0Q=s120-c-c0x00000000-cc-rp-mo-ba4-br100”,
“review_text”: “These folks are GREAT! They took the time to repair my garage door TWICE and then told me honestly, that I needed to replace it as the fix simply wasn’t going to hold. The price on the new garage door was WAY lower than I expected! Fast service, friendly technicians, and great prices!”,
“review_img_url”: “https://lh3.googleusercontent.com/a-/ACNPEu8S7a8qSqeBsngia1SY9MuQcZqbJeOONBg7VRKh0Q”,
“owner_answer”: “Thank you! for being one of our valued customers. You have been a wonderful customer!”,
“owner_answer_timestamp”: 1653007431,
“owner_answer_timestamp_datetime_utc”: “05/20/2022 00:43:51”,
“review_link”: “Google Maps”,
“review_rating”: 5,
“review_timestamp”: 1651333106,
“review_datetime_utc”: “04/30/2022 15:38:26”,
“review_likes”: 1
},
{
“review_id”: “ChdDSUhNMG9nS0VJQ0FnSUMteVB2OXZnRRAB”,
“author_link”: “Google Maps”,
“author_title”: “Rice Man”,
“author_id”: “103649495941586242465”,
“author_image”: “https://lh3.googleusercontent.com/a-/ACNPEu81d8QJdyG2aWi8MYJkem1vke2jhxXNcWRQx42Hjg=s120-c-c0x00000000-cc-rp-mo-br100”,
“review_text”: “Foothills Overhead Door are my go to service group. Honest and dependable. Thanks guys!!”,
“review_img_url”: “https://lh3.googleusercontent.com/a-/ACNPEu81d8QJdyG2aWi8MYJkem1vke2jhxXNcWRQx42Hjg”,
“owner_answer”: “We appreciate you and your business! Joe”,
“owner_answer_timestamp”: 1666742137,
“owner_answer_timestamp_datetime_utc”: “10/25/2022 23:55:37”,
“review_link”: “Google Maps”,
“review_rating”: 5,
“review_timestamp”: 1666741261,
“review_datetime_utc”: “10/25/2022 23:41:01”,
“review_likes”: 0
}
],
“photos_count”: 11,
“google_id”: “0x87d42943bb8ebf53:0x2ee47dbde4dee479”,
“cid”: “3378963874976818297”,
“place_id”: “ChIJU7-Ou0Mp1IcReeTe5L195C4”,
“reviews_link”: “Redirecting”,
“reviews_id”: “3378963874976818297”,
“photo”: “https://lh5.googleusercontent.com/p/AF1QipN7_IB7B9ai0jw3o9bWBKULUBKPr9jXGp1lseg6=w800-h500-k-no”,
“street_view”: “https://streetviewpixels-pa.googleapis.com/v1/thumbnail?panoid=VAIRp15p2ikREpngBkoF2w&cb_client=search.gws-prod.gps&w=1600&h=1000&yaw=270.15305&pitch=0&thumbfov=100”,
“working_hours_old_format”: “Monday: 8AM-5PM | Tuesday: 8AM-5PM | Wednesday: 8AM-5PM | Thursday: 8AM-5PM | Friday: 8AM-5PM | Saturday: Closed | Sunday: Closed”,
“working_hours”: {
“Monday”: “8AM-5PM”,
“Tuesday”: “8AM-5PM”,
“Wednesday”: “8AM-5PM”,
“Thursday”: “8AM-5PM”,
“Friday”: “8AM-5PM”,
“Saturday”: “Closed”,
“Sunday”: “Closed”
},
“other_hours”: null,
“business_status”: “OPERATIONAL”,
“about”: {
“Service options”: {
“Online estimates”: true,
“On-site services”: true
},
“Planning”: {
“Appointment required”: true
}
},
“range”: null,
“reviews_per_score”: {
“1”: 0,
“2”: 0,
“3”: 0,
“4”: 0,
“5”: 34
},
“reservation_links”: null,
“booking_appointment_link”: “Contact Foothills Overhead Doors in Jonesboro, AR”,
“menu_link”: null,
“order_links”: null,
“owner_id”: “118341862776511540210”,
“verified”: true,
“owner_title”: “Foothills Overhead Doors LLC”,
“owner_link”: “Google Maps”,
“location_link”: “Google Maps”
}
]
}
What I'm trying to do is range over the reviews.data to populate the shortcode. When I try to do this, it throws a `Error: Error building site: "C:\Users\marcl\Documents\Web Dev\Foothills Overhead Doors\content\reviews\index.html:11:3": failed to render shortcode "reviews": failed to process shortcode: "C:\Users\marcl\Documents\Web Dev\Foothills Overhead Doors\layouts\shortcodes\reviews.html:6:22": execute of template failed: template: shortcodes/reviews.html:6:22: executing "shortcodes/reviews.html" at <$reviewsData.reviews_data>: can't evaluate field reviews_data in type []interface {}`
I was thinking that I need to use bracket notation to access the inside of the array, but when I use {{ $reviewsData := $reviews.data[0], it throws another error saying that the brackets are a bad character. Is there any way to do this? Since it's a remote file, I can't manipulate the format. Thanks in advance!