Error Message: Incompatibility in Parameter Type Detected in UrlFetchApp Payload

When attempting to make a POST request using Google Apps Script, I encountered the error message: 'Passed parameter type mismatch: 'fields''.

I attempted to resolve this issue by adding JSON.stringify(requestBody) to the payload, however, this solution did not work. What could be causing this problem?

 var fields = ["id","name","group_name"]

  var requestBody = {
    "project_id": "3259344",
    "fields": fields,
    "limit": "30"
} 

  var options =
      {
           'method'  : 'POST',
           'headers' : {
           'User-Id' : email,
           'Authorization' : 'Bearer '+ apiKey
           }, 
          'payload' : requestBody
      };


var response = UrlFetchApp.fetch("https://api.test.com/v2/json/get/keywords", options);

Answer №1

Uncertain about the precise specifications of the API you wish to utilize. Considering the error message from your inquiry, how do the following 3 adjustment patterns sound?

Pattern 1:

Adjusted script:

var fields = ["id","name","group_name"];
var requestBody = {
  "project_id": "3259344",
  "fields": fields,
  "limit": "30"
};
var options = {
  'method'  : 'POST',
  'headers' : {
    'User-Id' : email,
    'Authorization' : 'Bearer ' + apiKey
  }, 
  'payload' : JSON.stringify(requestBody),  // Adjusted
  'contentType': 'application/json'  // Added
};
var response = UrlFetchApp.fetch("https://api.test.com/v2/json/get/keywords", options);

Pattern 2:

Adjusted script:

var fields = "id,name,group_name";  // Adjusted
var requestBody = {
  "project_id": "3259344",
  "fields": fields,
  "limit": "30"
};
var options = {
  'method'  : 'POST',
  'headers' : {
    'User-Id' : email,
    'Authorization' : 'Bearer ' + apiKey
  }, 
  'payload' : JSON.stringify(requestBody),  // Adjusted
  'contentType': 'application/json'  // Added
};
var response = UrlFetchApp.fetch("https://api.test.com/v2/json/get/keywords", options);

Pattern 3:

Adjusted script:

var fields = "id,name,group_name";  // Adjusted
var requestBody = {
  "project_id": "3259344",
  "fields": fields,
  "limit": "30"
};
var options = {
  'method'  : 'POST',
  'headers' : {
    'User-Id' : email,
    'Authorization' : 'Bearer ' + apiKey
  }, 
  'payload' : requestBody
};
var response = UrlFetchApp.fetch("https://api.test.com/v2/json/get/keywords", options);

Resource:

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

Looking to display a gif when a user clicks a button

I need help with making a spinner gif hidden in Unbounce and then show when the user clicks a button. The button is labeled #lp-pom-button-279 and the image is labeled #lp-pom-image-288 My attempts to use JS and CSS have resulted in the gif being either a ...

Ways to navigate to a specific list-group-item using JavaScript

I am working on a bootstrap list-group with a vertical scrollbar and fixed height. The issue I am facing is that the active item is selected programmatically during group creation, but it ends up being out of view when the list is displayed. Is there a wa ...

Tips for modifying javascript code to have popups appear as bPopup instead of in a separate popup window

