How to send the body in wp_remote_post as “raw”?

I got this one working, you have to pass the json_encoded array on the body parameter of the request. $customer_details = [ ‘first_name’ => $first_name, ‘last_name’ => $last_name, ’email’ => $email, ]; $customer_details[‘body’] = json_encode($customer_details); $customer = $api->createUpdateCustomer($customer_details); public function createUpdateCustomer($customer_details) { $response = $this->apiCall( “2.0/customers”, ‘POST’, $customer_details); $result = json_decode($response); return $result; } public … Read more

How to code auto-retry for API call

First you should save the data somewhere in your wordpress. I personally like to use custom tables. Then use a schedule (cron job) to check if there is new data. Then try to submit the data. If you sumitted the data successfully delete it or mark your local data as successfully submitted. Else retry it … Read more

http_response_timeout filter not working

There is no filter named “http_response_timeout” in the WordPress core. Where are you finding this filter name from? The timeout parameter as passed to a wp_remote call has a default of five seconds, and that default can be changed using the “http_request_timeout” filter, which is a different name than you used. Maybe you’re just using … Read more

Publish page remotely

Pat is correct the REST API is the best way to add a new post/page to your site. Here is a more complete guide with an example: https://rudrastyh.com/wordpress/rest-api-create-delete-posts.html#create_post Example code for publishing a new post: $api_response = wp_remote_post( ‘https://WEBSITE/wp-json/wp/v2/posts’, array( ‘headers’ => array( ‘Authorization’ => ‘Basic ‘ . base64_encode( ‘LOGIN:PASSWORD’ ) ), ‘body’ => array( … Read more

How to send file by wp_remote_post?

I found an solution for this issue, i using wp_remote_post to send binary of file to server. When processing data received on server, i use this code to get data of file $file = file_get_contents(‘php://input’); And i write it to temp file $temp = tmpfile(); fwrite($temp, $file); $metadata = stream_get_meta_data($temp); Do you have any other … Read more

How to convert this cURL to wp_remote_*?

/* ########################################################################## * * * DETERMINE ENTITY, via native wp_remote_post() call * /* ########################################################################## */ function get_entity_type_via_wp( $text_to_analyse, // passed string to be handed to GClouD NLP $entity = ‘type’ // part of each “entities” result to return ) { // Google Cloud API key $options = get_option( ‘cxt_settings’ ); $google_nlp_api = $options[‘cxt_gcloud’]; // Call … Read more