Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can you run a POST or PUT with this api #14

Closed
olliedean opened this issue Aug 3, 2019 · 5 comments
Closed

How can you run a POST or PUT with this api #14

olliedean opened this issue Aug 3, 2019 · 5 comments
Labels
question Further information is requested

Comments

@olliedean
Copy link

For example,
$api->station($stationId)->streamers()->create(
string $username,
string $password,
string $displayName,
string $comments,
bool $isActive
);

how would you actually execute this?

@Vaalyn Vaalyn added the question Further information is requested label Aug 3, 2019
@Vaalyn
Copy link
Member

Vaalyn commented Aug 3, 2019

You create a PHP script that uses the composer autoload file to get access to the library, then instantiate a client with the URL/IP and API key for your AzuraCast instance and then just call the method you want to use with the parameters that are specified for it in the corresponding format.

<?php

require __DIR__ . '/vendor/autoload.php';

$api = \AzuraCast\Api\Client::create(
	'my.azuracast.host.com',
	'xxxx:xxxx'
);

$api->station(1)->streamers()->create(
	'vaalyn',
	'mypassword',
        'Vaalyn',
	'This is my personal account',
	true
);

This will send a POST request to the specified AzuraCast instance to create a streamer account.

All you have to do is execute the PHP script then. This can be as simple as running it directly on the command line with via php -f script.php or embed it into an existing PHP application that calls this method somewhere in its workflow.

@olliedean
Copy link
Author

[04-Aug-2019 03:09:54 UTC] PHP Fatal error: Uncaught AzuraCast\Api\Exception\AccessDeniedException: {"code":403,"message":"Permission Denied","formatted_message":"Permission Denied","extra_data":[],"success":false} in /home/itspower/vendor/azuracast/php-api-client/src/AbstractClient.php:58
Stack trace:
#0 /home/itspower/vendor/azuracast/php-api-client/src/Station/StreamersClient.php(85): AzuraCast\Api\AbstractClient->request('POST', 'station/1/strea...', Array)
#1 /home/itspower/public_html/v1/playground.php(20): AzuraCast\Api\Station\StreamersClient->create('vaalyn', 'mypassword', 'Vaalyn', 'This is my pers...', true)
#2 {main}
thrown in /home/itspower/vendor/azuracast/php-api-client/src/AbstractClient.php on line 58

@olliedean
Copy link
Author

I updated both my azuracast, and composer package, and now these errors show for both creating Streamers, and showing nowPlaying data:
[04-Aug-2019 08:49:35 UTC] PHP Fatal error: Uncaught TypeError: Argument 1 passed to AzuraCast\Api\Dto\NowPlayingDto::fromArray() must be of the type array, null given, called in /home/itspower/vendor/azuracast/php-api-client/src/StationClient.php on line 42 and defined in /home/itspower/vendor/azuracast/php-api-client/src/Dto/NowPlayingDto.php:187 Stack trace: #0 /home/itspower/vendor/azuracast/php-api-client/src/StationClient.php(42): AzuraCast\Api\Dto\NowPlayingDto::fromArray(NULL) #1 /home/itspower/public_html/v1/playground.php(10): AzuraCast\Api\StationClient->nowPlaying() #2 {main} thrown in /home/itspower/vendor/azuracast/php-api-client/src/Dto/NowPlayingDto.php on line 187 [04-Aug-2019 08:50:55 UTC] PHP Fatal error: Uncaught TypeError: Argument 1 passed to AzuraCast\Api\Dto\StreamerDto::fromArray() must be of the type array, null given, called in /home/itspower/vendor/azuracast/php-api-client/src/Station/StreamersClient.php on line 88 and defined in /home/itspower/vendor/azuracast/php-api-client/src/Dto/StreamerDto.php:233 Stack trace: #0 /home/itspower/vendor/azuracast/php-api-client/src/Station/StreamersClient.php(88): AzuraCast\Api\Dto\StreamerDto::fromArray(NULL) #1 /home/itspower/public_html/v1/playground.php(17): AzuraCast\Api\Station\StreamersClient->create('vaalyn', 'mypassword', 'Vaalyn', 'This is my pers...', true) #2 {main} thrown in /home/itspower/vendor/azuracast/php-api-client/src/Dto/StreamerDto.php on line 233

@Vaalyn
Copy link
Member

Vaalyn commented Aug 4, 2019

The first error you posted (AzuraCast\Api\Exception\AccessDeniedException) is showing because your API key seems to be invalid. Please check that you created an API key in AzuraCast and that you've copied it correctly into your script.

About the Uncaught TypeError I'm not quite sure what's causing this yet. I've just tested the following code on my local dev installation on the newest versions of both AC and the client library and got no errors:

<?php

require __DIR__ . '/vendor/autoload.php';

$api = \AzuraCast\Api\Client::create(
    'localhost',
    'fad674101a36198c:397fc35b10da7f0ace26f8080dede0b3'
);

$newStreamer = $api->station(1)->streamers()->create(
    'vaalyn',
    'mypassword',
    'Vaalyn',
    'This is my personal account',
    true
);

var_dump($newStreamer);
var_dump($api->station(1)->nowPlaying());

Could you copy and paste your code here so that I can take a look at it?

@olliedean
Copy link
Author

I fixed it by generating a new API key

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants