3

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

1 Answer 1

6

'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>';
}
4
  • @LatheeshVMVilla yes, it’s only an example. You should fill the request according to your needs. Nov 10, 2018 at 18:26
  • @LatheeshVMVilla Sorry, but it’s problem with your remote server and not with WP, so I’m afraid we won’t be able to help with that 🤷🏻‍♂️ Nov 10, 2018 at 18:54
  • 1
    Any way i was able to understand the process with your answer..i will make it work some how .thanks :)
    – user145078
    Nov 10, 2018 at 18:59
  • 1
    Hey, now i do understand the process, the above method works ..i was passing the wrong url, also alternative will be curl method. thanks
    – user145078
    Nov 10, 2018 at 21:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.