AlexaCRM/dynamics-webapi-toolkit

ExecuteAction does not allow for null

tsukasa-sama opened this issue · 4 comments

Describe the bug
Method executeAction in the OData client does not account for nulls being returned

To Reproduce
Use the exectueAction method on an odata client to an action that does not return any data back. An exception is thrown:
Fatal error: Uncaught TypeError: Return value of AlexaCRM\WebAPI\OData\Client::executeAction() must be an object, null returned

Expected behavior
A null should be returned.

Change _$entityId = null ): object {
to $entityId = null ): ?object {

Hi @tsukasa-sama

Could you elaborate at what circumstance you receive null from there?

Thanks

@wizardist:

I am calling an action that was developed by a 3rd party. print_r($res->getBody()) yields:

GuzzleHttp\Psr7\Stream Object
(
    [stream:GuzzleHttp\Psr7\Stream:private] => Resource id #85
    [size:GuzzleHttp\Psr7\Stream:private] => 
    [seekable:GuzzleHttp\Psr7\Stream:private] => 1
    [readable:GuzzleHttp\Psr7\Stream:private] => 1
    [writable:GuzzleHttp\Psr7\Stream:private] => 1
    [uri:GuzzleHttp\Psr7\Stream:private] => php://temp
    [customMetadata:GuzzleHttp\Psr7\Stream:private] => Array
        (
        )
)

And var_dump(json_decode( $res->getBody() )) yields NULL.

This is probably happening because no body is returned on the call.

Ah, that makes sense. Would you like to send a pull request with changes for executeFunction() and executeAction()?

Doesn't matter to me... May be faster for you to just put the two ? in and commit it.