Search API Connector Documentation

Print

Add Request Body

The API Connector add-on for Google Sheets enables requests using the GET, POST, PUT, PATCH, and DELETE methods.

Not all APIs strictly follow this usage, but in general, request methods are defined as follows:

  • GET: retrieve data
  • POST: create data
  • PUT: fully update (i.e. replace) an existing record
  • PATCH: update part of an existing record
  • DELETE: delete records

This article describes how to add a request body to a POST, PUT, or PATCH request in API Connector.

Contents

Before You Begin

Click here to install the API Connector add-on from the Google Marketplace.

Choose the POST Method

API Connector defaults to the GET method. To make a POST, PUT, or PATCH request, choose that method from the drop-down menu:

Enter a Request Body

As part of a POST, PUT, or PATCH request, a data payload can be sent to the server in the body of the request. When you select one of those methods from the method drop-down button, the API Connector form changes to display an input field for the request body.

The body contents can be any valid JSON object, for example like this:

{
   "FirstName": "Peter"
   "LastName" : "Piper",
   "UserName" : "ppiper",
   "Email"    : "ppiper@example.com"
 }

Multiple Request Bodies

Please check this article for information on cycling through a list of request bodies (paid feature): https://mixedanalytics.com/knowledge-base/api-connector-run-multiple-queries-single-request/

Use Cell Values in Request Bodies

You can reference cells in the request body by wrapping your cell reference in 3 plus signs on either side. (The plus signs tell API Connector that this is a cell reference and not part of the original URL.) So a reference to cell B2 in a tab called QuerySheet would be written like this: +++QuerySheet!B2+++.

Additional details are provided in this article: Create API Request Based on a Cell

Setting Content-Type Headers

A content-type header describes the object’s format, so the server knows how to parse it. The default content type will be application/x-www-form-urlencoded. API Connector will use this content type unless you manually set Key = content-type, Value = application/json in the Headers table, like this.
post-requests-img3

Only application/x-www-form-urlencoded and application/json content types are supported.

Adapting Instructions for cURL

Many services provide documentation on how to make API requests using cURL, a popular command-line tool for interacting with APIs. For example, here is some documentation from Chargebee on how to make a POST request with cURL:

post-requests-img4

There are two ways to import these cURL commands into API Connector: automatic and manual.

Method 1: Automatic

The easiest way to convert these instructions into a format that works with API Connector is to use API Connector’s cURL import tool (Add-ons > API Connector > Import / Export > Import from cURL). Simply paste in the entire cURL command and hit Import to view the request in the API Connector sidebar.

The cURL import tool will work with most standard cURL snippets, but not with graphQL or multi-part cURL requests.

Method 2: Manual

Alternatively, you can convert cURL commands manually. In the above screenshot, the -u flag marks the user credentials that get sent in the Header, while the -d flags mark the POST request body (other cURL options/flags are listed here). To convert these instructions into a POST body that works with API Connector, convert all the -d values into a JSON object, like this:

{
   "plan_id":"cbdemo_free" ,
   "auto_collection":"off",
   "customer[first_name]":"John" ,
   "customer[last_name]":"Doe" ,
   "customer[email]":"john@user.com" ,
   "billing_address[first_name]":"John" ,
   "billing_address[last_name]":"Doe" ,
   "billing_address[line1]":"PO Box 9999" ,
   "billing_address[city]":"Walnut" ,
   "billing_address[state]":"California" ,
   "billing_address[zip]":"91789" ,
   "billing_address[country]":"US"
}

Enter the above into the POST body input field as described in the Enter a request body section.

Troubleshooting

  • If your POST request isn’t working, a likely cause is a mismatched content type. Try adding in a content type into the header as described above, where Key = content-type, and Value = application/json.
  • If you need to send an empty request body, enter {}
  • Other possible issues are listed in this article on troubleshooting: Troubleshooting API Requests
Previous Include Headers
Next Set Data Destination

21 thoughts on “Add Request Body”

  1. Ana, even though I appreciate having a POST option available, I don’t see how to take advantage of it considering there’s no actual integration with the google sheets content; maybe I’m missing something? Thanks.

    Reply
    • Hi Oscar, you can send a post request and the resulting response gets printed into your Google Sheet. You can also base the request URL on values in a cell. Can you please let me know what you mean by integration with the Google Sheets content? Maybe you’re referring to basing the request body on a value in a cell? That feature is coming : )

      Reply
  2. Hello, I would like to know how to create a POST request that could do the same that a PUT request in PostMan do, for example, PUT type request in GitHub API.

    Reply
    • Hi there, a POST request can’t do the same thing as a PUT request as they are different methods with different functions. API Connector only supports GET and POST, though I’ll consider adding more methods if I get more demand for it.

      Reply
    • Sorry, there is no way to include a file, you can only enter values directly or reference cells that contain the values you need.

      Reply
  3. A very interesting conversation. I have recently used ReqBin. With this client, you can post HTTP requests to the server and check server responses fully online, with no desktop app needed.

    Reply
  4. Great tool! 🙂
    I managed to connect to my service successfully.
    1. I encoded the user ID and password in Bas64.
    2. I called the API URL with Authorization Basic and added the bace64-Code.
    3. I added {“grant_type”:”client_credentials” ,} to the POST body.

    I then get a token written in the sheet.

    To extract data from the API I built another (GET) request:
    I called the API URL with Authorization Bearer and added the token i got from the other request.

    That also worked fine. But it is not very convenient to always run both requests and copy the restult of the first (the token) into the second.

    How can I combine these two request to one?

    I would appreciate your help very much! 🙂

    Reply
    • Hi Philipp, it sounds like you’re running an OAuth2 process manually, so I think the best solution is just to use API Connector’s OAuth2 manager (info). That way you won’t need to encode to base64 and keep manually refreshing your token.

      However if you’d like to continue with this method, I think you can semi-automate your process by referencing your token in its cell (info) instead of manually copying it in. That way you’d have, say, request #1 sending to a sheet called Token, then request #2 would include Authorization Bearer +++Token!A5+++. Then you just need to click Run twice in a row to retrieve and use the new token.

      Just let me know if I can clarify further.

      Reply
  5. Ana, I need some custom work for a few stores that is beyond my abilities. Do you do that or recommend someone with good knowledge of the API connector?

    Reply
    • Hi Rob, thank you for the message. I don’t know anyone offhand, but I’ve seen people post this type of request on upwork.com. You could also try on the API Connector user forum: https://www.reddit.com/r/api_connector.
      Of course if you just have questions about setting up your requests, I’ll be happy to assist you myself.

      Reply
    • If it says invalid POST body data that means it isn’t valid JSON. Maybe you’ve inadvertently copied in some extra characters, or maybe I wrote it wrong to start with, I can’t really say much without seeing it. Can you please paste your JSON here? I can check it out.

      Reply
  6. That looks all right so I would try re-typing the quotation marks to make sure they are straight quotation marks. Sometimes copying/pasting can automatically replace one version with another, and curly quotes won’t work. Can you please try that?

    Reply
    • I’m not totally sure what you mean by relative reference here, but if you’d like to add multiple request bodies you need to add them one after the other with :::BREAK::: in between. So there’s no way to do something like +++Sheet!K23:K25+++ in the request body, if that’s what you mean.

      Reply

Leave a Reply to Jon Cancel reply

Table of Contents