Summary

The addFileLabels() mutation attaches labels to an existing file in a LogScale view or repository. Files are uploaded lookup resources that queries can reference for data enrichment. Labels organize and filter these files alongside dashboards and actions.

Each file supports at most 10 labels, with a maximum of 60 characters per label. Exceeding either limit causes the mutation to fail. On success, the mutation returns the updated file.

Syntax

graphql
addFileLabels(
      input: AddFileLabels!
   ): File

The input argument requires the view or repository name, the file name, and a list of labels to attach. The Show Files Query example retrieves file names for a repository.

The return type is File, which is nullable. The mutation returns the updated File object on success, or null with errors on failure.

Hide Query Example

Show Files Query

Example

Raw
graphql
mutation {
  addFileLabels(
    input: { 
      viewName: "humio",
      fileName: "my-file.txt",
      labels: [ "bobs-files",
                "admin-files" ]
    }
  )
  { createdAt }
}
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 {
  addFileLabels(
    input: { 
      viewName: \"humio\",
      fileName: \"my-file.txt\",
      labels: [ \"bobs-files\",
                \"admin-files\" ]
    }
  )
  { createdAt }
}"
}
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 {
  addFileLabels(
    input: { 
      viewName: \"humio\",
      fileName: \"my-file.txt\",
      labels: [ \"bobs-files\",
                \"admin-files\" ]
    }
  )
  { createdAt }
}"
}
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 { ^
  addFileLabels( ^
    input: {  ^
      viewName: \"humio\", ^
      fileName: \"my-file.txt\", ^
      labels: [ \"bobs-files\", ^
                \"admin-files\" ] ^
    } ^
  ) ^
  { createdAt } ^
}" ^
} '
Windows Powershell and curl
powershell
curl.exe -X POST 
    -H "Authorization: Bearer $TOKEN"
    -H "Content-Type: application/json"
    -d '{"query" : "mutation {
  addFileLabels(
    input: { 
      viewName: \"humio\",
      fileName: \"my-file.txt\",
      labels: [ \"bobs-files\",
                \"admin-files\" ]
    }
  )
  { createdAt }
}"
}'
    "$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 {
  addFileLabels(
    input: { 
      viewName: \"humio\",
      fileName: \"my-file.txt\",
      labels: [ \"bobs-files\",
                \"admin-files\" ]
    }
  )
  { createdAt }
}";
$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 {
  addFileLabels(
    input: { 
      viewName: \"humio\",
      fileName: \"my-file.txt\",
      labels: [ \"bobs-files\",
                \"admin-files\" ]
    }
  )
  { createdAt }
}"
}'''

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 {
  addFileLabels(
    input: { 
      viewName: \"humio\",
      fileName: \"my-file.txt\",
      labels: [ \"bobs-files\",
                \"admin-files\" ]
    }
  )
  { createdAt }
}"
}
);


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": {
    "addFileLabels": {
      "createdAt": "1729603406707"
    }
  }
}

Input Parameters

Provide the view or repository name in viewName, the file name in fileName, and the labels to attach in labels. Each call adds the specified labels to any labels already on the file — labels are not replaced. To replace all labels, first remove existing labels with removeFileLabels(), then call addFileLabels() with the new labels. Each file supports at most 10 labels, and each label has a maximum of 60 characters.

Table: AddFileLabels Input Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
fileNameStringyes   Name of the file.
labelsStringyes   Labels for the file. There can be at most 10 labels with a max length of 60 characters per label.
viewNameRepoOrViewNameyes   Name of the view for the file.

Returned Values

The mutation returns a File object on success, or null with errors on failure. labels returns the complete set of labels now attached to the file, including any labels that were already present before this call. Available fields also include the file name, creation timestamp, and modification timestamp.

Table: File Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
allowedActionsAssetActionyes Short-Term Allowed asset actions
contentHashStringyes Long-Term  
createdAtDateTimeyes Long-Term  
createdByStringyes Long-Term  
fileSizeBytesLong  Long-Term  
labelsStringyes Short-Term Labels associated with this file
modifiedAtDateTimeyes Long-Term  
modifiedByStringyes Long-Term  
nameAndPathFileNameAndPathyes Long-Term  
packagePackageInstallation  Long-Term  
packageIdVersionedPackageSpecifier  Long-Term  
resourceStringyes Short-Term The resource identifier for this file.