Skip to content

[JavaScript SDK] [FlowsApi] Unauthorized error using searchFlowsBySourceCode #117

@Pradumnasaraf

Description

@Pradumnasaraf

Describe the issue

Even tho I have an appropriate amount of authorisation, I am getting an unauthorised error while using searchFlowsBySourceCode. Other than this, other methods are working with the current Auth.

Error Logs

➜  test-js-sdk git:(main) ✗ npm run start

> test-js-sdk@1.0.0 start
> node index.js

Error: Unauthorized
    at Request.callback (/Users/kestra/Dev/test-js-sdk/node_modules/superagent/lib/node/index.js:883:15)
    at /Users/kestra/Dev/test-js-sdk/node_modules/superagent/lib/node/index.js:1126:20
    at IncomingMessage.<anonymous> (/Users/kestra/Dev/test-js-sdk/node_modules/superagent/lib/node/parsers/json.js:22:7)
    at IncomingMessage.emit (node:events:520:35)
    at endReadableNT (node:internal/streams/readable:1701:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:90:21) {
  status: 401,
  response: <ref *1> Response {
    _events: [Object: null prototype] {},
    _eventsCount: 0,
    _maxListeners: undefined,
    res: IncomingMessage {
      _events: [Object],
      _readableState: [ReadableState],
      _maxListeners: undefined,
      socket: [Socket],
      httpVersionMajor: 1,
      httpVersionMinor: 1,
      httpVersion: '1.1',
      complete: true,
      rawHeaders: [Array],
      rawTrailers: [],
      joinDuplicateHeaders: undefined,
      aborted: false,
      upgrade: false,
      url: '',
      method: null,
      statusCode: 401,
      statusMessage: 'Unauthorized',
      client: [Socket],
      _consuming: false,
      _dumped: false,
      req: [ClientRequest],
      _eventsCount: 4,
      text: '{"message":"Unauthorized","logref":null,"path":null,"_links":{"self":{"href":"/api/v1/pradumnasaraf/flows/source?page=1&size=10&q=test&namespace=test.qa.example","templated":false,"profile":null,"deprecation":null,"title":null,"hreflang":null,"type":null,"name":null}},"_embedded":{}}',
      Symbol(shapeMode): true,
      Symbol(kCapture): false,
      Symbol(kHeaders): [Object],
      Symbol(kHeadersCount): 8,
      Symbol(kTrailers): null,
      Symbol(kTrailersCount): 0
    },
    request: Request {
      _events: [Object: null prototype] {},
      _eventsCount: 0,
      _maxListeners: undefined,
      _enableHttp2: false,
      _agent: false,
      _formData: null,
      method: 'GET',
      url: 'http://localhost:8021/api/v1/pradumnasaraf/flows/source?page=1&size=10&q=test&namespace=test.qa.example',
      _header: [Object],
      header: [Object],
      writable: true,
      _redirects: 0,
      _maxRedirects: 5,
      cookies: '',
      qs: {},
      _query: [],
      qsRaw: [],
      _redirectList: [],
      _streamRequest: false,
      _timeout: 60000,
      _responseTimeout: 0,
      _uploadTimeout: 0,
      req: [ClientRequest],
      protocol: 'http:',
      host: 'localhost:8021',
      _endCalled: true,
      _callback: [Function (anonymous)],
      res: [IncomingMessage],
      _resBuffered: true,
      response: [Circular *1],
      called: true,
      Symbol(shapeMode): false,
      Symbol(kCapture): false
    },
    req: ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 3,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      destroyed: false,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: false,
      maxRequestsOnConnectionReached: false,
      _defaultKeepAlive: true,
      useChunkedEncodingByDefault: false,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      strictContentLength: false,
      _contentLength: 0,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      _closed: false,
      _header: 'GET /api/v1/pradumnasaraf/flows/source?page=1&size=10&q=test&namespace=test.qa.example HTTP/1.1\r\n' +
        'Host: localhost:8021\r\n' +
        'Accept-Encoding: gzip, deflate\r\n' +
        'User-Agent: OpenAPI-Generator/1.0.0/Javascript\r\n' +
        'Accept: application/json\r\n' +
        'Connection: close\r\n' +
        '\r\n',
      _keepAliveTimeout: 0,
      _onPendingData: [Function: nop],
      agent: [Agent],
      socketPath: undefined,
      method: 'GET',
      maxHeaderSize: undefined,
      insecureHTTPParser: undefined,
      joinDuplicateHeaders: undefined,
      path: '/api/v1/pradumnasaraf/flows/source?page=1&size=10&q=test&namespace=test.qa.example',
      _ended: true,
      res: [IncomingMessage],
      aborted: false,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: null,
      maxHeadersCount: null,
      reusedSocket: false,
      host: 'localhost',
      protocol: 'http:',
      Symbol(shapeMode): false,
      Symbol(kCapture): false,
      Symbol(kBytesWritten): 0,
      Symbol(kNeedDrain): false,
      Symbol(corked): 0,
      Symbol(kChunkedBuffer): [],
      Symbol(kChunkedLength): 0,
      Symbol(kSocket): [Socket],
      Symbol(kOutHeaders): [Object: null prototype],
      Symbol(errored): null,
      Symbol(kHighWaterMark): 65536,
      Symbol(kRejectNonStandardBodyWrites): false,
      Symbol(kUniqueHeaders): null
    },
    text: '{"message":"Unauthorized","logref":null,"path":null,"_links":{"self":{"href":"/api/v1/pradumnasaraf/flows/source?page=1&size=10&q=test&namespace=test.qa.example","templated":false,"profile":null,"deprecation":null,"title":null,"hreflang":null,"type":null,"name":null}},"_embedded":{}}',
    body: {
      message: 'Unauthorized',
      logref: null,
      path: null,
      _links: [Object],
      _embedded: {}
    },
    files: undefined,
    buffered: true,
    headers: {
      'content-type': 'application/json',
      date: 'Wed, 22 Oct 2025 12:40:35 GMT',
      'content-length': '284',
      connection: 'close'
    },
    header: {
      'content-type': 'application/json',
      date: 'Wed, 22 Oct 2025 12:40:35 GMT',
      'content-length': '284',
      connection: 'close'
    },
    statusCode: 401,
    status: 401,
    statusType: 4,
    info: false,
    ok: false,
    redirect: false,
    clientError: true,
    serverError: false,
    error: Error: cannot GET /api/v1/pradumnasaraf/flows/source?page=1&size=10&q=test&namespace=test.qa.example (401)
        at Response.toError (/Users/kestra/Dev/test-js-sdk/node_modules/superagent/lib/node/response.js:98:13)
        at ResponseBase._setStatusProperties (/Users/kestra/Dev/test-js-sdk/node_modules/superagent/lib/response-base.js:119:48)
        at new Response (/Users/kestra/Dev/test-js-sdk/node_modules/superagent/lib/node/response.js:44:8)
        at Request._emitResponse (/Users/kestra/Dev/test-js-sdk/node_modules/superagent/lib/node/index.js:930:18)
        at /Users/kestra/Dev/test-js-sdk/node_modules/superagent/lib/node/index.js:1126:42
        at IncomingMessage.<anonymous> (/Users/kestra/Dev/test-js-sdk/node_modules/superagent/lib/node/parsers/json.js:22:7)
        at IncomingMessage.emit (node:events:520:35)
        at endReadableNT (node:internal/streams/readable:1701:12)
        at process.processTicksAndRejections (node:internal/process/task_queues:90:21) {
      status: 401,
      text: '{"message":"Unauthorized","logref":null,"path":null,"_links":{"self":{"href":"/api/v1/pradumnasaraf/flows/source?page=1&size=10&q=test&namespace=test.qa.example","templated":false,"profile":null,"deprecation":null,"title":null,"hreflang":null,"type":null,"name":null}},"_embedded":{}}',
      method: 'GET',
      path: '/api/v1/pradumnasaraf/flows/source?page=1&size=10&q=test&namespace=test.qa.example'
    },
    created: false,
    accepted: false,
    noContent: false,
    badRequest: false,
    unauthorized: true,
    notAcceptable: false,
    forbidden: false,
    notFound: false,
    unprocessableEntity: false,
    type: 'application/json',
    links: {},
    setEncoding: [Function: bound ],
    redirects: [],
    pipe: [Function (anonymous)],
    Symbol(shapeMode): false,
    Symbol(kCapture): false
  }
}
➜  test-js-sdk git:(main) ✗ 

