---
# System prepended metadata

title: UpSkillME lambda functions setup (updated)

---

# UpSkillME lambda functions setup (updated)

Ensure you have the below headed files saved in src/functions


## To run locally
To run locally, run the below in terminal 

export API_URL=https://api.airtable.com/v0/
export BASE_ID=*your BaseID*
export API_KEY=*your API key*

Then:

npm run lambda-build
npm run lambda-serve


## GetUserData.js

```
const axios = require("axios");

exports.handler = (event, context, callback) => {
    console.log("this is the event2", event.queryStringParameters.email);
    // console.log("this is the event3", event.queryStringParameters);
    // console.log("this is the event", context);
    // console.log("this is the event", event);

    let parsedEmail = JSON.parse(event.queryStringParameters.email);
    console.log("this is the one boys", parsedEmail);

    const { API_URL, BASE_ID, API_KEY } = process.env;
    const SEARCH_FILTER = `&filterByFormula={schoolEmail}=`;
    const SEARCH_INPUT = `"${parsedEmail}"`;
    const URL = `${API_URL}${BASE_ID}${API_KEY}${SEARCH_FILTER}${SEARCH_INPUT}`;

    const send = body => {
        console.log('about to send body', body)
        callback(null, {
            statusCode: 200,
            headers: {
                "Access-Control-Allow-Origin": "*",
                "Access-Control-Allow-Headers":
                    "Origin, X-Requested-With, Content-Type, Accept"
            },
            body: JSON.stringify(body)
        });
    };

    const getUserData = () => {
        axios
            .get(URL)
            .then(res => {
                console.log('axios request ', res);
                send(res.data);
            })

            .catch(err => send(err));
    };

    // if (event.httpMethod == "GET") {
    console.log('about to make getUserData request')
    console.log(URL);
    getUserData();
    // } else {
    //     console.error(`Expected get request, but recieved ${event.httpMethod}`);
    // }
};
```

## CreateUserActivity.js

```

const axios = require("axios");

exports.handler = (event, context, callback) => {
    const { API_URL, BASE_ID, API_KEY } = process.env;
    const data = JSON.parse(event.queryStringParameters.activityData);
    const URL = `${API_URL}${BASE_ID}${API_KEY}`;

    const send = body => {
        callback(null, {
            statusCode: 200,
            headers: {
                "Access-Control-Allow-Origin": "*",
                "Access-Control-Allow-Headers":
                    "Origin, X-Requested-With, Content-Type, Accept"
            },
            body: JSON.stringify(body)
        });
    };

    const createUserActivity = () => {
        axios
            .post(URL, data)
            .then(res => send(res.data))
            .catch(err => send(err));
    };

    // We expected this to be a post request, but it is a get request.
    // Need to investigate why.
    if (event.httpMethod == "GET") {
        createUserActivity();
    } else {
        console.error(`Expected get request, but recieved ${event.httpMethod}`);
    }
};


```

## APICall.js

```
const axios = require("axios");

exports.handler = (event, context, callback) => {
  const { API_URL, BASE_ID, API_KEY } = process.env;
  const URL = `${API_URL}${BASE_ID}${API_KEY}`;

  const send = body => {
    callback(null, {
      statusCode: 200,
      headers: {
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Headers":
          "Origin, X-Requested-With, Content-Type, Accept"
      },
      body: JSON.stringify(body)
    });
  };

  const getMockData = () => {
    axios
      .get(URL)
      .then(res => send(res.data))
      .catch(err => send(err));
  };

  if (event.httpMethod == "GET") {
    getMockData();
  } else {
    console.error(`Expected get request, but recieved ${event.httpMethod}`);
  }
};

```


### GetOpportunitiesData.js

```
const axios = require("axios");

exports.handler = (event, context, callback) => {
    const { API_URL, OPPS_ID, API_KEY } = process.env;
    const URL = `${API_URL}${OPPS_ID}${API_KEY}`;

    const send = body => {
        callback(null, {
            statusCode: 200,
            headers: {
                "Access-Control-Allow-Origin": "*",
                "Access-Control-Allow-Headers":
                    "Origin, X-Requested-With, Content-Type, Accept"
            },
            body: JSON.stringify(body)
        });
    };

    const getOppsData = () => {
        axios
            .get(URL)
            .then(res => send(res.data))
            .catch(err => send(err));
    };

    if (event.httpMethod == "GET") {
        getOppsData();
    } else {
        console.error(`Expected get request, but recieved ${event.httpMethod}`);
    }
};

```