Try using a GET request instead of a POST request. The headers indicate they only allow origin from weedmaps.com in the POST request. The method in WordPress is wp_remote_get().
function call_for_api() {
$url="https://api-v2.weedmaps.com/api/v2/listings";
$response = wp_remote_get( $url,
array(
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => array(
'accept' => 'application/json',
'accept-encoding' => 'gzip, deflate, br',
'connection' =>'keep-alive'
),
'body' => null,
'cookies' => array(),
'compress' => false,
'decompress' => true,
'sslverify' => true,
'stream' => false,
'filename' => null,
'user-agent' => 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0',
)
);
if ( is_wp_error( $response ) ) {
$error_message = $response->get_error_message();
echo "Something went wrong: $error_message";
} else {
echo 'Response:<pre>';
print_r( $response );
echo '</pre>';
echo wp_remote_retrieve_body( $response );
}
}
function cf_shortcode() {
ob_start();
call_for_api();
return ob_get_clean();
}
add_shortcode( 'weed-list', 'cf_shortcode' );