# API (DB replication, Email)

{% embed url="<https://guidejar.com/guides/a960084b-8de5-4b7c-88ca-896980a6ffd8>" %}

### Script Source (Table)

```typescript
var request = HttpUtil.get("https://randomuser.me/api");
var jsonContent = JsonUtil.parse(request.asString().getBody());
var user = jsonContent.get("results").get(0);

// Create a table to store the data
var table = SuiteTable.create("UsersTable");
table.addStringColumn("uuid");
table.addStringColumn("firstname");
table.addStringColumn("lastname");
table.addStringColumn("gender");
table.addStringColumn("country");
table.addStringColumn("city");
table.addStringColumn("email");
table.addStringColumn("phone");


// Populate the table with data from the API
var uuid = user.get("login").get("uuid").asText();
var firstname = user.get("name").get("first").asText();
var lastname = user.get("name").get("last").asText();
var gender = user.get("gender").asText();
var country = user.get("location").get("country").asText();
var city = user.get("location").get("city").asText();
var email = user.get("email").asText();
var phone = user.get("phone").asText();

var row = {
    "uuid": uuid,
    "firstname": firstname,
    "lastname": lastname,
    "gender": gender,
    "country": country,
    "city": city,
    "email": email,
    "phone": phone
};


table.addRow(row);

// Return the table
return table;
```

### DataPrep

#### Weather&#x20;

```typescript
var table = NodeInputReader.inputAsDataFrame();
var city = table.row(0).getString("city");

var request = HttpUtil.get("https://wttr.in/" + city + "?format=2");
var body = request.asString().getBody().trim();
```

### Send Email (Global SMTP)

*Email (property)*

```typescript
var table = NodeInputReader.inputAsDataFrame();
return table.row(0).getString("email");
```

*City (property)*

```typescript
var table = NodeInputReader.inputAsDataFrame();
return table.row(0).getString("city");
```

*FULL\_NAME (property)*

```typescript
var table = NodeInputReader.inputAsDataFrame();
var firstname = table.row(0).getString("firstname");
var lastname = table.row(0).getString("lastname");
return firstname + " " + lastname
```

*Weather (property)*

```typescript
var table = NodeInputReader.inputAsDataFrame();
return table.row(0).getString("weather");
```

#### General configuration

To:

`${EMAIL}`

Subject:

`Welcome to "Company", ${FULL_NAME}!`

Message:&#x20;

`Dear ${FULL_NAME},`

`Welcome to the "Company" family! We’re thrilled to have you join our team.`

`As you settle in, we hope the weather (${WEATHER}) in ${CITY} reflects the warmth and excitement we feel about having you onboard.`

`We believe that your skills and experiences will make a positive impact on our journey together. If you have any questions or need support as you get started, please don’t hesitate to reach out—we’re here to help.`

`Looking forward to meeting you in person and working together!`

`Warm regards, "Company" family`
