Actually it is more general question but now i am trying to use it on wordpress site so I preferred to post it here. I am trying to understand the difference between remote post and form post. When I query a string and post it to remote server, I get the result as string and with "print $response" see it on browser console. But I want it to be displayed as html on browser. Am I expecting wrong thing or …
My function below includes a cURL call which throws a text string at a Google Cloud text analysis API, returning a response object, which we then parse to get a specific piece. It has been recommended to me that I switch the cURL PHP statement to use WordPress' wp_remote_get. I have read the docs for that but, to be honest, I don't understand how my cURL header fields should map to wp_remote_get arguments. Or even if it should be wp_remote_post …
I'm somehow new to Wordpress and its API and while writing an simple Rest Service to an remote Server i have been asked to use the native wp_remote_X functions. Right now i have some trouble to distinguish between them both: wp_remote_post() wp_remote_request(). Does it make any difference which one to use or is the wp_remote_request an alias to missing wp_remote_delete() and wp_remote_update() ?
I'm trying to post content with wp_remote_post. Content that I want to be posted is in a separate php file, which echo's block with html and WPBakery shortcode. I tried include but it didn't work, I tried file_get_contents but it posts 1 in the content as if there were no errors executing the code. Code that I use: $postDataContent = "blahblahblah"; $api_response = wp_remote_post( 'https://SITE/wp-json/wp/v2/posts', array( 'headers' => array( 'Authorization' => 'Basic ' . base64_encode( $username . ':' . $password …
I'm not sure if I'm asking the right question, so here is the context. I'm making a POST to an API (The api is to a Google Sheets Script - so there are some unusual limitations). When I use postman the data is returned in a json file. In order to get it to work in postman I have to send the parameters via the body and I have to select the raw option. Selecting any other option(i.e. x-www-form-urlencoded or …
I would like to use wp_remote_post to retrieve data from an external API. The matter is that the external API only accepts a maximum of 5 requests per second. However, depending on how many users are using the related feature on my website, my website may send more than 5 requests per second. How can I, in Wordpress, enqueue (or limit) the output requests (or the use of wp_remote_post) in order to allow only 5 external API calls per second …
On my site I have a form that can be filled out by users. Once submitted, I am storing the form data in a third-party service using their RESTful API. function gravity_forms_1_after_submission( $entry, $form ) { if ( rgar( $entry, 'status' ) === 'spam' ) { return; } $response = wp_remote_post( esc_url_raw( '...' ), array( 'headers' => array( ... ), 'body' => json_encode( array( ... ) ) ) ); if ( is_wp_error( $response ) ) { ... } else { …
Ok, I've searched a lot but cannot understand what I'm missing. I need to post some data to a php file on another server, but if I print the wp_remote_post variable I get: {"headers":{},"body":"","response":{"code":200,"message":"OK"} ..... here the code: $url = 'https://xxx.domain.net/api/api.php'; $args = array( 'method' => 'POST', 'timeout' => 45, 'sslverify' => false, 'headers' => array( 'Authorization' => 'xxxx', 'Content-Type' => 'application/json; charset=utf-8', ), 'body' => json_encode($attachment_fields), 'data_format' => 'body' ); $request = wp_remote_post( $url, $args ); and $attachment_fields is …
I am using wp_remote_post to send a request to a 3rd parti API. The response from the API looks something like: { status: 'a', member_id: 12345678 } I understand that this is returned in the body of the array returned by wp_remote_post, but I'm having problems checking the value of status. here's what I've got: $response = wp_remote_post($url, $myArr); if ( is_wp_error( $response ) ) { $error_message = $response->get_error_message(); echo "Something went wrong: $error_message"; } else { echo 'Status: ' …
I have a problem with a plugin I'm working on, I have implemented a cron that 2 times a day makes a call to update the data, the call is made with the wp_remote_post function. $response = wp_remote_post( ENDPOINT, array( 'method' => 'POST', 'headers' => array( 'Content-Type' => 'application/json; charset=utf-8', 'domainUrl' => get_site_url(), ), 'body' => wp_json_encode( $body ), ) ); the problem is in the get_site_url() function. For a site that uses the https protocol, get_site_url() returns the domain …
I am developing a plugin that has a long-running function for setting up a load of posts of a custom post type. I want to run this function asynchronously. In order to do this, I have tried something like this: add_action( 'admin_post_my_action', 'my_long_running_function' ); $url = admin_url( 'admin-post.php' ); $args = [ 'method' => 'POST', 'timeout' => 50, 'redirection' => 5, 'blocking' => true, 'headers' => [] , 'body' => [ 'action' => 'my_action' ], 'cookies' => [] ]; $response …
I am trying to create a basic plugin to send user details to a CRM when a user signs up on the WordPress website as a basic subscriber. I have reached a sticking point, I have tried to interpret the API details as best as I can, but I am unsure, if I am formatting my body data properly as it just isn't working. I can get the POST to work using Postman, however that is via json/javascript and on-site …
I have this cURL code below which is running on PHP, yet when I did it with WordPress it didn't work. I tried using WP_REMOTE_POST I couldn't do the return transfer function of cURL, what can be a replacement for that or how can I use cURL in my WordPress website. (PS cURL is enabled and work fine for get method but have errors in post method.) my cURL code try{ $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: …
I want to post to multiple rest API endpoints with wp_remote_post but don't want to wait for the response back and keep continuing code execution. Some popular clients like guzzle etc. support asynchronous Http call. Does wp_remote_post also support the same? If yes how can I achieve that?
I can successfully make the RESTful post using cURL: $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://api.mindbodyonline.com/public/v6/usertoken/issue'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, "{\n \"Username\": \"Siteowner\",\n \"Password\": \"apitest1234\"\n}"); $headers = array(); $headers[] = 'Content-Type: application/json'; $headers[] = 'Api-Key: {myapikey}'; $headers[] = 'Siteid: 999999'; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $response = curl_exec($ch); print_r($response); if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } curl_close($ch); However, what seems to be the same request using wp_remote_post, fails to deliver the "Api-Key" in the headers: $headers = array(); …
I am new to this. Figuring out how to use it. I am trying to create a custom post by filling out a frontend form. I am using ajax button in the form. This button triggers wp_remote_post().I have the following doubts. I have a front form. can that be used to create a custom post by filling out and that creates the custom post with on the same website? When I visited a website they said header authorization is not …
I need to submit a form on the woo-commerce product page via restful API custom endpoint the problem is the wp_remote_post not working correctly with me or me mostly I did something wrong. The form is add to cart form and it has a lot of custom data, not the usual add to cart. for plugin called yith composite to specific My code so far add_action('rest_api_init', function () { register_rest_route( 'yith-composite', 'add-item',array( 'methods' => 'POST', 'callback' => 'yith_custom_add_item' )); }); …