Summary

The newFile() mutation creates a new lookup file in a LogScale repository or view. Lookup files are CSV-format tables that queries can reference for data enrichment — for example, mapping identifiers to readable names or IP addresses to hostnames. Provide the filename and the target repository or view name to create the file.

Supply the optional content argument to populate the file immediately with headers and row data. If you omit content, LogScale creates an empty file that you can populate later with updateFile(). Attach organizational labels at creation time with the optional labels argument.

Syntax

graphql
newFile(
      fileName: String!,
      name: String!,
      labels: [String!],
      content: NewFileContent
   ): UploadedFileSnapshot!

The fileName and name arguments are required. The optional content argument accepts a NewFileContent object with headers (the column names) and rows (an array of row strings, each containing the same number of columns as the headers). The optional labels argument attaches organizational labels to the file.

The return type UploadedFileSnapshot! is non-nullable. The mutation always returns a snapshot object on success, or an error on failure.

Example

Raw
graphql
mutation {
  newFile( 
     fileName: "somefile.csv",
     name: "humio",
  ) 
  { nameAndPath {path} }
}
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" : "mutation {
  newFile( 
     fileName: \"somefile.csv\",
     name: \"humio\",
  ) 
  { nameAndPath {path} }
}"
}
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" : "mutation {
  newFile( 
     fileName: \"somefile.csv\",
     name: \"humio\",
  ) 
  { nameAndPath {path} }
}"
}
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" : "mutation { ^
  newFile(  ^
     fileName: \"somefile.csv\", ^
     name: \"humio\", ^
  )  ^
  { nameAndPath {path} } ^
}" ^
} '
Windows Powershell and curl
powershell
curl.exe -X POST 
    -H "Authorization: Bearer $TOKEN"
    -H "Content-Type: application/json"
    -d '{"query" : "mutation {
  newFile( 
     fileName: \"somefile.csv\",
     name: \"humio\",
  ) 
  { nameAndPath {path} }
}"
}'
    "$YOUR_LOGSCALE_URL/graphql"
Perl
perl
#!/usr/bin/perl

use HTTP::Request;
use LWP;

my $TOKEN = "TOKEN";

my $uri = '$YOUR_LOGSCALE_URL/graphql';

my $query = "mutation {
  newFile( 
     fileName: \"somefile.csv\",
     name: \"humio\",
  ) 
  { nameAndPath {path} }
}";
$query =~ s/\n/ /g;
my $json = sprintf('{"query" : "%s"}',$query);
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" : "mutation {
  newFile( 
     fileName: \"somefile.csv\",
     name: \"humio\",
  ) 
  { nameAndPath {path} }
}"
}'''

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" : "mutation {
  newFile( 
     fileName: \"somefile.csv\",
     name: \"humio\",
  ) 
  { nameAndPath {path} }
}"
}
);


const options = {
  hostname: '$YOUR_LOGSCALE_URL',
  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": {
    "newFile": {
      "nameAndPath": {
        "path": null
      }
    }
  }
}

Input Parameters

The name argument identifies the repository or view where the file is created. The fileName argument sets the filename within that repository. The optional content argument accepts a NewFileContent input with headers (the column names) and rows (an array of row strings). Omitting content creates an empty file. The optional labels argument attaches labels at creation time; each file supports at most 10 labels.

Table: Input Parameters

Parameter Type Required Default Description
This table contains all input parameters for this mutation.
content NewFileContent     Initial content for the file. Accepts a NewFileContent object with headers (column names) and rows (an array of row strings). If omitted, the file is created empty.
fileName String! yes   The filename to assign to the new file.
labels [String!]     Labels to associate with the new file. Omitting this parameter creates the file with no labels.
name String! yes   The name of the target repository or view.

Returned Values

The mutation returns an UploadedFileSnapshot object describing the newly created file. nameAndPath returns the file name and its path within the repository. headers returns the column names, confirming the structure of the file. totalLinesCount returns the number of data rows. lines returns the actual row data; for an empty file it returns an empty array. offset is always 0 for a newly created file.

Table: UploadedFileSnapshot Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
filterStringString  Long-Term Any string on which to filter the data.
headersStringyes Long-Term The headers for the uploaded snapshot file.
limitIntyes Long-Term The file upload limit.
lines[String]yes Long-Term 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 Long-Term The name and path of the uploaded snapshot file. See FileNameAndPath.
offsetIntyes Long-Term This is the offset supplied to a file query. For a new or updated file, this is always 0.
resourceStringyes Short-Term The resource identifier for the file.
totalLinesCountLongyes Long-Term The total number of lines in the uploaded snapshot file.