Reproducibility

Create the flow below the Flow:

id: test_flow_1
namespace: test.qa.example
tasks:
  - id: hello
    type: io.kestra.plugin.core.log.Log
    message: Hello from flow test_flow_1! 👋 

After creating, also, replace the namespace and tenant accordingly.

Then, run the below code.

JS Code

import 'dotenv/config';
import KestraIoKestraSdk from '@kestra-io/kestra-sdk';
import fs from 'fs';

// Initialize Kestra SDK client
const defaultClient = KestraIoKestraSdk.ApiClient.instance;

// Configure API endpoint
defaultClient.basePath = process.env.KESTRA_API_URL;

let apiInstance = new KestraIoKestraSdk.FlowsApi();
let page = 1; // Number | The current page
let size = 10; // Number | The current page size
let tenant = "pradumnasaraf"; // String | 
let opts = {
  'q': "test", // String | A string filter
  'namespace': "test.qa.example" // String | A namespace filter prefix
};
apiInstance.searchFlowsBySourceCode(page, size, tenant, opts, (error, data, response) => {
  if (error) {
    console.error(error);
  } else {
    console.log('API called successfully. Returned data: ', data);
  }
});

Environment

  • Kestra Version: develop

Environment

  • Kestra Version: develop

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/backendNeeds backend code changesbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions