# callFunction

Calls cloud function.

OBJECT parameter description

Parameter Type Required Description
name String Yes Cloud function name
data Object No Parameter passed to the cloud function

Description of Promise return result

Parameter Type Description Minimum Version
errMsg String General return result
result String Return result of cloud function call
requestID String The cloud function execution ID, used to query logs in the console 0.0.12

Sample code:

Suppose a cloud function add already exists:

exports.main = (event, context) => {
  return event.x + event.y
}

Call sample code:

const cloud = require('wx-server-sdk')
exports.main = async (event, context) => {
  const res = await cloud.callFunction({
    // The name of the cloud function to be called
    name: 'add',
    // Parameter to be passed to the cloud function
    data: {
      x: 1,
      y: 2,
    }
  })
  return res.result
}
点击咨询小助手