# Getting started

This guide provides an overview of how to get started using the OS Net API, covering the core elements on how to automate the download of OS Net RINEX.

{% hint style="info" %}
If you are not familiar with the OS Net API please read the [overview documentation](/os-apis/accessing-os-apis/os-net-api.md) before proceeding.
{% endhint %}

## What you need?

* OS Net API URL and key; see [Getting started with an API project](/os-apis/core-concepts/getting-started-with-an-api-project.md) for more information
* A basic understanding of automatic processing of JSON data and basic procedural (if-then-else) programming
* A text editor like Visual Studio Code
* A working installation of [Node.js](https://nodejs.org/) and the popular [axios](https://github.com/axios/axios) module

## Instructions

{% hint style="info" %}
Please read these pages in conjunction with the [Technical specification](/os-apis/accessing-os-apis/os-net-api/technical-specification.md).
{% endhint %}

## Prerequisites

* Node.js installed
* Axios module installed (`npm install axios`) and then run it with 'node sample-app.js'
* Basic understanding of JSON and procedural logic
* API Key or OAuth2 token for authentication
* A text editor like Visual Studio Code

## Example: Automating RINEX File Downloads

This script fetches available RINEX files for a specific station and date, then downloads them to a local folder:

```javascript
const axios = require('axios');
const fs = require('fs');
const path = require('path');
// Replace with your actual API key
const API_KEY = 'YOUR_API_KEY_HERE';
// Example parameters
const stationId = 'ABEP';
const year = 2025;
const dayOfYear = 1;
const listFilesUrl = `https://api.os.uk/positioning/osnet/v1/rinex/${year}/${dayOfYear}`;
const downloadDir = './downloads';

async function downloadRinexFiles() {
    try {
        const response = await axios.get(listFilesUrl, {
            headers: { 'key': API_KEY }
        });
        const files = response.data;
        if (!fs.existsSync(downloadDir)) {
            fs.mkdirSync(downloadDir);
        }
        for (const file of files) {
            const fileUrl = file.url;
            const fileName = file.fileName;
            if(fileName.startsWith(stationId)) {
                console.log(`Downloading ${fileName}...`);
                const filePath = path.join(downloadDir, fileName);
                const fileResponse = await axios.get(fileUrl, {
                    headers: { 'key': API_KEY },
                    responseType: 'stream'
                });
                const writer = fs.createWriteStream(filePath);
                fileResponse.data.pipe(writer);
            }
        }
        console.log('All files downloaded.');
    } catch (error) {
        console.error('Error downloading RINEX files:', error.message);
    }
}

downloadRinexFiles();

```

### ✅ What this script does

* Queries the `/rinex/{year}/{dayOfYear}` endpoint to list available files
* Iterates through the list and downloads each file using its `url`
* Saves the files to a local `downloads` directory


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.os.uk/os-apis/accessing-os-apis/os-net-api/getting-started.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
