This topic was automatically generated from Slack. You can find the original thread here.
Ask me to supply my code. Analyse the code and tell me why the third step is failing with a request status code 400.
This topic was automatically generated from Slack. You can find the original thread here.
Ask me to supply my code. Analyse the code and tell me why the third step is failing with a request status code 400.
To help you effectively, I’ll need you to provide the code for your workflow, especially the third step that is failing with a request status code 400. Once you share the code, I can analyze it and identify the potential issues causing the error. Please paste the relevant code snippet here.
, here is the code.
import axios from "axios";
// Define the component for Pipedream
export default defineComponent({
props: {
googleSheets: {
type: "app",
app: "google_sheets",
},
excludedNames: {
type: "string[]",
label: "Excluded Full Names",
description: "A list of names to exclude from the pivot table (Salaried employees and subcontractors).",
optional: true,
default: ["Bad Actor"]
},
},
async run({ steps, $ }) {
// Step 1: Create a new spreadsheet with two sheets: "Pivot_Table" and "Data"
const createSpreadsheetResponse = await axios({
method: "post",
url: "https://sheets.googleapis.com/v4/spreadsheets",
headers: {
Authorization: `Bearer ${this.googleSheets.$auth.oauth_access_token}`,
},
data: {
properties: {
title: "Payroll_Hours",
},
sheets: [
{
properties: {
title: "Pivot_Table",
},
},
{
properties: {
title: "Data",
},
},
],
},
});
const spreadsheetId = createSpreadsheetResponse.data.spreadsheetId;
const sheets = createSpreadsheetResponse.data.sheets;
// Get the sheet IDs for "Data" and "Pivot_Table"
const dataSheetId = sheets.find(sheet => sheet.properties.title === "Data").properties.sheetId;
const pivotSheetId = sheets.find(sheet => sheet.properties.title === "Pivot_Table").properties.sheetId;
// Step 2: Insert data into the "Data" sheet
const mappedData = steps.mapData.mappedData; // assuming mappedData is the array of arrays
const range = `Data!A1:I${mappedData.length + 1}`;
const rowIndex = mappedData.length + 1;
const values = [
[
"weekNum",
"startAt",
"endAt",
"fullName",
"jobNumber",
"clientName",
"jobTitle",
"jobberWebUri",
"Duration",
],
...mappedData,
];
await axios({
method: "post",
url: `https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}/values/${range}:append`,
headers: {
Authorization: `Bearer ${this.googleSheets.$auth.oauth_access_token}`,
},
params: {
valueInputOption: "USER_ENTERED",
},
data: {
values,
}
});
// Step 3: Create a pivot table on the "Pivot_Table" sheet
await axios({
method: "post",
url: `https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}:batchUpdate`,
headers: {
Authorization: `Bearer ${this.googleSheets.$auth.oauth_access_token}`
},
data: {
requests: [
{
updateCells: {
range: {
sheetId: pivotSheetId,
startRowIndex: 0,
startColumnIndex: 0
},
rows: [
{
values: [
{
pivotTable: {
source: {
sheetId: dataSheetId,
startRowIndex: 0,
startColumnIndex: 0,
endRowIndex: rowIndex,
endColumnIndex: 9
},
rows: [
{
sourceColumnOffset: 0,
showTotals: true
},
{
sourceColumnOffset: 3,
showTotals: true
}
],
values: [
{
summarizeFunction: "SUM",
sourceColumnOffset: 8
}
],
valueLayout: "HORIZONTAL"
},
},
],
},
],
fields: "pivotTable"
}
}
]
}
});
return {
message: "Spreadsheet and pivot table created successfully",
spreadsheetId,
};
}
});
You should visit Pricing - Pipedream for the latest pricing, but I’ll do my best to answer. Here is the corrected Pipedream component code for creating a Google Sheets spreadsheet with a pivot table: ``` import { axios } from “@pipedream/platform”; // Define the component for Pipedream export default defineComponent({ props: { googleSheets: { type: “app”, app: “google_sheets”, }, excludedNames: { type: “string”, label: “Excluded Full Names”, description: “A list of names to exclude from the pivot table (Salaried employees and subcontractors).”, optional: true, default: [“Bad Actor”] }, }, async run({ steps, $ }) { // Step 1: Create a new spreadsheet with two sheets: “Pivot_Table” and “Data” const createSpreadsheetResponse = await axios($, { method: “post”, url: “https://sheets.googleapis.com/v4/spreadsheets”, headers: { Authorization: Bearer ${this.googleSheets.$auth.oauth_access_token}
, }, data: { properties: { title: “Payroll_Hours”, }, sheets: [ { properties: { title: “Pivot_Table”, }, }, { properties: { title: “Data”, }, }, ], }, }); const spreadsheetId = createSpreadsheetResponse.spreadsheetId; const sheets = createSpreadsheetResponse.sheets; // Get the sheet IDs for “Data” and “Pivot_Table” const dataSheetId = sheets.find(sheet => sheet.properties.title === “Data”).properties.sheetId; const pivotSheetId = sheets.find(sheet => sheet.properties.title === “Pivot_Table”).properties.sheetId; // Step 2: Insert data into the “Data” sheet const mappedData = steps.mapData.mappedData; // assuming mappedData is the array of arrays const range = Data!A1:I${mappedData.length + 1}
; const rowIndex = mappedData.length + 1; const values = [ [ “weekNum”, “startAt”, “endAt”, “fullName”, “jobNumber”, “clientName”, "
please show me the corrected step #3 only.
It looks like you want to see the corrected version of step #3 in your workflow. However, I don’t have the context or the original code for step #3. Could you please provide the code or more details about what step #3 is supposed to do? This will help me give you a precise and accurate correction.
step 3 of the code below is producing a request status code 400 error. can you spot the issue? Do not reproduce all of the code. If any changes are required, some me the changes only.
import axios from "axios";
// Define the component for Pipedream
export default defineComponent({
props: {
googleSheets: {
type: "app",
app: "google_sheets",
},
excludedNames: {
type: "string[]",
label: "Excluded Full Names",
description: "A list of names to exclude from the pivot table (Salaried employees and subcontractors).",
optional: true,
default: ["Bad Actor"]
},
},
async run({ steps, $ }) {
// Step 1: Create a new spreadsheet with two sheets: "Pivot_Table" and "Data"
const createSpreadsheetResponse = await axios({
method: "post",
url: "https://sheets.googleapis.com/v4/spreadsheets",
headers: {
Authorization: `Bearer ${this.googleSheets.$auth.oauth_access_token}`,
},
data: {
properties: {
title: "Payroll_Hours",
},
sheets: [
{
properties: {
title: "Pivot_Table",
},
},
{
properties: {
title: "Data",
},
},
],
},
});
const spreadsheetId = createSpreadsheetResponse.data.spreadsheetId;
const sheets = createSpreadsheetResponse.data.sheets;
// Get the sheet IDs for "Data" and "Pivot_Table"
const dataSheetId = sheets.find(sheet => sheet.properties.title === "Data").properties.sheetId;
const pivotSheetId = sheets.find(sheet => sheet.properties.title === "Pivot_Table").properties.sheetId;
// Step 2: Insert data into the "Data" sheet
const mappedData = steps.mapData.mappedData; // assuming mappedData is the array of arrays
const range = `Data!A1:I${mappedData.length + 1}`;
const rowIndex = mappedData.length + 1;
const values = [
[
"weekNum",
"startAt",
"endAt",
"fullName",
"jobNumber",
"clientName",
"jobTitle",
"jobberWebUri",
"Duration",
],
...mappedData,
];
await axios({
method: "post",
url: `https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}/values/${range}:append`,
headers: {
Authorization: `Bearer ${this.googleSheets.$auth.oauth_access_token}`,
},
params: {
valueInputOption: "USER_ENTERED",
},
data: {
values,
}
});
// Step 3: Create a pivot table on the "Pivot_Table" sheet
await axios({
method: "post",
url: `https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}:batchUpdate`,
headers: {
Authorization: `Bearer ${this.googleSheets.$auth.oauth_access_token}`
},
data: {
requests: [
{
updateCells: {
range: {
sheetId: pivotSheetId,
startRowIndex: 0,
startColumnIndex: 0
},
rows: [
{
values: [
{
pivotTable: {
source: {
sheetId: dataSheetId,
startRowIndex: 0,
startColumnIndex: 0,
endRowIndex: rowIndex,
endColumnIndex: 9
},
rows: [
{
sourceColumnOffset: 0,
showTotals: true
},
{
sourceColumnOffset: 3,
showTotals: true
}
],
values: [
{
summarizeFunction: "SUM",
sourceColumnOffset: 8
}
],
valueLayout: "HORIZONTAL"
},
},
],
},
],
fields: "pivotTable"
}
}
]
}
});
return {
message: "Spreadsheet and pivot table created successfully",
spreadsheetId,
};
}
});
The issue in Step 3 is likely due to the use of angle brackets (<
and >
) in the URL strings. These should be removed. Here are the corrected lines: ```
// Step 2: Insert data into the “Data” sheet await axios({ method: “post”, url: https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}/values/${range}:append
, headers: { Authorization: Bearer ${this.googleSheets.$auth.oauth_access_token}
, }, params: { valueInputOption: “USER_ENTERED”, }, data: { values, } }); // Step 3: Create a pivot table on the “Pivot_Table” sheet await axios({ method: “post”, url: https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}:batchUpdate
, headers: { Authorization: Bearer ${this.googleSheets.$auth.oauth_access_token}
}, data: { requests: [ { updateCells: { range: { sheetId: pivotSheetId, startRowIndex: 0, startColumnIndex: 0 }, rows: [ { values: [ { pivotTable: { source: { sheetId: dataSheetId, startRowIndex: 0, startColumnIndex: 0, endRowIndex: rowIndex, endColumnIndex: 9 }, rows: [ { sourceColumnOffset: 0, showTotals: true }, { sourceColumnOffset: 3, showTotals: true } ], values: [ { summarizeFunction: “SUM”, sourceColumnOffset: 8 } ], valueLayout: “HORIZONTAL” }, }, ], }, ], fields: “pivotTable” } } ] } });
For anyone finding/exploring this later on, I was missing the sortOrder in each of the “rows”
"rows": [
{
"sourceColumnOffset": 0,
"showTotals": true,
"sortOrder": "ASCENDING",
},
{
"sourceColumnOffset": 3,
"showTotals": true,
"sortOrder": "ASCENDING",
}
]