createWebhook method

Future<Map<String, dynamic>> createWebhook(
  1. String projectId, {
  2. required String name,
  3. required String url,
  4. required List<String> events,
  5. String description = '',
  6. String? action,
  7. String? payload,
})

Corresponds to: POST /accounts/projects/{project_id}/webhooks Body: { "name", "description", "url", "events" } Returns the JSON object the server responds with (could be empty or the new resource data).

Implementation

Future<Map<String, dynamic>> createWebhook(
  String projectId, {
  required String name,
  required String url,
  required List<String> events,
  String description = '',
  String? action,
  String? payload,
}) async {
  final uri = Uri.parse('$baseUrl/accounts/projects/$projectId/webhooks');
  final body = {'name': name, 'description': description, 'url': url, 'events': events, 'payload': payload, 'action': action};

  final response = await http.post(uri, headers: _getHeaders(), body: jsonEncode(body));

  if (response.statusCode >= 400) {
    throw MeshagentException(
      'Failed to create project webhook. '
      'Status code: ${response.statusCode}, body: ${response.body}',
    );
  }
  return jsonDecode(response.body) as Map<String, dynamic>;
}