dynamics-webapi-toolkit
dynamics-webapi-toolkit copied to clipboard
Could someone help me with a "simple" example?
Hello,
please, maybe do you have a simple example on how to connect, collect records (eg.: incidents) and list it (FetchXML)? It will be very userful to me and will save me a lot of time.
PS.: I want to try to migrate my APP from the php-crm-toolkit to the dynamics-webapi-toolkit.
I am trying to follow the Tutorial, but no luck.
Error: Fatal error: Uncaught Error: Class 'AlexaCRM\WebAPI\ClientFactory' not found in C:\Tools\xampp\htdocs\WebApi2\index2.php:5 Stack trace: #0 {main} thrown in C:\Tools\xampp\htdocs\WebApi2\index2.php on line 5
Thank you for your support. Best regards,
Dante
@dantedantas have you run composer?
$ composer require alexacrm/dynamics-webapi-toolkit:dev-master
Yes, I did. I will try again.
Em sex, 8 de abr de 2022 01:57, George Doubinski @.***> escreveu:
@dantedantas https://github.com/dantedantas have you run composer?
$ composer require alexacrm/dynamics-webapi-toolkit:dev-master
— Reply to this email directly, view it on GitHub https://github.com/AlexaCRM/dynamics-webapi-toolkit/issues/77#issuecomment-1092311339, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACS2BK4ZXNJBIOGPL5KQYLLVD5Y6BANCNFSM5SZIFOIQ . You are receiving this because you were mentioned.Message ID: @.***>
I did one time more.
And... it works... I have no idea why. I just ran one time more the compose. As you see, there was no update. But good. Now it "works" better.
I am getting the error bellow.
**Fatal error**: Uncaught AlexaCRM\WebAPI\ToolkitException:
**Metadata request returned a 403 code in** C:\Tools\xampp\htdocs\WebApi2\vendor\alexacrm\dynamics-webapi-toolkit\src\WebAPI\Client.php:351 Stack trace:
#0 C:\Tools\xampp\htdocs\WebApi2\vendor\alexacrm\dynamics-webapi-toolkit\src\WebAPI\Client.php(271): AlexaCRM\WebAPI\Client->retrieveViaFetchXML(Object(AlexaCRM\Xrm\Query\FetchExpression))
#1 C:\Tools\xampp\htdocs\WebApi2\index.php(24): AlexaCRM\WebAPI\Client->RetrieveMultiple(Object(AlexaCRM\Xrm\Query\FetchExpression))
#2 {main} thrown in C:\Tools\xampp\htdocs\WebApi2\vendor\alexacrm\dynamics-webapi-toolkit\src\WebAPI\Client.php on line 351
Please, could you help me to find out the reason of the issue? Thank you very much!
BR, Dante
That's probably insufficient permissions. If you attach a logger and set level to Debug then you'll be able to track the issue better. Check the roles assigned to the app user.
Hi @georged, thank you for your reply.
I will be very thankful with your attention and help. Please, see below the log:
[2022-04-12T12:47:12.457991+02:00] WebAPI_2.DEBUG: Initializing Dynamics Web API Toolkit {"settings":{"AlexaCRM\\WebAPI\\OData\\OnlineSettings":{"applicationID":"XXX","applicationSecret":"YYY","certificatePath":"","passphrase":null,"tenantID":null,"apiVersion":"9.0","instanceURI":"https://myorg.crm4.dynamics.com","caBundle":null,"caBundlePath":null,"tlsVerifyPeers":true,"cachePool":[],"logger":[],"callerID":null}},"authentication":"AlexaCRM\\WebAPI\\OData\\OnlineAuthMiddleware","handlers":[]} []
[2022-04-12T12:47:12.700217+02:00] WebAPI_2.DEBUG: Probed https://myorg.crm4.dynamics.com/api/data/v9.0/ for tenant ID {myorg} [] []
[2022-04-12T12:47:12.906791+02:00] WebAPI_2.DEBUG: Retrieved a new access token via https://login.microsoftonline.com/myorg/oauth2/token [] []
[2022-04-12T12:47:13.095735+02:00] WebAPI_2.ERROR: Failed to retrieve OData metadata from https://myorg.crm4.dynamics.com/api/data/v9.0/$metadata {"responseCode":403} []
About the setting of the Application. I asked the Azure Administrator to follow the link below: https://docs.microsoft.com/en-us/power-apps/developer/data-platform/walkthrough-register-app-azure-active-directory
Maybe do I missing something?
My code:
Thank you very much.
BR, Dante
@dantedantas that has nothing to do with delegated permissions.
What roles do you have assigned to the app user in Dataverse?
Where could I find this information? Please, could you share with me a screenshot where could I find this info?
@dantedantas Dataverse documentation has all you need: https://docs.microsoft.com/power-platform/admin/database-security#assign-security-roles-to-users-in-an-environment-that-has-a-dataverse-database
Hi @georged , thank you for your feedback.
I am using HTTP and not HTTPS. Could be it an issue? (Hope not)
Thank you for the link, but, maybe, do you have a list with the permissions that I would need?
We created 2 APPs with the same config. Tha App that uses C# works fine, my (with PHP), still doesnt work.
I've got user_impersonation granted, but I don't think that I need this for the incident viewer (my tools), but I don't have any read permissions granted. I'm not sure if these need to API permissions or not.
Maybe, could you help me to establish exactly what permissions I need to request?
Thank you ver much.
@dantedantas user_impersonation is API permission, this is not the place to look. You need to assign roles to the app user in Dataverse. Try something like System Administrator role just to see if it works. If it does then you can figure out reduced set of permissions. If it does not work the problem is elsewhere.
@georged Just to be sure. I am using HTTP and not HTTPS. Could be it an issue?
On your site you should be able to use http but you must use https to connect to Dataverse
Dear Georg, I am sorry for my later reply. I moved to a new flat and it was a lot of work, and I was about 1 month in Vacation. Thank you very much for your help and attention.
Back to the topic...
I am using XAMPP as an internal Web-Server.
I tried to follow up some tutorials to install the SSL but without luck so far.
https://stackoverflow.com/questions/64800565/how-to-create-valid-ssl-in-localhost-for-xampp
Maybe do you have some idea? Thank you.
Dear Georg, sorry if I bother you. Please, could you give me a little bit more help?
I have inplemented the SSL Cert by following the link (StackOverflow) above, but I am still getting the same issue.
`Fatal error: Uncaught AlexaCRM\WebAPI\ToolkitException: Metadata request returned a 403 code in C:\Tools\xampp\htdocs\WebApi2\vendor\alexacrm\dynamics-webapi-toolkit\src\WebAPI\Client.php:357 Stack trace:
#0 C:\Tools\xampp\htdocs\WebApi2\vendor\alexacrm\dynamics-webapi-toolkit\src\WebAPI\Client.php(272): AlexaCRM\WebAPI\Client->retrieveViaFetchXML(Object(AlexaCRM\Xrm\Query\FetchExpression))
#1 C:\Tools\xampp\htdocs\WebApi2\index.php(53): AlexaCRM\WebAPI\Client->RetrieveMultiple(Object(AlexaCRM\Xrm\Query\FetchExpression))
#2 {main} thrown in C:\Tools\xampp\htdocs\WebApi2\vendor\alexacrm\dynamics-webapi-toolkit\src\WebAPI\Client.php on line 357`
Do I miss something?
My code: https://github.com/AlexaCRM/dynamics-webapi-toolkit/discussions/69 #69
Thank you very much. BR, Dante
@dantedantas you're getting 403 which means you're not authenticated properly try executing something simple that does not require metadata like WhoAmI: $foo = $client->executeAction('WhoAmI');
Dear Georg. Thank you for youy feedback.
If I sent: $settings->tlsVerifyPeers = false; Then, I am getting the error:
**Fatal error:** Uncaught AlexaCRM\WebAPI\OData\ODataException:
Client error: `POST https://xxxx.crm4.dynamics.com/api/data/v9.0/WhoAmI` resulted in a `403 Forbidden` response with the following message: `The user is not a member of the organization.`
in C:\Tools\xampp\htdocs\incidentreport\vendor\alexacrm\dynamics-webapi-toolkit\src\WebAPI\OData\Client.php:245 Stack trace:
#0 C:\Tools\xampp\htdocs\incidentreport\vendor\alexacrm\dynamics-webapi-toolkit\src\WebAPI\OData\Client.php(615): AlexaCRM\WebAPI\OData\Client->doRequest('POST', 'https://xxx...', NULL)
#1 C:\Tools\xampp\htdocs\incidentreport\index.php(57): AlexaCRM\WebAPI\OData\Client->executeAction('WhoAmI')
#2 {main} thrown in C:\Tools\xampp\htdocs\incidentreport\vendor\alexacrm\dynamics-webapi-toolkit\src\WebAPI\OData\Client.php on line 245
If I set: $settings->caBundlePath = 'server.crt'; //My local certificate. Then, I am getting the error:
Fatal error: Uncaught AlexaCRM\WebAPI\OData\TransportException: cURL error 77: error setting certificate verify locations: CAfile: server.crt CApath: none (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://xxxx.crm4.dynamics.com/api/data/v9.0/ in C:\Tools\xampp\htdocs\incidentreport\vendor\alexacrm\dynamics-webapi-toolkit\src\WebAPI\OData\Client.php:220 Stack trace:
#0 C:\Tools\xampp\htdocs\incidentreport\vendor\alexacrm\dynamics-webapi-toolkit\src\WebAPI\OData\Client.php(615): AlexaCRM\WebAPI\OData\Client->doRequest('POST', 'https://xxx...', NULL)
#1 C:\Tools\xampp\htdocs\incidentreport\index.php(57): AlexaCRM\WebAPI\OData\Client->executeAction('WhoAmI')
#2 {main} thrown in C:\Tools\xampp\htdocs\incidentreport\vendor\alexacrm\dynamics-webapi-toolkit\src\WebAPI\OData\Client.php on line 220
Some idea that could help me from this blinding? :)
Thank you very much. BR, Dante
@dantedantas the part where it says "The user is not a member of the organization." is the clue. You've created an app registration in Azure AD but you didn't create an app user in Dataverse. Once you create that user, do not forget to assign security role(s) to it .