Access a JSON value in the Google Sheets script editor and retrieve the data

I'm trying to retrieve a value from a JSON object by making an API call in a Google Sheet.

Below is the script I am using:

function getBitcoinPrice()
{
    var url = "https://acx.io//api/v2/tickers/btcaud.json";
    var response = UrlFetchApp.fetch(url);
    var json = response.getContentText();
    var data = JSON.parse(json);

    var price = data.buy;
                                    
    return price;
}

However, when I try to run this function in my Google Sheet, it gives me an error message:

Error: Unknown range name 'getBitcoinPrice'.

Answer №1

Here is the JSON data provided for reference.

{
  "timestamp": ###,
  "stocks": {
    "purchase": ###,
    "sale": ###,
    "low_threshold": ###,
    "high_threshold": ###,
    "latest_price": ###,
    "volume": ###
  }
}

If you require the value associated with the key purchase, consider modifying the code snippet as shown below:

Original Code :

var price = data.purchase

Updated Code :

var price = data.stocks.purchase

Answer №2

Have you made sure to call it as a function?

=ccprice()

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

AngularJS : "Executing successive promises" with additional functions interspersed

Recently, I encountered a challenge in my Angular project. As a newcomer to Angular, I was tasked with modifying a directive that handles forms to ensure the submit button is disabled during processing and then enabled again once all operations are complet ...

Utilizing the components within the range set by paper.setStart() and paper.setFinish() in Raphaels

My question has two parts - the first and second part. Let's consider an example code that I am working on. I am creating a map of my country with regions, and I want to perform actions on the entire map such as scaling or translating (as seen in the ...

I am facing an issue with the routing functionality in the Quasar framework for Vue 3

I seem to be having an issue with my code where no matter what route I give, it only takes me to the home page. Specifically, when I give the path "auth", it still redirects me to the home page. Can someone please help me understand why this is happening a ...

Create a duplicate of a React component that utilizes the forwardRef method

Imagine you have a foundational component that utilizes forwardRef in this manner: const BaseMessage = React.forwardRef((props, ref) => ( <div ref={ref}> {props.icon} <h2>{props.title}</h2> <p>{props.message ...

Building personalized error messages using graphql-js and express

It has come to my attention that you have the ability to create customized errors within graphql and graphql-express. https://codeburst.io/custom-errors-and-error-reporting-in-graphql-bbd398272aeb I recently implemented a custom Error feature, but it see ...

What is the best way to incorporate JavaScript code as React syntax?

For my project, I am using the OpenLayers API Map. I'm unsure of the correct way to incorporate JavaScript code in React or vice versa. Here is an answer on how to use markers in the map, but I am struggling to implement it in my current code since I ...

Discover the process of retrieving an image from the backend with React and Node.js

Hey there! I'm currently working on a Housing blog using ReactJS and NodeJS. One of the tasks I tackled was creating a login controller in NodeJS to send user details, including the image path from the database, to the frontend. The image path is sto ...

Storing files offline in Firefox 3.5 with file:// protocol

While experimenting with the code for offline storage in Firefox 3.5, I referred to a tutorial on . When the page loads, I am prompted with a dialog asking to store data, but after clicking Allow, the dialog does not disappear. The application functions co ...

Tips for resolving the error "Encountered duplicate registration of views named RNGestureHandlerButton" in ReactNative

Seeking guidance on implementing a Swipe-to-Delete feature in my App, I manually installed the react-native-gesture-handler. This action triggered an error message which persists even after attempting to uninstall the gesture handler. Any suggestions or so ...

Trouble with converting NSDictionary into JSON data

Is there a way to convert an NSDictionary into JSON data object for sending to a server? While attempting to use the code below, I am encountering issues when the NSDictionary contains arrays or further nested dictionaries. The code functions correctly wit ...

Soft keyboard on mobile fails to update when arrows are used in Ajax-populated dropdown menus

I am working on a web form that includes two select fields: Country and City: <select id="country" onchange="getCity(this);"> <option value="">-- Please select your country --</option> <option value="1">Austria& ...

I'm looking to configure @types for a third-party React JavaScript module in order to use it with TypeScript and bundle it with webpack. How can I accomplish this?

Imagine you have a third-party npm package called @foo that is all Javascript and has a module named bar. Within your TypeScript .tsx file, you want to use the React component @foo/bar/X. However, when you attempt to import X from '@foo/bar/X', y ...

Solution for displaying table cells in IE 7 and lower using Javascript

Lately, the community has come up with some amazing tools to push early versions of IE beyond their intended capabilities. For example, using multi-column CSS selectors. However, I've been struggling to find a JavaScript that can be loaded conditional ...

Place attribute value directly under the border of an HTML element using a combination of JavaScript and CSS

I'm currently working on a JavaScript script to scan the DOM for elements that have a specific custom attribute called example-type. The goal is to apply CSS styling to draw a border around these elements and then display the value of the example-type ...

Using React Hooks to render radio buttons within a map iteration

My code contains a nested map function where I try to retrieve values from radio buttons. However, the issue is that it selects all radio buttons in a row instead of just one. Below is the snippet of my code: <TableHead> <TableRow> ...

Serve JSON response as text/json in Scala Play 2.1

I'm using Play! 2.2 with Scala and I'm attempting to return a JSON response. The current code serves the response as application/json, but I need it to be served as text/json. While researching, I came across some documentation on . However, the ...

What is the @page rule in Material-UI?

Trying to incorporate Material-UI styles with react-to-print to print components can be tricky, especially when dealing with a specific component that requires a particular page size. Here's an attempt at achieving this: const styles = (theme: Theme) ...

Alter the app's entire background color in React.js with a button click

I am facing an issue with changing the background color of my entire React App when a button is clicked. Currently, I am able to change the color of the button itself but not the background. I have imported the App.css file into my project and I am looking ...

Angular6 HttpClient: Unable to Inject Headers in Get Request for Chrome and IE11

Under my Angular 6 application, I am attempting to make a GET request while injecting some custom Headers: Here is how my service is structured: @Injectable() export class MyService { constructor(public httpClient: HttpClient) { } getUserInfos(login): Ob ...

How can I retrieve objects using the JSON function?

I need to design a function that returns objects like the following: function customFunction(){ new somewhere.api({ var fullAddress = ''; (process address using API) (return JSON data) })open(); } <input type= ...