How to use the netlify.methods.forEach function in netlify

To help you get started, we’ve selected a few netlify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github netlify / cli / src / commands / api.js View on Github external
const { api } = this.netlify
    const { args, flags } = this.parse(APICommand)

    const { apiMethod } = args

    await this.config.runHook('analytics', {
      eventName: 'command',
      payload: {
        command: 'api'
      }
    })

    if (isEmptyCommand(flags, args) || flags.list) {
      const table = new AsciiTable(`Netlify API Methods`)
      table.setHeading('API Method', 'Docs Link')
      methods.forEach(method => {
        const { operationId } = method
        table.addRow(operationId, `https://open-api.netlify.com/#/operation/${operationId}`)
      })
      this.log(table.toString())
      this.log()
      this.log('Above is a list of available API methods')
      this.log(`To run a method use "${chalk.cyanBright('netlify api methodName')}"`)
      this.exit()
    }

    if (!apiMethod) {
      this.error(`You must provide an API method. Run "netlify api --list" to see available methods`)
    }

    if (!api[apiMethod] || typeof api[apiMethod] !== 'function') {
      this.error(`"${apiMethod}"" is not a valid api method. Run "netlify api --list" to see available methods`)