updateWebhook method

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

Corresponds to: PUT /accounts/projects/{project_id}/webhooks/{webhook_id} Body: { "name", "description", "url", "events" } Returns the updated resource JSON or an empty object (depends on your server).

Implementation

Future<Map<String, dynamic>> updateWebhook(
  String projectId,
  String webhookId, {
  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/$webhookId');
  final body = {'name': name, 'description': description, 'url': url, 'events': events, 'payload': payload, 'action': action};

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

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