# Node.js

```javascript
const axios = require('axios');

const token = 'YOUR_TOKEN_HERE'; // Replace with your token
const createUrl = 'https://api.autocontentapi.com/Content/Create';
const pollInterval = 5000; // Poll every 5 seconds

// The request data to create the content
const requestData = {
  resources: [
    { content: 'https://autocontentapi.com', type: 'website' },
    { content: '74% of businesses expect AI to increase productivity', type: 'text' }
  ],
  text: 'Explain why automating with AutoContent API is a game changer for any business',
  outputType: 'audio'
};

// Create the content request
async function createContent() {
  const response = await axios.post(createUrl, requestData, {
    headers: {
      'Authorization': `Bearer ${token}`,
      'Content-Type': 'application/json',
      'accept': 'text/plain'
    }
  });
  
  return response.data;
}

// Poll for status until complete or error
async function pollStatus(requestId) {
  const statusUrl = `https://api.autocontentapi.com/content/status/${requestId}`;

  while (true) {
    const response = await axios.get(statusUrl, {
      headers: {
        'Authorization': `Bearer ${token}`,
        'Content-Type': 'application/json',
        'accept': 'application/json'
      }
    });

    const { status, error_message, audio_url, audio_title } = response.data;

    if (error_message) {
      console.error('Error from status check:', error_message);
      return;
    }

    if (status === 100) {
      console.log('Content creation complete!');
      console.log('Audio URL:', audio_url);
      console.log('Audio Title:', audio_title);
      return;
    }

    console.log(`Current status: ${status}. Waiting for 100...`);
    await new Promise(resolve => setTimeout(resolve, pollInterval));
  }
}

// Main function
async function run() {
  try {
    const { request_id, error_message } = await createContent();

    if (error_message || !request_id) {
      console.error('Error from create request:', error_message);
      return;
    }

    console.log(`Request initiated. Request ID: ${request_id}`);
    await pollStatus(request_id);
  } catch (err) {
    console.error('Error:', err.response ? err.response.data : err.message);
  }
}

run();

```

Need scenario-specific snippets? Browse the [podcast examples](/code-samples/podcasts/nodejs.md).


---

# 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.autocontentapi.com/code-samples/language-quickstarts/nodejs.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.
