I have to make a Post request to below and get the response . How can I do this in WordPress.
I have [CLIENT_ID] and [CLIENT_SECRET] – i can just change it.
[REFRESH_TOKEN] is $_GET('code');
POST https://api.envato.com/token
grant_type=refresh_token&
refresh_token=[REFRESH_TOKEN]&
client_id=[CLIENT_ID]&
client_secret=[CLIENT_SECRET]
Please help thanks
‘wp_remote_post’ is the function you’re searching for.
$response = wp_remote_post( $url, array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => array(),
'body' => array( 'param1' => 'value1' ),
'cookies' => array()
)
);
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>';
}