One of the easiest ways to post JSON content is to use an external utility, such as a cURL, whose task is to transfer data over URLs. We have two ways to transfer data:
- Directly as a JSON in the body of an HTTP POST request, with a specific content-type header, and this is the preferred method
- As a URL-escaped JSON inside the payload parameter as part of the POST body
In the first case, we are going to use cURL with the following bits:
-X POST
It specifies the method to use to communicate with an HTTP server. The default method is GET , but here, we have to POST some information:
-H 'Content-type: application/json'
This option allows us to send extra headers to the HTTP server. In our case, we are sending a Multipurpose Internet Mail Extensions (MIME) type, informing the Slack server that it has to expect a JSON (rfc4627) application type object...