1. Home
  2. Docs
  3. Emerald Stay Documentatio...
  4. Workflows
  5. Reservation Total Amounts Gross / NET Price:

Reservation Total Amounts Gross / NET Price:

Triggers:
Identifier is known.
Process:


First we check which cluster the reservation belongs to, based on the “Cluster” property, once the cluster is found out, we execute a code fragment that based on specific credentials for each cluster, makes a request to the Mews API, in order to obtain the gross or net amount of the cost of the reservation, this code fragment returns that amount to then be set in the “Amount” property of the specific deal.

exports.main = async (event, callback) => {

const axios = require("axios");

const custumersUrl = `https://app.mews.com/api/connector/v1/reservations/getAllItems`;

  try {
    let request = await axios.post(custumersUrl, {
      ClientToken:
        process.env.ClientToken,
      AccessToken:
        process.env.AccessTokenMarrakech,
      Client: "HubSpot CRM - Emerald Private Integration",
      ReservationIds: [event.inputFields['es_identifier']],
    });

    let netValue = 0;
    request.data.Reservations[0].OrderItems.map((a) => {
      netValue += a.Amount.NetValue;
    });
    
    callback({
    outputFields: {
      netValue,
    }
  });
  } catch (error) {
    console.log(error);
  }
}


Important HubSpot properties:
Amount.

How can we help?