Skip to main content
All CollectionsPortal-X Pages
Design | Cloud Code | Web Services
Design | Cloud Code | Web Services

Declare external services that your cloud code scripts would like to use

Jason Liang avatar
Written by Jason Liang
Updated over 9 months ago

Web services allow you to make HTTP requests to external third-party websites.
For security reasons, the external services must be configured on brainCloud.

To get started, navigate to the Web Services page on the brainCloud portal.

  • Click [+New WebService] to show the Add Hook interface and fill out the essential fields, then Save.

  • Then you can call HttpClient APIs To communicate with this service. There are several API request types available on the brainCloud system.

  • Or write a could code for your web service as well if you want, see the code example below:

// GetWeather script - takes the following parameters
// location - location to get the weather for - example "Ottawa, Canada"
// API key from WorldWeatherOnline.com
var key = "841664cedf0942afbe5164953200505";
// Path to the api method
var path = "free/v2/weather.ashx";
// Retrieve the HTTP Client proxy
var httpClientService = bridge.getHttpClientServiceProxy();
// Construct the query parameters (they will be automatically encoded in the URL)
var queryMap = {
"q": data.location,
"num_of_days": 1,
"format": "json",
"key": key
};
// No need to send anything specific in the headers
var headers = {};
// Make the request

var result = httpClientService.getResponseJson("getWeather", path, queryMap, headers);//make sure the name of Service match the one added at web services.

// Return the results
var retval = null;
if (result.status === 200)
{
retval = result.data.json.data;
//if use getResponseText instead of using getResponseJson, need change here accordingly
//retval = result.data.text;
}
retval;
  • Then you can call this script on your client app, or from an external browser, postman, or whatever tools you prefer.

Did this answer your question?