Is there a way to modify the following code so that popup windows open as dpopups instead of just in a new popup window ()? $(document).ready(function() { var table = $('#taulu').DataTable( { "ajax": "taulu.php", "columnDefs" ...

Maintain a fixed element and enable the rest of the elements to scroll as the mobile browser address bar collapses while scrolling upwards

Currently facing a challenge where I want the background image to remain static while the address bar and content underneath scroll up. The image occupies 90% of the view height, and although I've prevented it from resizing and jumping when the addres ...

"Troubleshooting: Ajax File Uploader Plugin Not Functioning Properly

Today, our web site's file upload feature using the javascript plugin Simple-ajax-uploader suddenly stopped functioning (09/05/2019). The upload div/button is unresponsive when clicked. This issue is not limited to our site; even the official plugin ...

Implementing automatic redirection upon clicking using React without the need for manual clicking

I'm experiencing an issue where the page seems to automatically navigate to another page without clicking on the div. Can anyone explain why this is happening? Here's the code snippet for reference: import React, { Component } from "react&q ...

Unlocking the Power of Global Props in AlpineJS: A Step-by-Step Guide

I'm currently exploring AlpineJS after having some experience with React and basic knowledge of Vue. One thing that has puzzled me about AlpineJS is how to update a state value from within a function, similar to how it's done in React. Let' ...

The phonegap-plugin-push does not successfully register

Currently, I am delving into the realm of app development using Phonegap and experimenting with the Phonegap push plugin available here. I am encountering an issue where the register event fails to fire even after initialization. Here are the steps I have ...

What could be causing the Firebase email verification to result in a 400 error?

I've been struggling to implement email verification in my React website. Every time I try to use the sendSignInLinkToEmail function, I keep encountering this error: XHRPOSThttps://identitytoolkit.googleapis.com/v1/accounts:sendOobCode?key=XXXXXXXXXXX ...

Disabling eventListener upon the occurrence of another event is ineffective

I am having trouble with two functions in my app that create different HTML structures. I want to close the info button event when the menu_div button is clicked, and vice versa. Can anyone provide some help? const menu_div = document.createElement("butt ...

Receiving a 401 error while attempting to make an axios get request with authentication headers

I have been utilizing axios in my React project to fetch data from MongoDB. However, I am facing a challenge with the axios get requests returning a 401 error when I include my auth middleware as a parameter. This middleware mandates that the user must pos ...

Access the JavaScript array within a click function by dynamically generating the array name

Here's a scenario where I have an array like this: var first_array = ['foo','bar','foobar']; My goal is to run a click function that retrieves the array's name and iterates through its elements. The array has an ID ...

Are the functionalities of my code implemented with Node.js and callback functions comparable to Java Threads?

I am unfamiliar with the Node.js concurrency model. Below is an example of creating Java threads and starting them concurrently. package com.main; class MyThread implements Runnable{ private int num = 0; MyThread(int num){ this.num = num; } ...

Refresh the view in AngularJS following a successful $http.get request

I have a <ul> in my HTML view that is populated based on a $http.get request. HTML: <div id="recentlyReleased" ng-controller="sampleRecordController as recCtrl"> <h1>Sample Records</h1> <ul> <li class= ...

In JQuery, an empty string will be returned if it contains the dollar sign character

In the scenario presented here, the value is retrieved accurately with the exception of when it includes a $ symbol at the beginning (e.g. $25.00), in which case it consistently results in an empty string. HTML: <input type="number" class="form-contro ...

Switching user agents to access mobile websites

I'm currently using JavaScript to redirect the main website to the mobile website, but I'm struggling to switch back to desktop view on a mobile device. Is there any way to provide a link labeled "Full Website" that redirects to the main website ...

"Using axios and async/await in VUE.JS to perform multiple asynchronous GET

Perhaps this is a somewhat basic inquiry, as I am still learning the ropes of vue.js and javascript. Please bear with me if my question is not well-articulated or if the solution is straightforward... I am facing an issue where I need to retrieve data from ...

Managing a variety of PHP responses using AJAX

I am currently in the process of designing PHP pages for form processing. On these pages, I aim to redirect if the result is successful or display an error message in case of any errors. The structure of the pages is as follows: $arg = $_POST["arg"]; if ( ...

What could be causing my handle button to slide off the timeline towards the right?

I'm facing an issue with my volume bar component where the slider button is rendering outside of the timeline instead of on top of the progress bar. I need assistance in adjusting its position. // Here is the code for my volume bar component: import ...

Show the present category name within breadcrumbs (utilizing angularJS)

Struggling to display category and vendor names on breadcrumbs? Utilizing the ng-breadcrumbs module but encountering difficulties in making curCategory and curVendor globally accessible. Tried various methods without success. Below is the HTML code snippe ...