Extracting Information from API Response

I am struggling to extract specific data from a website API. My current method involves dumping the entire response into Google Sheets and using the mid function to retrieve the desired string. Is there a more efficient way to only return the value of "unpaid"?

The response I receive is:

{"status":"OK","data":{"time":1612834200,"lastSeen":1612834035,"reportedHashrate":154783794,"currentHashrate":131055555.55555557,"validShares":116,"invalidShares":0,"staleShares":3,"averageHashrate":150218750,"activeWorkers":3,"unpaid":26075516667066776,"unconfirmed":null,"coinsPerMin":0.00000787562193181224,"usdPerMin":0.013755797534761213,"btcPerMin":2.9738348414523017e-7}}

I only require:

"unpaid":26075516667066776

Below is the script I'm using to import this data to Google Sheets.

function callNumbers() {
  var response = UrlFetchApp.fetch("");
  Logger.log(response.getContentText());
  
  var data = response.getContentText();
  var sheet = SpreadsheetApp.getActiveSheet();
  sheet.getRange(49,7).setValue([data]);

}

I have been unable to find sufficient guidance on this matter, or perhaps I am looking in the wrong places. The functions mentioned above were sourced from a Google page and modified to suit my requirements. Thank you.

Answer №1

After some experimentation, I realized that making a few adjustments was necessary. Here is the final result:

function retrieveData() {
  var response = UrlFetchApp.fetch("URL");
  var data = JSON.parse(response.getContentText());
  var sheet = SpreadsheetApp.getActiveSheet();
  sheet.getRange(49,7).setValue([data.info.unpaid]);
  Logger.log(data.info.unpaid);
}

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

Unable to retrieve real-time data from Firestore using getStaticPaths in Next.js

While fetching data from Firebase Firestore using getStaticProps is successful, I encounter a 404 page when attempting to implement the logic for retrieving details of individual items with getStaticPaths. The current state of my [id].js code appears as fo ...

JavaScript, can you explain the significance of the "length" set in this function?

I found this code snippet online and used it in my function. Surprisingly, it works perfectly. However, I'm puzzled by the use of .length in the for loop statement. Isn't length a measurement of how long something is? It's somewhat like ...

Having trouble deciphering this snippet of Express JS source code

Upon reviewing the Express JS source code, I came across the main module where express is being exported. module.exports = createApplication; function createApplication() { var app = function(req, res, next) { app.handle(req, res, next); }; m ...

Is it possible to implement CSS code from a server request into a React application?

With a single React app that hosts numerous customer websites which can be customized in various ways, I want to enable users to apply their own CSS code to their respective sites. Since users typically don't switch directly between websites, applying ...

Using d3 to create an SVG with a Bootstrap dropdown feature

I am seeking to create a graph that is not a tree, as some nodes may have multiple parents. When a node on the graph is clicked, a dropdown menu should be displayed with a list of text options. Though I am new to d3.js, I have observed examples of bootstra ...

Unique Symbols and Characters in JavaScript

My JavaScript code looks like this: confirm("You are selecting to start an Associate who is Pending Red (P RD) status. Is this your intent?") I am encountering a strange issue where I get an alert with special characters, even though my code does not con ...

drawing tool with JavaScript and HTML5

Can you help me figure out why my sketchpad isn't working in Processing.js? I've checked my code and there are no errors, but the canvas is not showing up. Any suggestions? Take a look at the code below: function createSketchPad(processing) { ...

KineticJS: Applying a filter to an image does not result in the image having a stroke

Working with KineticJS version 5.1.0 I encountered an issue where a KineticJS image that had a stroke lost the stroke after applying a filter to it. I have created a demo showcasing this problem, which can be viewed on JSFiddle. Here is the code snippet: ...

Having trouble with the jQuery function not working as expected? Can't seem to identify any errors in the code?

I'm attempting to capture the essence of moving clouds from this beautiful theme: (I purchased it on themeforest, but it's originally designed for tumblr) Now, I want to incorporate it into my wordpress website here: The code used to be under ...

What exactly is the mechanism behind the functionality of ng-cloak?

Recently, I've been delving into the ng-cloak source code and trying to understand its inner workings. If you're interested, you can take a look at the source code here. From what I gather, it seems that the ng-cloak attribute is removed during ...

JavaScript enables running Acrobat Run profiles with variables

Is it possible to set a value to a preflight created using Acrobat before running it? var oProfile = Preflight.getProfileByName("myPreflight"); var oThermometer = app.thermometer; var textSize = 10; //oProfile.SetVariable("textSize",t ...

Changing an XML Linq query into JSON format

I am currently using Linq to parse an XML feed in order to develop a mobile application. The code snippet I am using is as follows: var Questions = from myQuestion in IXML.Descendants("item") let Anonymous = myQuest ...

Implementing dynamic property addition to a class

Here is an example list of product classes: { Name = "Product 1", Category = "TV", Region = "China" }, { Name = "Product 2", Category = "Watch", Region = "Germany" }, { Name = "Product 3", Category = "Smartphone", Region = ...

The contrast between FormData and jQuery's serialize() method: Exploring the distinctions

Recently I came across a situation where I needed to submit a form using AJAX. While researching the most efficient method, I discovered two popular approaches - some developers were utilizing jQuery#serialize() while others were opting for FormData. Here ...

What is the process for recursively extracting specific fields from json data?

Underneath is a sample json document or json variable that I'm working with in python to extract specific fields. Any guidance on how to accomplish this task would be greatly appreciated. json_variable = { "server01":{ "addr ...

Loading an image from Vue.js and Django

I'm currently working on a project using Vue, and I'm fetching an image through a Django REST API. The code in table.vue file: <tbody> <tr v-for= "user in users" :key="user.id_users"> <th>{{user.id_use ...

Developing a specialized directive to enhance bootstrap menuItems

I have created a custom directive in AngularJS for the navbar in Bootstrap. This directive uses ng-transclude and handles two types of list items (li) depending on whether it is a dropdown or not. However, I am experiencing issues with the dropdown functio ...

Schedule - the information list is not visible on the calendar

I am trying to create a timeline that loads all data and events from a datasource. I have been using a dev extreme component for this purpose, but unfortunately, the events are not displaying on the calendar. Can anyone offer any insights into what I might ...

What is the secret behind the checkbox retaining its checked status upon page reload?

My dataTable is loading all data from the MySQL database and the first checkboxes are automatically incremented when a new row is added. However, users may check or uncheck these checkboxes. My goal is to retain the checkbox results even when the page is r ...

Determining the nearest upcoming date from a JSON dataset

Looking to find the nearest date to today from the array "dates". For example, if today is 2011-09-10 -> the next closest date from the JSON file is "2012-12-20" -> $('div').append('date1: ' + dates.date1); For example 2, if tod ...