Hey Colin!
As you mentioned the POST function takes 4 parameters (3 mandatory and an optional one):
- action_url: The API URI (e.g. https://postb.in/api/bin)
- headers: Takes a JSON file and mainly used for authentication.
- body: Takes a JSON object and is mainly the data you’re sending in the request.
- return_type (optional):
- The default “0” returns the response content from the server.
- “1” returns the request status (e.g. =POST(“https://httpbin.org/post",,’{“hello”:"world”}’, 1) returns “200” indicating that the request was successfully sent. While =POST(“https://httpbin.org/wrongurl",,’{“hello”:"world”}’, 1) returns “404” indicating a bad request because of a wrong URI or missing resource.)
- “2” returns the server response as a JSON object with the status, response headers, and content. So a combination of 0 and 1.
For example, when using Postbin:
- When checking out their API documentation, you’ll find that the POST request to create a bin only needs the API URI without headers or body (so we can leave these required parameters empty. So if we do:
A1: =POST("https://postb.in/api/bin",,)
This will return a JSON object with the bin ID created (binId), its creation time in UNIX (now), and its expiration time UNIX (expires),
To confirm that this worked, we can PARSE the binID and use it in a get statement to get its info.
C1: binID
C2: GET Request
C3: now
C4: expires
D1: =PARSE(A1,"['binId']")
D2: =GET("https://postb.in/api/bin/"&D1)
D3: =PARSE(D2,"['now']")
D4: =PARSE(D2,"['expires']")
This will return the bin information which will look like this:
Other APIs, will require things like authentication tokens or client IDs and secrets passed as a JSON object in the headers or body of the call. To do this you can easily create the JSON object using the PAIR2JSON function and pass that to the POST.
For example, if the call required a bearer Authentication which is common in many APIs and it looks like (Authorization: Bearer xxx) where “xxx” is the API key. You can make this call as follows:
A1: Authorization
B1: Bearer xxx
A2: =PAIR2JSON(A1,B1)
B2: =POST("API URI",A2,)
Regarding webhook, we currently don’t support for it but it is definitely part of our product roadmap.
I suggest you also check out our Youtube video on Sending Data to an API for more information.
Please let me know if you have any other questions or come across any issues.