Sending data to a Sheetlabs API using Axios

I'm currently collaborating with a service called Sheetlabs to transform a Google Sheet into a full-fledged API. Unfortunately, I'm struggling to find useful resources online apart from the Sheetlabs documentation, as it appears to be a relatively niche service at this stage.

My approach involves using axios within a customized function in Twilio to transmit data to our Sheetlabs API. The API specifically requires HTTP Basic authentication.

I've experimented with various iterations of my axios request, attempting to adhere to the guidance provided in the Sheetlabs SwaggerHub Documentation but I'm feeling stuck.

const url = 'https://sheetlabs.com/records/{organization}/{dbName}';

const postData = {
  trackingid: `${trackingUrl}`,
  phonenumber: `${userPhoneNumber}`
}

const authParams = {
  username: //sheetlabs email,
  password: //access token
}

// axios function
axios.post(url, postData, {auth: authParams}).then(response => {
  console.log('response: ', response);
}).catch(err => {
  console.log('axios sheetlabs post error catch: ', err);
});

Any assistance you can provide would be greatly valued. I'm prepared to furnish any additional details you may require.

Answer №1

When it comes to sending data over the web, AJAX typically uses the

application/x-www-form-urlencoded
format, while Axios opts for JSON. This distinction is highlighted in the network requests section of the example page where $.ajax is utilized.

Axios discusses this default behavior on their Github page here. This difference is significant, as some servers may not be configured to receive JSON data. In such cases, installing the npm install qs package may provide a solution:

const qs = require('qs');
axios.post(url, qs.stringify(postData), {auth: authParams}).then(response => {
  console.log('response: ', response);
}).catch(err => {
  console.log('axios sheetlabs post error catch: ', err);
});

Answer №2

After contacting Sheetlabs Support, it appears that they currently do not offer the functionality to post new records to a Google Sheet. Despite thinking this feature was previously available in their documentation and API. Appreciate the input from everyone.

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

When resizing the window in IE8, the function DIV offsetWidth/Width/innerWidth returns a value of zero

My page is filled with many elements, one of which is the following DIV: <div id="root"> .................. <div id="child1"> ............. </div> <div id="child2"> ............... </div> & ...

Enhance efficiency of repetitive tasks involving accessing the Mongo database

Currently, I am developing a chat bot using MeteorJS/NodeJS, which engages with approximately 2,000 active users on a daily basis. Tracking the number of individuals who interact with the bot each day is made possible by storing their activity information ...

I encountered an error in the console stating, "Uncaught ReferenceError: req is not defined," while trying to access req.query.id

Encountering the error 'Uncaught ReferenceError: req is not defined' when attempting to use req.query.id. Below is the content of my index.js file: const express = require("express"); const path = require("path"); const port = 8000; ...

Leveraging the power of ES6 syntax in Node scripts with Babel

My npm CLI tool utilizes ES6 syntax from BabelJS, specifically arrow functions. Within the entry point of my tool, I'm using the following require: require('babel-core/register'); var program = require('./modules/program.js'); I ...

Encountering error when using require() with Firebase in Express

I am facing an issue with my Express application while attempting to connect it to Firebase. Currently, my console is showing an error message: C:\Users\Tyler\Desktop\Dev\food-bank\app.cjs:19 const firebase = initializeApp(fi ...

Tips for assigning a standard or custom value using JavaScript

What is the best way to automatically assign a value of 0 to my input field when the user leaves it blank? Should I use an if statement { } else { } ...

Is it possible to interpret all events from multiple perspectives?

Is it possible to listen for events in three different ways? This example shows how we can listen for the load event: 1. <body onload="doSomething();"> 2. document.body.onload = doSomething; 3. document.body.addEventListener('load', doS ...

Is it possible to execute MongoDB queries from an AS3 client?

Can native Javascript functions for the mongo shell be run on server side from an AS3 client AIR app? I have experience running Javascript methods embedded/loaded in HTML where SWF is also embedded, and I'm curious if it's possible to make a ser ...

Is it possible to view JavaScript methods in the watch window of IE's debugger?

Can I view custom methods in the IE developer toolbar's watch window? For example, if I have a global function named hello, can I locate it within the DOM? function hello() { alert("hello"); } If so, where in the watch window would I find them? ...

What is the best way to transform a JSON array in text format into a JSON object array using NodeJS or JavaScript?

I have a RESTful API built with Node.JS and ExpressJS. I want to retrieve a JSON array from the FrontEnd and pass it into my API. api.post('/save_pg13_app_list', function (req, res) { var app_list = { list_object: req.body.li ...

Issue with updating a div using jQuery ajax and adding fresh content

How can I update the content of the #calendar div with new data from calendar.php? Although I receive a success alert, the content does not refresh. What adjustments can I make to display the new calendar.php data that was posted? $(document).ready(functi ...

jQuery is unable to locate elements

Here is a JavaScript code snippet that I have: (function($, undefined) { $("a").click(function(event) { //or another elemtnt alert('Hello!'); }) })(jQuery); Also, here is the link being referenced in the code: <a href="http: ...

What is the most effective method to determine if a given string is suitable for $compile in Angular?

I am currently in the process of creating a directive that is designed to accept a "message" input which may contain HTML and nested Angular directives. In my directive's controller, I am using the following code: var compiled = $compile(message)($sc ...

Can someone please explain how to use the prevState in REACT?

Can you explain the difference between how to define the counterHandler function in these two examples? counterHandler = () => { this.setState(() => { return { times: this.state.times + 1 } }); } versus counterHandle ...

Attempting to grasp the concept of ternary condition logic in this specific scenario

Recently, I delved into a code kata involving an array of football scores such as: ["3:1", "2:2"] (The total points here would be 4, 3 + 1) After applying certain rules and summing up the points, I came across an interesting solution: const points = g ...

Using Jquery and Ajax to initiate a load function by clicking a button

I'm currently working on designing a webpage that utilizes jQuery to display content. Additionally, I want the content to be dynamically loaded from a database when users visit the site. My goal is to include a button that, when clicked, will trigger ...

Titanium: Picture -> "automatically"

Imagine there is an image named hello.png with the dimensions of 200x100. A button is then created using this hello.png as shown below: var btn = Titanium.UI.createButton({ bottom : 50, backgroundImage : "images/hello.png", width:100, height:"auto"; }); w ...

Tips for applying a custom design to your MUI V5 styled component

How do I customize the style of a button component in MUI V5? I've been trying to combine old methods with the new version, but it's not working as expected. import { Button } from "@mui/material"; import { styled } from "@mui/mate ...

Would it be possible to use a script to convert the y-axis values of the chart into Arabic numerals?

Currently, I am working on creating line and pie charts, but I need the Y-axis to display Arabic language. $('button').on('click', function(e) { $('#pie-chart3').empty(); var type = $(this).d ...

Investigate the presence of a vertical scrollbar using JQuery or JavaScript

Within an HTML report, I have applied the style "overflow:auto" to allow for dynamic data filling. I am now facing the challenge of detecting whether a vertical scrollbar exists within the report. After scouring various forums for solutions, I came across ...