title: How to: GET Data from 2 APIs, compare, POST bool
body: <p>I'm working on a project that requires me to:</p>
  
  <ol>
  <li><p>GET IDs from API1, push the IDs into an array, then map over those IDs, using them for a second GET request, where IDs are used as params for API2 GET request, populates an array with IDs or N for "Not existing" -- this array is then called in:</p></li>
  <li><p>A POST request. This post maps over the returned array from the GET request. IF the item is not "N", it POSTS to API1 with checked: true. IF the item is "N", it emails us telling us API2 is missing this project.</p></li>
  </ol>
  
  <p>I want this system to automatically do a GET and POST every 2 hours, so I'm using setInterval (not sure this is the best idea). EDIT: Cron job would be a better solution.</p>
  
  <p>I'm working with NodeJS, Express, Request-Promise, Async / Await.</p>
  
  <p>Here is some of my pseudo code so far:</p>
  
  <pre><code>// Dependencies
  const express = require('express');
  const axios = require('axios');
  const mailgun = require('mailgun-js')({ apiKey, domain });
  
  // Static
  const app = express();
  
  
  app.get('/', (req, res, next) =&gt; {
    // Replace setInterval with Cron job in deployment
  
    // Get All Ids
    const orders = await getGCloud();
  
    // Check if IDs exist in other API
    const validations = await getProjectManagementSystem(orders);
  
    // If they exist, POST update to check, else, mailer
    validations.map(id =&gt; {
      if (id !== 'n') {
        postGCloud(id);
      } else {
        mailer(id);
      }
    });   
  }
  
  // Method gets all IDs
  const getGCloud = async () =&gt; {
    try {
      let orders = [];
      const response = await axios.get('gCloudURL');
      for (let key in response) {
        orders.push(response.key);
      }
      return orders;
    } catch (error) {
      console.log('Error: ', error);
    }
  }
  
  // Method does a GET requst for each ID
  const getProjectManagementSystem = async orders =&gt; {
    try {
      let idArr = [];
      orders.map(id =&gt; {
        let response = await axios.get(`projectManagementSystemURL/${id}`);
        response === '404' ? idArr.push('n') : idArr.push(response)
      })
      return idArr;
    } catch (error) {
      console.log('Error: ', error);
    }
  }
  
  const postGCloud = id =&gt; {
    axios.post('/gcloudURL', {
      id,
      checked: true
    })
    .then(res =&gt; console.log(res))
    .catch(err =&gt; console.log(err))
  }
  
  const mailer = id =&gt; {
    const data = {
      from: 'TESTER &lt;test@test.com&gt;',
      to: 'customerSuppoer@test.com',
      subject: `Missing Order: ${id}`,
      text: `Our Project Management System is missing ${id}. Please contact client.`    
    }
  
    mailgun.messages().send(data, (err, body) =&gt; {
      if (err) {
        console.log('Error: ', err)
      } else {
        console.log('Body: ', body);
      }
    });
  }
  
  app.listen(6000, () =&gt; console.log('LISTENING ON 6000'));
  </code></pre>
  
  <p>The TL;DR: Need to do a GET request to API 1, then another GET request to API 2 following it (using IDs from API 1 as params), then send data from second GET to a POST request that then either updates API 1's data or emails Customer support. This is an automatic system that runs every two hours.</p>
  
  <p>Main Questions:
  1. Is it okay to have a setInterval in a get req?
  2. Can I have a GET request automatically call a POST request?
  3. If so, how can I pass GET request data onto a POST request?</p>