Having trouble retrieving information from the SeatGeek API

I am currently working on retrieving data from the SeatGeek API when a user inputs a performer's name. To test my API key, I have been manually entering the query string into the URL. For example:

https://api.seatgeek.com/2/events?performers.slug=new-york-mets&client_id=MY_CLIENT_ID

This method works well as it returns a JSON with information about New York Mets events such as total count, page number, and event details.

On the server side, I handle fetching data through a POST request to /events:

app.post('/events', function(req, res) {
  let band = req.body.bandName;
  band = band.split(' ').join('-')

  fetch(`https://api.seatgeek.com/2/events?performers.slug=${band}&client_id=MY_CLIENT_ID`)
    .then(function(data){
      res.json(data);
    }).catch(function(error){
      console.log(error);
    });
});

However, when I make the POST request I receive different data than expected, with an unfamiliar structure like:

{
  "url": "https://api.seatgeek.com/2/events?performers.slug=new-york-mets&client_id=OTk1Mzg2MXwxNTEzMTkwMDUyLjI3",
  "status": 200,
  "statusText": "OK",
  "headers": { ... },
  "body": { ... }

This has left me questioning if there is an issue with how I am handling the fetch request. Any insights would be greatly appreciated.

Answer №1

Explained here is the Response object obtained through the use of fetch within the then method.

The concept revolves around treating the Response as a continuous data stream, where complete access to the fetched API data requires reading the entire content of the Response stream.

In order to extract the JSON data retrieved, one must utilize the Body.json method, which is accessible to responses due to their implementation of the Body interface:

fetch(`https://api.seatgeek.com/2/events?performers.slug=${band}&client_id=MY_CLIENT_ID`)
  .then(function(response) {
    return response.json();
  }).then(function(json) {
    res.json(json);
  }).catch(function(error) {
    console.log(error);
  });

Highlighted is the additional then. The invocation of response.json() marks the end of reading the Response stream and triggers a promise that resolves upon exhaustion of the stream, delivering the JSON content. The initial then block awaits this JSON content before sending it from SeatGeek to your own API's user in the subsequent then section.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Exploring the MUI Data Grid: A Step-by-Step Guide to Adding a Summary Row

Need help with adding a summary row to my Data Table from MUI. You can find the documentation here or visit the main website here. I have tried to implement the summary row but I am facing some challenges. Any suggestions or ideas would be highly apprecia ...

Continuing to reference outdated JSON data even after refreshing the page, instead of utilizing the most recent version

I have a query regarding JSON and JavaScript. I update the JSON file through a web page and save it to the server. However, when I visit the page where the information from the JSON should be displayed, it shows the old data even after refreshing. The upda ...

Having trouble getting the Node.js Loopback API to run properly when starting it with PM2

Here is a snippet of my pm2 ecosystem.config.js setup: HGBackend is currently not running in pm2, while the other apps are running smoothly. module.exports = { apps : [ { name : "HGBackend", cwd : "hgbackend/server", scrip ...

Unusual jQuery error notification

Short Receiving Error in syntax, unrecognized expression: [object Object] @ jquery.js:4267 This code snippet is from jQ: Sizzle.error = function( msg ) { throw new Error( "Error in syntax, unrecognized expression: " + msg ); // Line 4267 }; Detaile ...

Ways to continuously monitor an array until specific criteria are fulfilled

My goal is to search for a specific item in an array called idarray and loop through it until I find a value that is not equal to -1. Once I find that value, I want to use the index to retrieve the corresponding value from another array called array. To a ...

Using Vanilla JavaScript library in Angular 6 - A Comprehensive Guide

I encountered an error while trying to import a Vanilla JavaScript library into an Angular 6 component. Can you please provide me with some guidance on how to resolve this issue? This is the syntax I used to import the library: import * as ExistingLibrar ...

How can you implement a v-if directive in a Vue loop based on the maximum numerical value?

I am trying to display an element specifically for the cat with the most kittens, which in this scenario would be Bob: { "cats": [ {"name": "Tom", "kittens": [ {"name": "Dan"} ...

What could be preventing the fill color of my SVG from changing when I hover over it?

I am currently utilizing VueJS to design an interactive map showcasing Japan. The SVG I am using is sourced from Wikipedia. My template structure is illustrated below (The crucial classes here are the prefecture and region classes): <div> <svg ...

How to Manage Specific Types of Promise Rejections in Node.js?

I am exploring Node.JS and I have discovered the usefulness of the unhandledRejection event in capturing unhandled errors. Yet, I am specifically interested in catching a particular type of error. What is the best approach to achieve this selective handl ...

Eliminate viewed alerts by implementing a scrolling feature with the help of Jquery, Javascript, and PHP

My goal is to clear or remove notifications based on user scrolling. The idea is to clear the notification once the user has seen it, specifically in a pop-up window for notifications. I am relatively new to Javascript/jQuery and feeling a bit confused abo ...

Error encountered when sending information to web service repeatedly

After populating an array with data, the information is logged into a database using a web service when the array reaches a specific record count. However, upon calling the web service, I encountered an error related to a parameter being passed: Error Ty ...

Managing an indefinite amount of values within a PHP script

When submitting the data form, there will be a range of 10 to 100 values to be sent to the PHP file. The quantity of inputs is stored in a JavaScript function variable named count, but I am unsure of how to pass this value to the PHP file. One approach I ...

Is there a way to effortlessly upload numerous files in one go when browsing with jquery or JavaScript?

Currently working on a web application and looking to enable multiple file upload functionality within a single browse session, as opposed to selecting one file at a time. The goal is for users to be able to easily select multiple files with just one clic ...

What is the purpose of the setDrawRange function in the Three.js library?

I've been diving into a three.js codebase. While studying the code and the documentation, there's one thing that's puzzling me. In this particular code snippet. http://jsfiddle.net/w67tzfhx/ there exists the following piece of code. fun ...

Adjusting the height of a container dynamically in React while flex items wrap using CSS

In my React project, I have a container called "answers-container" with multiple buttons inside it, laid out using flexbox with flex-wrap: wrap to allow them to wrap onto the next line when the container width is exceeded. However, I'm facing an issu ...

Tag editor assessing the input's width for SO

I've been working on a tag editor similar to Stack Overflow's and it's coming along nicely. The only issue I'm facing is calculating the width of the textbox after a tag has been selected by the user. For each tag added, I try to adjus ...

Do not open iframe links in a new window

Is it possible to manipulate the iframe so that links open inside the iframe window? I want the links clicked within the iframe to stay within the same window instead of opening in a new one. However, I have too many links to individually edit their code ...

Guidelines for uploading an Android and iOS application that includes MySQL/PHP integration and packaging it with PhoneGap

I am developing an Android and iOS app using HTML, CSS, PHP to interact with MySQL database through JSON for integration with PhoneGap. All functionalities work smoothly on a browser, but I'm unsure how to upload the app and its server-side functions ...

What is the easiest way to create a star pattern using JavaScript?

I attempted the following code but the output is incorrect! for(i=5;i>=1;i--) { for(j=i;j>=1;j--){ console.log(j); } console.log("\n"); } ...

Can the arrangement of icons/buttons on the JW Player control bar be customized?

I am trying to customize the skin of my JWplayer like this: This is my current progress: I have been researching how to rearrange the order of icon / button on the controlbar. According to the jwplayer documentation, the buttons on the controlbar are div ...