SMMRY API bug stemming from a lack of necessary variables

Here is the code snippet:

// Article Summary
var params = {
    host: 'api.smmry.com',
    path: '/',
    body: {
        SM_API_KEY: 'B...',
        SM_URL: 'www.bbc.com/sampleNews'
    }
};
http.get(params, function(res) {
    res.on('data', function(data) {
        console.log(JSON.parse(data.toString()));
    });
});

I have been attempting to make a functional API request without success. I attempted to structure the data like this:

var params = {
    host: 'api.smmry.com',
    path: '/',
    SM_API_KEY: 'B...',
    SM_URL: 'www.bbc.com/sampleNews'
};

Also tried:

var params = {
    host: 'api.smmry.com',
    path: '/',
    data: {
        SM_API_KEY: 'B...',
        SM_URL: 'www.bbc.com/sampleNews'
    }
};

The encountered error:

{ sm_api_error: 1, sm_api_message: 'INSUFFICIENT VARIABLES' }

Answer №1

Here's the solution that worked for me:

    const options = {
        hostname: 'api.smmry.com',
        path: '/&SM_API_KEY=B...&SM_URL=' + url,
        method: 'POST'
    };

    const req = http.request(options, (res) => {
        let rawData = '';
        res.on('data', (chunk) => {
            rawData += chunk;
        });
        
        res.on('end', () => {
            try {
                const parsedData = JSON.parse(rawData);
                console.log(parsedData);
            } catch (error) {
                console.error(error);
            }
        });
    });

    req.end();

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Guide on how to showcase the template by leveraging the roomList information with ngTemplateOutlet in Angular

TS roomList = [{ name: 'Room2' }] HTML <div class="Layout-body"> <ng-container *ngFor="let dt of roomList; index as i" [ngTemplateOutlet]="Room1" [ngTemplateOutletContext]="{ data: dt, i: i }&qu ...

Challenges encountered in exporting functions with Webpack 5

Imagine having an exported function called createTableFromJSON(json) from the main file named index.js. The configuration example below adheres to the guidelines outlined in Webpack's official documentation: const config = { entry: './assets/ja ...

Nightwatch failing to locate element within iFrame

I'm currently facing a challenge when trying to access an element within an iframe. Despite successfully switching to the frame, Nightwatch keeps returning "element not found" whenever I attempt to verify its presence or visibility. Below is a snippe ...

Mastering the art of integrating a multi-step form in React

While developing a multi-step form in my React 17.0.1 application using Typescript version 4.1.2, I came across this helpful guide: https://dev.to/sametweb/how-to-create-multi-step-forms-in-react-3km4 The guide was clear up to step 6, which I decided to s ...

Creating dynamic charts in Javascript using Firebase

My dad recently asked me to enhance our motor home by integrating an Arduino with Firebase to monitor the water and propane tanks. He's hoping to be able to check tank levels from his phone so he can see when they need refilling. I've successful ...

Unable to fetch the Observable value

I have a function that returns an Observable<Person[]>, where Person is my model: export interface Person { id: string; age: number; } Now in my component.ts, I am calling this function and aiming to retrieve the array to display it in the HTML ...

Converting a unix timestamp to a Date in TypeScript - a comprehensive guide

To retrieve the unix timestamp of a Date in plain JavaScript and TypeScript, we can use this code snippet: let currentDate = new Date(); const unixTime = currentDate.valueOf(); Converting the unix timestamp back to a Date object in JavaScript is straight ...

Insert a division into the table following every row

I'm working with a table that can be found here: https://codepen.io/anon/pen/bjvwOx Whenever I click on a row (for example, the 1st row 'NODE ID 1'), I want the div with the id #divTemplate to appear below that particular row, just like it d ...

Acquiring information from a different Vue.js component

I am faced with a puzzle involving 2 components, A and B. Component A: import B from '../components/B.vue'; export default { components: { B }, methods: { test: function() { console.log(B.data().settin ...

Tips for comparing two arrays in node.js

I am faced with the task of comparing two arrays. let runArray = ['Welcome', 'Hello'] let data = [{ Node:'Good', Session:'2', Run:'Welcome', Run_Group:'Display', Elapsed_Ms: '1000& ...

Adjusting the brightness of colors using JavaScript

I am looking for a way to return different color tones for a specific color using JavaScript. For example, if I have the color code #4a4a4a, I want to be able to return #494949 and #666464. If there is a package or method that can achieve this, please sugg ...

Generating and delivering files without the need to save them to a hard drive

I've been attempting to create a file and send it as a response using expressjs. Here's what I've tried: import { createWriteStream } from 'fs'; const writeStream = createWriteStream('./file.sxcu'); const data = { " ...

Is it possible to use HTML alone in Bootstrap 5 to link a button to display a toast notification?

I'm working on a Bootstrap page that includes a button and a toast element sourced from the Bootstrap documentation. The documentation states that I need to initialize the toast in JavaScript during page load. My goal is to have the toast appear when ...

Guide on implementing a date selector for each button/option clicked using Vue.js

My experience with Vuejs is still fresh, and I've incorporated 3 buttons named chart1, chart2, and chart3. Whenever any of these buttons are clicked, I want a Date selection to appear in a radio type format. You can see an example below: https://i.ss ...

Retrieving a specific document from an array that meets a specific query using MongoDB in JavaScript

I have a collection of data stored in MongoDB structured like this: users: { { user_id: 1000, activities: [ {id: 1, activity: 'swimming'}, {id: 2, activity: 'running'}, {id: 3, activi ...

Timepicker.js - Incorrect Placement of Time Picker in Certain Scenarios

Utilizing the timepicker.js library to select a time, I am encountering an issue. When clicking on the input field, the timepicker should appear next to it. This function works as expected when the input is within the main view of the document. However, if ...

Exploring package.json: Uncovering the Installed Components of a Module

I am working on a project with the following structure: __tests__ example src .bablerc .eslintignore .eslintrd .gitignore package.json package-lock.json README.md The package.json file has the following parameters: { "name": "", "version": "0.0.1", ...

Flask - send notification after receiving service data, and proceed with processing

I have a couple of lightweight web microservices built using Flask. One service, referred to as X, accepts a POST request from an external source. After processing some calculations, X then sends another POST request to a different service called Y. Curren ...

The AJAX request to the URL is failing

Creating a webpage with the ability to control an IP camera's movements such as moving up and down or zooming in and out involves calling specific URLs. While trying to implement this feature asynchronously, I encountered issues using AJAX which did n ...

Relocate the bxslider carousel to the specific div clicked on

Is it possible to move the slider to the selected div when using bxslider? I have a carousel below. Currently, when you click on the controls (left/right arrows), it only moves one slide/div at a time, keeping the active div always on the left side. Howev ...