> ## Documentation Index
> Fetch the complete documentation index at: https://developers.hubspot.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

---
id: ec5c6bd3-48e2-43fd-b77b-bcab41b41b1d
---

# no-invalid-fetch-url

> Only allow fully-qualified HTTPS URLs in the first argument of hubspot.fetch().

The `no-invalid-fetch-url` rule validates that the first argument of [`hubspot.fetch()`](https://developers.hubspot.com/docs/apps/developer-platform/add-features/ui-extensions/fetching-data#hubspot-fetch) is a fully-qualified HTTPS URL.

## Rule details

`hubspot.fetch()` requires a fully-qualified HTTPS URL. Relative paths and non-HTTPS URLs fail at runtime. This rule validates that the URL:

1. Contains no leading or trailing whitespace.
2. Is absolute, not a relative path.
3. Uses the `https://` protocol.

The rule checks the first argument when its value can be determined from the code, including string literals, template literals, string concatenation, and variables declared with `const` in the same file. For template literals and concatenation, the rule checks the text before the first dynamic value.

Values that are only known at runtime are not validated by this rule, such as function parameters, imported values, `let` and `var` variables, and values that start with a dynamic part. Calls to `fetch()` on objects other than `hubspot` are also ignored. Native `fetch()` calls are reported by the [`no-native-http`](https://developers.hubspot.com/docs/apps/developer-platform/add-features/ui-extensions/tools/linting/rules/no-native-http) rule.

## Examples

### Relative URLs

**Invalid:** relative URL path:

```jsx theme={null}
// Incorrect - relative paths can't be resolved
hubspot.fetch('/api/v1/data');
```

Instead use the full URL:

```jsx theme={null}
hubspot.fetch('https://api.example.com/v1/data');
```

### Invalid protocols

**Invalid:** unsupported URL protocol:

```jsx theme={null}
// Incorrect - only https:// is supported
hubspot.fetch('http://api.example.com/v1/data');
```

Use the `https://` protocol instead:

```jsx theme={null}
hubspot.fetch('https://api.example.com/v1/data');
```

### Whitespace in URLs

**Invalid:** extra space around the URL:

```jsx theme={null}
// Incorrect - whitespace around URL
hubspot.fetch(' https://api.example.com/v1/data ');
```

Remove the whitespace:

```jsx theme={null}
hubspot.fetch('https://api.example.com/v1/data');
```

### Template literals and variables

The rule checks the known start of a template literal or concatenated string, and the value of a `const` variable:

```jsx theme={null}
// Incorrect - the URL starts with a relative path
hubspot.fetch(`/api/${id}`);

const url = '/api/v1/data';
hubspot.fetch(url);
```

Start the URL with an HTTPS URL instead:

```jsx theme={null}
hubspot.fetch(`https://api.example.com/${id}`);

const url = 'https://api.example.com/v1/data';
hubspot.fetch(url);
```

### Dynamic values

Dynamic values are not validated by this rule:

```jsx theme={null}
function getData(url) {
  return hubspot.fetch(url);
}

hubspot.fetch(`${baseUrl}/v1/data`);
```

## Related resources

* [Fetching data in UI extensions](https://developers.hubspot.com/docs/apps/developer-platform/add-features/ui-extensions/fetching-data.md)
* [hubspot.fetch() API](https://developers.hubspot.com/docs/apps/developer-platform/add-features/ui-extensions/fetching-data.md#hubspot-fetch)
