rest api – WP_REMOTE_POST Requests are being blocked by API provider


I’m trying to make some API POST requests via WordPress’ own method i.e. wp_remote_post()

Here is the sample code I’m using:

$args = array (
    'sslverify' => false,
    'headers' => [
        'Authorization: Bearer {API_KEY}',
        'Content-Type: application/json'
    'body' => array (
        'region' => 'USA',
        'plan' => 1,
        'label' => 'API Test',
        'app_id' => 2

$response = wp_remote_post( "", $args );

$response = wp_remote_retrieve_body($response);


But it returns me a 403 Forbidden error, Here are the details:

<head><title>403 Forbidden</title></head>
<center><h1>403 Forbidden</h1></center>

But when I try to use the cURL PHP Library to make POST requests with the same parameters and settings, the API request is successful and I’m returned with 200 Response with formatted JSON data.

I have contacted the API provider company and they say that everything is fine from their side, and they cannot do anything for it.

One more thing, I have tested the same calls on a live website server and on the localhost environment as well. But the situation is the same for both scenarios.

Can anybody have an idea why wp_remote_post() is causing these errors on this specific API provider (Yes, I have tested wp_remote_post method with another API provider and it seems to work well)?

Thank you very much!
Duryab Aziz.

Duryab 1 month 2021-05-12T13:31:50-05:00 0 Answers 0 views 0

Leave an answer