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

# JavaScript / Fetch

> Send submissions from any JavaScript app using fetch or axios.

## Using fetch

```javascript theme={null}
async function submitForm(data) {
  const res = await fetch('https://submito.dev/api/v1/your-endpoint-slug/submit', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'x-api-key': 'your-api-key',
    },
    body: JSON.stringify(data),
  })

  const result = await res.json()

  if (!result.ok) {
    throw new Error(result.error ?? 'Submission failed')
  }

  return result
}

// Usage
submitForm({
  name: 'John Doe',
  email: 'john@example.com',
  message: 'Hello!',
})
```

## Using axios

```javascript theme={null}
import axios from 'axios'

async function submitForm(data) {
  const { data: result } = await axios.post(
    'https://submito.dev/api/v1/your-endpoint-slug/submit',
    data,
    {
      headers: {
        'x-api-key': 'your-api-key',
      },
    }
  )
  return result
}
```

## Handling errors

```javascript theme={null}
async function submitForm(data) {
  try {
    const res = await fetch('https://submito.dev/api/v1/your-endpoint-slug/submit', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'x-api-key': 'your-api-key',
      },
      body: JSON.stringify(data),
    })

    const result = await res.json()

    if (res.status === 429) {
      console.error('Quota exceeded — upgrade your plan')
      return
    }

    if (!result.ok) {
      console.error('Error:', result.error)
      return
    }

    console.log('Submission sent!')
  } catch (err) {
    console.error('Network error:', err)
  }
}
```

## Using environment variables

Store your credentials in a `.env` file:

```bash theme={null}
SUBMITO_API_KEY=your-api-key
SUBMITO_ENDPOINT=https://submito.dev/api/v1/your-endpoint-slug/submit
```

```javascript theme={null}
const res = await fetch(process.env.SUBMITO_ENDPOINT, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'x-api-key': process.env.SUBMITO_API_KEY,
  },
  body: JSON.stringify(data),
})
```

See [Response Codes](https://docs.submito.dev/reference/response-codes.md) for a full list of possible errors.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.