Integrate with external services

With Cloud Code, you can call out to any public internet endpoint, including the public APIs that are a part of UGS.

The following example demonstrates how to call out to a Cat Facts API to get a random cat fact.

JavaScript

const axios = require("axios-0.21");

module.exports = async ({ params, context, logger }) => {
  let result;
  try {
    const catFactUrl = `https://catfact.ninja/fact`;
    result = await axios.get(catFactUrl);

    return result.data;
  } catch (err) {
    logger.error("Failed to call out to Cat Facts", {"error.message": err.message});
    throw err;
  }
};

For more information, learn how to integrate with other Unity services.