0

I have problem with use NodeJitsu API in PHP curl... I want make php file which will be restart my application.

Here is NodeJistu API: https://www.nodejitsu.com/documentation/api/#restart-an-application But i don't realy now how i can use it in php. Can you help me?

Xawier
  • 165
  • 1
  • 11

1 Answers1

1

They use a simple REST API. You'll need to send an empty HTTP POST request to the url named in the docs. A request body isn't required for the restart action.

I don't have an account for testing there, but following their documentation it could look like this:

/* Login credentials */
$user = 'user';
$pass = 'secret';

/* Application id */
$application = 'foo';

/* Base url */
$baseUrl = 'https://www.nodejitsu.com';

// Create a context for the following HTTP request
$context = stream_context_create(
    'http' => array(
        'method' => 'POST',
        'header' => 'Authorization: Basic '
             . base64_encode("$user:$pass")
    )
);

// Execute the HTTP request to restart the application
$url = "$baseUrl/apps/$user/$application/restart";
$response = file_get_contents($url, false, $context);

// Dump response
var_dump(json_decode($response));

You can use file_get_contents(), curl isn't required.

hek2mgl
  • 152,036
  • 28
  • 249
  • 266
  • Wow! Thanks for code, i made some changes and nowe it's work! http://wklej.to/cY2B6 – Xawier Sep 10 '14 at 23:05
  • Can u say me, how i Can use the same API to take logs? https://www.nodejitsu.com/documentation/api/#get-logs-for-a-specific-application - Becouse i see i need to send a some array with POST action. This the body about which you say? I still can use file_get_contets() instead of curl? – Xawier Sep 10 '14 at 23:17
  • @Xawier Yes, you will need to send a post body (json) - as described in the documentation. Check this page which shows how to send a post body with `file_get_contents()`: http://stackoverflow.com/questions/2445276/how-to-post-data-in-php-using-file-get-contents – hek2mgl Sep 11 '14 at 12:26