I am new to WordPress and I have a client requirement to hit their API, which accepts a POST request and I just can't find out the way to achieve this. I have to add the chat bot which hits API whenever user presses enter and display response of API.
closed as unclear what you're asking by Jack Johansson♦, cjbj, Dave Romsey, kraftner, kaiser Jul 25 '17 at 20:07
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
WordPress has several functions for sending requests via PHP, including
wp_remote_post(), which you can use to send a POST request to an API. Then you can use
wp_remote_retrieve_body() to handle the response. It would look something like:
$response = wp_remote_post( 'http://example.org/api' ); $api_response = json_decode( wp_remote_retrieve_body( $response ), true );