Addon Kit v1.3.1 – Synchronous TypeError when making REST API requests from Simple Function

I’m developing a private Job Action add-on using the new ServiceM8 Addon Kit CLI (v1.3.1) and have been unable to make a successful REST API request from the hosted Node.js 24 Simple Function.

The add-on deploys and launches successfully. CLI OAuth authentication works, and the handler receives valid job/staff context and a temporary OAuth token.

I’ve read the existing discussion about using fetch in Simple Functions and the example that successfully retrieves job information. However, we’re seeing different behaviour:

  • Global fetch throws a TypeError immediately, even for unauthenticated requests to example.com.

  • Native https.get successfully retrieves HTTP 200 from example.com.

  • Native https.get targeting api.servicem8.com throws synchronously after approximately 1 ms, before any HTTP response.

  • Our latest diagnostic identifies the failure at the https.get invocation, after URL and request-options construction.

  • These are not timeouts or HTTP 401/403 responses.

The code uses an asynchronous handler, the documented API hostname and temporary OAuth token. Local automated tests, TypeScript checks and Addon Kit dry-run validation all pass.

Has anyone successfully made authenticated ServiceM8 REST API requests from an add-on built with the new Addon Kit CLI, rather than the earlier developer interface?

If so, is there a particular configuration, HTTP client or request pattern required in the current hosted runtime?

I’d particularly appreciate guidance from anyone using Addon Kit v1.3.x with Node.js 24.

I can provide a minimal sanitised code example if useful.

Hi Susan — thanks for the detailed diagnostics, they made this easy to pin down.

The issue is the handler signature: handler(event, nativeHttpsGet = https.get). AWS Lambda always invokes the handler as handler(event, context), so the default parameter is never applied — nativeHttpsGet is actually the Lambda context object, and calling it throws TypeError: … is not a function synchronously (hence the 1 ms failure with no response). The earlier fetch attempts failed the same way if fetch was injected via a default parameter. Outbound networking is fine — your direct https.get probe got a 200.

To fix, keep the exported handler to handler(event) and pass the HTTP client into an internal function for testing, e.g.

export const handler = (event) => run(event, https.get);

and test run with your mock. Global fetch on Node 24 works fine for https://api.servicem8.com/api_1.0/... with Authorization: Bearer ${event.auth.accessToken}.

Cody

1 Like

Thank you so much Cody for your help!

Problem solved and add on deployed! :star_struck:

Hi Susan,

Addon Kit-deployed add-ons are Simple Function add-ons, and their handlers receive event.auth.accessToken for calling the ServiceM8 REST API. This capability isn’t limited to add-ons created through the earlier developer interface.

There are two configuration and validation points worth separating from the synchronous error you’re reporting:

  • API permissions: Include the required scopes in both addon.jsonc’s oauth.scope and the addon-kit login --scopes "…" request. The default CLI login requests manage_addons, which permits deployment but doesn’t by itself give your function access to account data. This is a permissions prerequisite, not a diagnosis of your TypeError.
  • Dry-run validation: addon-kit deploy --dry-run validates and bundles locally without deploying, so passing that check doesn’t exercise the hosted function’s HTTP requests.

To capture the deployed execution, use npx addon-kit tail. When logging the exception, include its message and stack explicitly, and don’t log the full event or access token.

For investigation of the synchronous failure, please email support@servicem8.com with your minimal sanitised reproduction, CLI version, and sanitised error message and stack, without API keys, tokens or other secrets.

We’ll confirm the HTTP-client requirements and request pattern for Addon Kit v1.3.x on the hosted Node.js 24 runtime with the team.

Thanks,
Cody