AlexaCRM / dynamics-webapi-toolkit

Dynamics 365 Web API Toolkit for PHP
MIT License
77 stars 58 forks source link

Response 401 UnAuthorise #12

Closed Andlibmehndi closed 5 years ago

Andlibmehndi commented 5 years ago

Hi, I have connected using the tutorial which mentioned on "dynamics-webapi-toolkit", but there is one error is arriving while executing create/update/delete or retrieve.

the Error is "Exception has occurred. GuzzleHttp\Exception\ClientException: Client error: GET https://organizationURL/api/data/v9.1/ resulted in a 401 Unauthorized response"

my code is as below:

$client = \AlexaCRM\WebAPI\ClientFactory::createOnlineClient(
        'URL',
        'Application ID',
        'App key'
    );
    $contact = new \AlexaCRM\Xrm\Entity( 'contact' );
    $contact['firstname'] = 'Nancy';
    $contact['lastname'] = 'Anderson';
    $contact['emailaddress1'] = 'someone_c@example.com';

    $contactId = $client->Create( $contact );

could you please help me with this.

georged commented 5 years ago

@Andlibmehndi

there could be multiple reasons for this error:

Thanks

Andlibmehndi commented 5 years ago

@georged yes, I have done all this thing. Still its giving same error

georged commented 5 years ago

@Andlibmehndi

I don't have enough information to advise. You need to attach a logger then and capture the details. Instructions are here

Thanks

Andlibmehndi commented 5 years ago

@georged I have prepared one small demo fo this that why I have not added any loggers but when i debugging it I have found that token is null. is this the token issue?

Thanks.

georged commented 5 years ago

That'd be authentication issue. For more details you need to look what's coming back from Azure AD. Perhaps secret is not correct but I cannot really tell.

Andlibmehndi commented 5 years ago

@georged
I have tried with C# code there it is retrieving the data but they are also using Bearer token.

Thanks

Andlibmehndi commented 5 years ago

@georged Here it's the image which I was getting a response from Azure AD temp

Thanks

georged commented 5 years ago

@Andlibmehndi could be various reasons, I can't tell without a log. For example, if a clock on your server is off, you'd get a null token. We are using bearer tokens

Andlibmehndi commented 5 years ago

@georged Thanks I will try to debug that scenario hope this will work.