The getFileContent() GraphQL query is used to get contents of a CSV file.

See the newFile() for information creating a new file, and updateFile() for updating data in an already uploaded or created file. You might also want to see the Lookup Files documentation page, if that's related to your reason for uploading a file.

Syntax

Below is the syntax for the getFileContent() query field:

graphql
getFileContent(
     name: string!
     fileName: string!
     filterString: string
     offset: integer
     limit: integer
   ): UploadedFileSnapshot!

For the input, there are several parameters, with the the basic datatypes of strings and integers. They're described in the Given Datatypes section below. What to use for the return, for UploadedFileSnapshot is listed in the Results Datatypes section. Below is an example with fictitious data.

Raw
graphql
query {
  getFileContent(
    fileName: "test.csv", 
    name: "humio", 
    filterString: "Barbara"
  )
  { nameAndPath{name, path}, 
    totalLinesCount,
    headers, lines
  }
}
Mac OS or Linux (curl)
shell
curl -v -X POST $YOUR_LOGSCALE_URL/graphql \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -d @- << EOF
{"query" : "query {
  getFileContent(
    fileName: \"test.csv\", 
    name: \"humio\", 
    filterString: \"Barbara\"
  )
  { nameAndPath{name, path}, 
    totalLinesCount,
    headers, lines
  }
}"
}
EOF
Mac OS or Linux (curl) One-line
shell
curl -v -X POST $YOUR_LOGSCALE_URL/graphql \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -d @- << EOF
{"query" : "query {
  getFileContent(
    fileName: \"test.csv\", 
    name: \"humio\", 
    filterString: \"Barbara\"
  )
  { nameAndPath{name, path}, 
    totalLinesCount,
    headers, lines
  }
}"
}
EOF
Windows Cmd and curl
shell
curl -v -X POST $YOUR_LOGSCALE_URL/graphql ^
    -H "Authorization: Bearer $TOKEN" ^
    -H "Content-Type: application/json" ^
    -d @'{"query" : "query { ^
  getFileContent( ^
    fileName: \"test.csv\",  ^
    name: \"humio\",  ^
    filterString: \"Barbara\" ^
  ) ^
  { nameAndPath{name, path},  ^
    totalLinesCount, ^
    headers, lines ^
  } ^
}" ^
} '
Windows Powershell and curl
powershell
curl.exe -X POST 
    -H "Authorization: Bearer $TOKEN"
    -H "Content-Type: application/json"
    -d '{"query" : "query {
  getFileContent(
    fileName: \"test.csv\", 
    name: \"humio\", 
    filterString: \"Barbara\"
  )
  { nameAndPath{name, path}, 
    totalLinesCount,
    headers, lines
  }
}"
}'
"$YOUR_LOGSCALE_URL/graphql"
Perl
perl
#!/usr/bin/perl

use HTTP::Request;
use LWP;

my $INGEST_TOKEN = "TOKEN";

my $uri = '$YOUR_LOGSCALE_URL/graphql';

my $json = '{"query" : "query {
  getFileContent(
    fileName: \"test.csv\", 
    name: \"humio\", 
    filterString: \"Barbara\"
  )
  { nameAndPath{name, path}, 
    totalLinesCount,
    headers, lines
  }
}"
}';
my $req = HTTP::Request->new("POST", $uri );

$req->header("Authorization" => "Bearer $TOKEN");
$req->header("Content-Type" => "application/json");

$req->content( $json );

my $lwp = LWP::UserAgent->new;

my $result = $lwp->request( $req );

print $result->{"_content"},"\n";
Python
python
#! /usr/local/bin/python3

import requests

url = '$YOUR_LOGSCALE_URL/graphql'
mydata = r'''{"query" : "query {
  getFileContent(
    fileName: \"test.csv\", 
    name: \"humio\", 
    filterString: \"Barbara\"
  )
  { nameAndPath{name, path}, 
    totalLinesCount,
    headers, lines
  }
}"
}'''

resp = requests.post(url,
                     data = mydata,
                     headers = {
   "Authorization" : "Bearer $TOKEN",
   "Content-Type" : "application/json"
}
)

print(resp.text)
Node.js
javascript
const https = require('https');

const data = JSON.stringify(
    {"query" : "query {
  getFileContent(
    fileName: \"test.csv\", 
    name: \"humio\", 
    filterString: \"Barbara\"
  )
  { nameAndPath{name, path}, 
    totalLinesCount,
    headers, lines
  }
}"
}
);


const options = {
  hostname: '$YOUR_LOGSCALE_URL/graphql',
  path: '/graphql',
  port: 443,
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Content-Length': data.length,
    Authorization: 'BEARER ' + process.env.TOKEN,
    'User-Agent': 'Node',
  },
};

const req = https.request(options, (res) => {
  let data = '';
  console.log(`statusCode: ${res.statusCode}`);

  res.on('data', (d) => {
    data += d;
  });
  res.on('end', () => {
    console.log(JSON.parse(data).data);
  });
});

req.on('error', (error) => {
  console.error(error);
});

req.write(data);
req.end();
Example Responses
Success (HTTP Response Code 200 OK)
json
{
  "data": {
    "getFileContent": {
      "nameAndPath": {
        "name": "test.csv",
        "path": null
      },
      "totalLinesCount": 1,
      "headers": [
        "id",
        "first",
        "last"
      ],
      "lines": [
        [
          "6",
          "Barbara",
          "Mills"
        ]
      ]
    }
  }
}

This example is gets the file from the repository, and returns rows containing the search text given for filterString. It also returns the name and path of the file, and the number of rows found — which is only one here. And it returns the data found matching the search text.

Given Datatypes

The given datatypes are described in the table below:

Table: Mix of Input for getFileContent

ParameterTypeRequiredDefaultDescription
Some arguments may be required, as indicated in the Required column. For some fields, this column indicates that a result will always be returned for this column.
Table last updated: Sep 10, 2024
namestringyes The name of the repository associated with the file.
fileNamestringyes The name of the uploaded or created file.
filterStringstring  Case-insensitive text on which to search the row.
limitinteger 50The maximum number of rows to return from the file.
offsetinteger 0The initial number of rows to skip; display only rows after number given.

Returned Datatypes

The returned datatype UploadedFileSnapshot has its own parameters. Below is a list of them along with their datatypes and a description of each:

Table: UploadedFileSnapshot

ParameterTypeRequiredDefaultDescription
Some arguments may be required, as indicated in the Required column. For some fields, this column indicates that a result will always be returned for this column.
Table last updated: Oct 4, 2024
filterStringstring  Any string on which to filter the data.
headers[string]yes The headers for the uploaded snapshot file.
limitintegeryes The file upload limit.
lines[string]yes The contents of the file in the form of a list of lines, with each line being itself a list of column values. When the file is empty or nothing matches filterString, then [] is returned.
nameAndPathFileNameAndPathyes The name and path of the uploaded snapshot file. See FileNameAndPath.
offsetintegeryes This is the offset supplied to a file query. For a new or updated file, this is always 0.
totalLinesCountlongyes The total number of lines in the uploaded snapshot file.