Add a Request Body to a POST Request
The API Connector add-on for Google Sheets enables requests using the GET and POST methods. GET requests are for retrieving information, while POST requests are generally used for creating or updating data.
This article describes how to add a request body to a POST request in API Connector.
- Choose POST method from the drop-down menu
- Enter a POST body
- Create POST body requests based on a cell
- Setting content-type headers
- Adapting instructions for cURL
API Connector defaults to the GET method. To make a POST request, choose POST from the drop-down menu:
ENTER A POST BODY
As part of a POST request, a data payload can be sent to the server in the body of the request. When you select POST from the method drop-down button, the API Connector form changes to display an input field for the post body.
The body contents can be any valid JSON object, for example like this:
"LastName" : "Kravitz",
"UserName" : "anakravitz",
"Email" : "firstname.lastname@example.org"
You can reference cells in the POST 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
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.
Only application/x-www-form-urlencoded and application/json content types are supported.
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:
In the above screenshot, the '-u' flag marks the credentials that get sent in the Header, while the '-d' flags mark the POST request body. To convert these instructions into a format that works with API Connector, convert all the '-d' values into a JSON object, like this:
"billing_address[line1]":"PO Box 9999" ,
Enter the above into the POST body input field as described in the Enter a POST Body section.
• 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.
• Try running your request with a different API tool like Swagger Inspector to help identify whether the issue lies with API Connector settings or with the API request itself.
• Other possible issues are listed in this article on troubleshooting: Troubleshooting API Requests
• If you still have problems, please send over an email to email@example.com, or submit a message using the API Connector Contact Form. You'll receive a response shortly!