Google Sheets spreadsheets.values.update not working when using axios

  Kiến thức lập trình

I am working on a simple internal react native application for my company. I am trying to update an excel sheet using google’s apis via axios requests. I have used Google’s oAuth (via Firebase) and am authenticated properly.

Here is the code (be advised that some of the variables are not used yet. I will update that when this code works):

const doWriteToGoogleSheets = async (sheetId, sheetName, range, majorDimension) => {
    await axios.put(`https://sheets.google.com/v4/spreadsheets/${sheetId}/values/${sheetName}!${range}?valueInputOption=${VALUE_INPUT_OPTION.USER_ENTERED}&key=${AUTH_SHEETS_API_KEY}`, {
        range: `${sheetName}!${range}`,
        majorDimension: "ROWS",
        values: [
            ["NAMESS"] // test value, try with only 1 cell as the range
        ],
    })

}

I have also tested using:

    await axios.put(`https://sheets.google.com/v4/spreadsheets/${sheetId}/values/'TimeFullYear (Input Here)'!A1?valueInputOption=${VALUE_INPUT_OPTION.USER_ENTERED}&key=${AUTH_SHEETS_API_KEY}`, {
        "range": "'TimeFullYear (Input Here)'!A1",
        "majorDimension": "ROWS",
        "values": [
            [
                "NAMESS"
            ]
        ]
    })

and

  await axios.put(`https://sheets.google.com/v4/spreadsheets/${sheetId}/values/'TimeFullYear (Input Here)'!A1?valueInputOption=${VALUE_INPUT_OPTION.USER_ENTERED}&key=${AUTH_SHEETS_API_KEY}`, {
        range: "TimeFullYear (Input Here)!A1",
        majorDimension: "ROWS",
        values: [
            [
                "NAMESS"
            ]
        ]
    })

THE PROBLEM

My logger is saying that the code completed successfully (no error was thrown) but then I get “undefined” as a response (after the “:” is where the response should be):

SUCCESS - write to timecards: undefined

And when I check in the google sheet nothing is updated.

WHAT I KNOW

  • I am authenticated properly. I know this as my Google Sheets get request does work
  • I have enabled the required scopes (https://www.googleapis.com/auth/spreadsheets)

HELP

can someone help me out?

EDIT

  • VALUE_INPUT_OPTION.USER_ENTERED is equal to the string “USER_ENTERED”
  • I am following these docs: https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/update

2

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website Kho Theme wordpress Kho Theme WP Theme WP

LEAVE A COMMENT