`schema` not present in Get Route(s) Notehub API

Hello!

The Route API docs for Get Routes mention that the route schema is returned in the response.

I have an http route, but when I request all routes, or a single route by route UID, the response doesn’t include the schema:

[{"uid":"route:<uid>","label":"test","type":"http","modified":"2024-02-13T23:06:20Z","disabled":false}]\n

I tried both with a direct HTTP call to the Notehub API, and also using notehub-js. According to the OpenAPI spec, the API behavior is correct, and the docs are incorrect. But I wish it behaved the way the docs say! :slight_smile: - it would be very helpful to be able to retrieve the complete Route definition.

The openAPI spec has Route and UserDbRoute types. The Route type includes the route schema and is used by Create/Update Route, while the UserDbRoute is what Get Route(s) returns, which doesn’t include the route schema.

We want to programmatically update a route (a token in the HTTP headers), and having the complete route schema would make this possible.

Thanks for any assistance.

Hello!

It looks like the response you posted might have been from the endpoint to retrieve ALL routes, which appears to not include the full route definition. However, the endpoint to retrieve a single route should include the full definition. Here’s an example of the response I got back from the endpoint to retrieve a single route:

{
    "disabled": false,
    "http": {
        "disable_http_headers": false,
        "filter": {
            "system_notefiles": false,
            "type": "all"
        },
        "fleets": null,
        "http_headers": {
            "X-Custom-Header": "My Value"
        },
        "timeout": 15,
        "transform": {},
        "url": "http://example.com"
    },
    "label": "My HTTP Route",
    "modified": "2024-02-21T13:23:15Z",
    "type": "http",
    "uid": "route:250f9c33d681184146486ab7ff23f082"
}

I’m curious to know if you’re able to get back the schema by issuing a request for a single route. As for the endpoint to retrieve ALL routes, I’m not sure exactly why that doesn’t include the full route definition but it looks like this was done to keep the response sizes reasonably sized.

2 Likes

Hi Scott!

Yes, you’re right. Sorry for the confusion. I was mixed up between the tests that use notehub-js vs a direct API call and getRoutes vs getRoute. I do see the route schema when fetching a single route via the API, but unfortunately not via notehub-js.

Here’s some test code that runs the same tests using notehub-js and axios http client.


// const projectUID, email, pwd, routeID = ...;

const notehubjs = require("@blues-inc/notehub-js");
import * as axios from "axios";

describe("Notehub API", () => {
    let session_token: string;

    beforeAll(async () => {  // get an authorization token
        let authorizationApi = new notehubjs.AuthorizationApi();
        let loginRequest = { "username": email, "password": pwd };
        const result = await authorizationApi.login(loginRequest);
        expect(result).toHaveProperty("session_token");
        session_token = result.session_token;
        expect(session_token).toBeTruthy;
    });

    function getRouteWithNotehubJS() {
        return async function() {
            let routeApi = new notehubjs.RouteApi();
            let defaultClient = notehubjs.ApiClient.instance;
            const session = defaultClient.authentications['api_key'];
            session.apiKey = session_token;
            const route = await routeApi.getRoute(projectUID, routeUID);
            return route;
        };
    }

    function getRouteWithAxios() {
        return async function() {
            const endpoint = new axios.Axios({
                baseURL: `https://api.notefile.net/v1`,
                headers: { 'X-Session-Token': `${session_token}` }
            });
            const response = await endpoint.get(`/projects/${projectUID}/routes/${routeUID}`, {});
            const route = JSON.parse(response.data);   // todo - axios is supposed to parse json responses
            return route;
        }
    }

    describe.each([
        ["axios", getRouteWithAxios()],
        ["notehub-js", getRouteWithNotehubJS()]
    ])
    ("get route via %s", (name: string, getRoute: any) => {
        let route: any;
        beforeAll(async () => {
            route = await getRoute();
        });

        describe('should retrieve route data having', () => {
            it('"type" http', () => {
                expect(route).toHaveProperty("type", "http");
            });
            it('"http" defined', () => {
                expect(route).toHaveProperty("http");
            });
            it('"schema" not defined', () => {
                // "schema" isn't a real property but a placeholder
                expect(route).not.toHaveProperty("schema");
            });
        });
    });
});

Running with these dependencies (excerpted):

"@blues-inc/notehub-js": "^1.0.19",
"jest": "^29.7.0",
"ts-jest": "^29.1.2"

The axios tests are green, but notehub-js only returns a response with the same properties as getRoutes. The http property for the event schema is missing even though getRoute is being called.

The last test, checking that schema doesn’t exist, is there since It wasn’t clear from the API docs that schema is a placeholder property name rather than an actual property name.

Thanks!

2 Likes