0

I am passing credentials to an API I'm using, but I can't get a response. Here is the code I have tried:

<!DOCTYPE html>
<html>
<body>

<?php
echo "My first PHP script!";

$request = new HttpRequest();
$request->setUrl('https://api.mindbodyonline.com/public/v6/usertoken/issue');
$request->setMethod(HTTP_METH_POST);

$request->setHeaders(array(
  'Content-Type' => 'application/json',
  'SiteId' => '-99',
  'Api-Key' => 'apikey12345'
));

$request->setBody('{
    "Username": "myusername",
    "Password": "mypassword"
}');

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}

?>

</body>
</html>

I see the echo "My first PHP script!" on my page, but I do not see the response. Nothing in the console. Am I doing something wrong?

Andrew
  • 379
  • 1
  • 2
  • 13
  • 1
    See [How do I get PHP errors to display?](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display) – Peter Apr 23 '20 at 14:52
  • Are any errors output? Line 8 would probably fatal error if you don't have the http extension installed. – drussey Apr 23 '20 at 14:53
  • If that's really your complete code, you don't seem to be loading the `HttpRequest` class anywhere. If PHP is configured to hide error messages, [that could explain it all](https://3v4l.org/9iRpE). – Álvaro González Apr 23 '20 at 16:33
  • You probably need to grab their [SDK](https://github.com/mindbody/API-Examples/tree/master/SDKs/PHP). – Álvaro González Apr 23 '20 at 16:37
  • Thanks, it does seem I need to include the HttpRequest class. Not exactly sure how to do that. I'm using cPanel, any advice? – Andrew Apr 27 '20 at 17:13

0 Answers0