diff --git a/src/Encoder/CsvEncoder.php b/src/Encoder/CsvEncoder.php
index 35f62a8..0ef2539 100644
--- a/src/Encoder/CsvEncoder.php
+++ b/src/Encoder/CsvEncoder.php
@@ -175,15 +175,17 @@ class CsvEncoder implements EncoderInterface, DecoderInterface {
     if (!empty($data)) {
       $first_row = $data[0];
       $allowed_headers = array_keys($first_row);
-
-      $fields = $context['views_style_plugin']
-        ->view
-        ->getDisplay('rest_export_attachment_1')
-        ->getOption('fields');
-
-      foreach ($allowed_headers as $allowed_header) {
-        $headers[] = !empty($fields[$allowed_header]['label']) ? $fields[$allowed_header]['label'] : $allowed_header;
+      if (!empty($context['views_style_plugin'])) {
+        $fields = $context['views_style_plugin']
+          ->view
+          ->getDisplay('rest_export_attachment_1')
+          ->getOption('fields');
+
+        foreach ($allowed_headers as $allowed_header) {
+          $headers[] = !empty($fields[$allowed_header]['label']) ? $fields[$allowed_header]['label'] : $allowed_header;
+        }
       }
+
     }
 
     return $headers;
