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.

  • Can you elaborate? When do you need to hit the API? What's the full context here. – Jacob Peattie Jul 21 '17 at 12:07
  • curl? – kero Jul 21 '17 at 12:08
  • check out again? – Daniel Bamal Jul 21 '17 at 12:12
  • Take a look here. – kaiser Jul 25 '17 at 20:07

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 );

If you need to interact with the API via JavaScript, then WordPress doesn't get involved, and you would do it the same way you'd do it any any JavaScript application.

Not the answer you're looking for? Browse other questions tagged or ask your own question.