title: How to get all event data from Ticketmaster's open API?
body: <p>I am trying to get all event information from Ticketmaster's API and add specific variables to mongoDB. However, the APIs' that I am currently using are limited to 200 events per page. It is therefore not possible for me to connect the event information with venue information since these are added seperately to mongoDB. One solution would maybe be to loop through all the pages by changing the page parameter in the API-url, or maybe there are other options? </p>
  
  <p>My code looks like this (sorry about the length..): </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>app.get('/tm', (req, res) =&gt; {
    axios // getting venues
      .get('https://app.ticketmaster.com/discovery/v2/venues.json?apikey=myApiKey&amp;page=0&amp;size=200&amp;countryCode=DK')
      .then(response =&gt; {
        const venuesToBeInserted = response.data._embedded.venues.map(venue =&gt; { // preparing venues
          return {
            sourceID: venue.id,
            venue: venue.name,
            postalCode: venue.postalCode,
            city: venue.city.name,
            country: venue.country.name,
            countryCode: venue.country.countryCode,
            address: !!venue.address ? venue.address.line1 : null,
            longitude: !!venue.location ? venue.location.longitude : null,
            latitude: !!venue.location ? venue.location.latitude : null,
            source: 'ticketmaster'
          }
        })
  
        // Create all venues at once
        Venue.create(venuesToBeInserted).then(venues =&gt; {
          console.log("venues inserted")
  
          axios // getting events and shows - note the page parameter in the api link
          .get('https://app.ticketmaster.com/discovery/v2/events.json?apikey=myApiKey&amp;countryCode=DK&amp;size=200&amp;page=0')
          .then(response =&gt; {
            const eventsToBeInserted = response.data._embedded.events.map(events =&gt; { // preparing events
              const event = events._embedded.attractions[0]
              return {
                sourceID: event.id,
                name: event.name,
                slug: slugify(event.name).toLowerCase(),
                tags: !!event.classifications ? [event.classifications[0].genre.name, event.classifications[0].subGenre.nam] : [], // duplicate genres occur
                // possible tags from ticketmaster: type and subtype
              }
            })
  
            // Create all events at once
              Event.create(eventsToBeInserted).then(events =&gt; {
                console.log("events inserted")
  
                const showsToBeInserted = response.data._embedded.events.map(show =&gt; {
                  const event = events.find(event =&gt; event.sourceID == show._embedded.attractions[0].id);
                  const venue = venues.find(venue =&gt; venue.sourceID == show._embedded.venues[0].id);
  
                  if (!!event &amp;&amp; !!venue) {
                    return {
                      event: event._id,
                      venue: venue._id,
                      timezone: show.dates.timezone,
                      dateStart: !!show.dates.start.dateTime ? show.dates.start.dateTime : show.dates.start.localDate,
                      tickets: !!show.priceRanges ? {
                        minPrice: show.priceRanges[0].min,
                        maxPrice: show.priceRanges[0].max,
                        currency: show.priceRanges[0].currency
                      }: {} 
                    }
                  }
                })
                 // Let's see what we have created in the database
                  Venue.find({}).select({
                    name: 1,
                    slug: -1
                  }).limit(10).populate('event').populate('venue').then(events =&gt; {
                    console.log(util.inspect(events));
                  }).catch(err =&gt; {
                    console.error(err);
                  });
               }).catch( err =&gt; {
                 console.error(err)
               })
  
              }).catch( err =&gt; {
                console.error(err)
              })
          }).catch(err =&gt; {
            console.error(err)
        });
      }).catch(err =&gt; {
    console.error(err)
    })
  })</code></pre>
  </div>
  </div>
  </p>