Error trying to update customer on Microsoft Dynamics 365 Business Central using API - dynamics-365

I'm trying to update a customer in Microsoft Dynamics 365 Business Central using the API. I'm using Postman to make the call to the API
However, when I try to do the update I get the following error: -
"error": {
"code": "BadRequest_ResourceNotFound",
"message": "Resource not found for the segment 'customer'. CorrelationId: b5593eb6-2074-41fe-9106-d7bbdba8b452."
}
It creates a customer fine. And if I create a customer using Dynamics web UI then I can update it okay via the API. The problem only occurs if I create and Customer via the API and then try to update it.
This is the json that I'm using to create the customer
{
"displayName": "Adatum Corporation",
"type": "Company",
"addressLine1": "192 Market Square",
"addressLine2": "",
"city": "Atlanta",
"state": "GA",
"country": "US",
"postalCode": "31772",
"phoneNumber": "",
"email": "robert.townes#contoso.com",
"website": "",
"taxLiable": true,
"blocked": " "
}
And this is the Json that I use to update
{
"displayName": "Some other name"
}
Looked at it for hours and I just can't figure out what I'm doing wrong. Anyone got any ideas?
This is the endpoint that i'm using:
https://api.businesscentral.dynamics.com/v2.0/{id}/Production/api/v2.0/companies({id})/customers({customerid})

You have to use customers (plural form), then it should work. Web API Create and Update documentation.
POST businesscentralPrefix/companies({id})/customers
PATCH businesscentralPrefix/companies({id})/customers({id})
Normally this Resource not found for the segment 'X' error happens when X table/entity cannot be found.

Related

Mentioning a tag when posting a channel message from a teams bot

I would very much like to mention a tag when creating a teams message. I read the tag ID from Microsoft graph (I've also tried fetching tag id from an incoming message).
I can do this as my self using Microsoft Graph api with the following payload
{
"body": {
"contentType": "html",
"content": "<div>New incident ##### assigned to <at id=\"0\">App operations</at></div>"
},
"mentions": [
{
"id": 0,
"mentionText": "Operations",
"mentioned": {
"application": null,
"device": null,
"user": null,
"conversation": null,
"tag": {
"id": "my tag Id which I got using graph lookup",
"displayName": "App operations"
}
}
}
]}
Is this at all possible using the bot framework? Can the payload be manipulated to do this?
Right now, it is not supported to mention a tag using bot. The possible workaround is to use Graph API in the bot. To do that you can refer to this sample. Follow this to Add authentication to a bot. You will need to add the required permission and call the required API in sample.

Microsoft Graph Communications - Bot joining call - Microsoft Teams

Ok. So let me try to set the stage here.
I have a Microsoft Teams Application that has a Bot (Bot Framework v4) associated with it.
I have a use case where when a specific type of compliance activity happens, I need my bot to join the scheduled meeting and participate.
I am able to send a meeting invitation to an email account associated with the bot, and the bot accepts the invite.
According to this documentation, I should be able to join the meeting in progress.
(https://learn.microsoft.com/en-us/graph/api/application-post-calls?view=graph-rest-1.0&tabs=http) - Specifically "Example 5"
According to what I am reading, once you have the required Graph Permissions on your App Id that's associated, you only need 3 pieces of information to join the call (Passed in through a communications/call/create).
Post to https://graph.microsoft.com/v1.0/communications/calls :
Body:
{
"#odata.type": "#microsoft.graph.call",
"callbackUri": "https://bot.contoso.com/callback",
"requestedModalities": [
"audio"
],
"mediaConfig": {
"#odata.type": "#microsoft.graph.serviceHostedMediaConfig",
"preFetchMedia": []
},
"chatInfo": {
"#odata.type": "#microsoft.graph.chatInfo",
"threadId": "19:meeting_XXXXXXXXXXXXXXXX#thread.v2",
"messageId": "0"
},
"meetingInfo": {
"#odata.type": "#microsoft.graph.organizerMeetingInfo",
"organizer": {
"#odata.type": "#microsoft.graph.identitySet",
"user": {
"#odata.type": "#microsoft.graph.identity",
"id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"tenantId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"displayName": "Drew Jenkel"
}
},
"tenantId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"allowConversationWithoutHost": true
}
}
Upon doing this, I'm getting a 403 / Forbidden:
{
"error": {
"code": "7505",
"message": "Request authorization tenant mismatch.",
"innerError": {
"request-id": "30739bd2-37b2-4bfc-9c52-36d72a4aa54e",
"date": "2020-06-08T16:47:36"
}
}
}
Has anyone seen anything this this?

Trustpilot invitation api weird result

Trying to create invitations using their API, I get a proper result back, however the status is "notsent". There is zero debug information to go by, so I'm wondering if anyone else has seen this and might have ideas for fixing the issue.
Here's an example of a response I got from their api:
{
"businessUnitId": "<business unit id here>",
"businessUserId": "<business user id here>",
"createdTime": "2018-10-02T09:58:35.135569Z",
"id": "<invitation id here>",
"locale": "da-DK",
"preferredSendTime": "2018-10-09T09:58:34Z",
"recipient": {
"email": "<email goes here>",
"name": "<name goes here>"
},
"redirectUri": "http://trustpilot.com",
"referenceId": "<our ref id>",
"replyTo": "trustpilot#boozt.com",
"sender": {
"email": "noreply.invitations#trustpilotmail.com",
"name": "Booztlet.com"
},
"sentTime": null,
"source": "InvitationApi",
"status": "notsent",
"tags": [],
"templateId": "57cfc1a660e1cc0620b53a38"
}
So, the NotSent status code is expected for new invitations. This is because invitations are sent asynchronously - at around the time you put in as your "preferredSendTime".
If you login to your account at https://businessapp.b2b.trustpilot.com/#/invitations/invitation-history, you should be able to see the invitation you created, and whether it was sent or not (since you specified October 9th as your preferredSendTime, the invitation will still be queued until that point)

Crm Update productsubstitutes gets 502 error within logic app

I am trying to update existing productsubstitutes entities in Dynamics CRM Online within a Logic App.
I make lookups on the products that should be linked and than use the connector to send the following data:
{
"host": {
"connection": {
"name": "/subscriptions/XXXX/resourceGroups/XXX/providers/Microsoft.Web/connections/dynamics_crm_dev"
}
},
"method": "patch",
"path": "/datasets/XXX.crm4/tables/productsubstitutes/items/ITEMID",
"retryPolicy": {
"type": "None"
},
"body": {
"ItemInternalId": "ITEMID",
"_productid_value": "1f2017c1-b9e8-40db-9e15-c890b127e7b2",
"_salesrelationshiptype_label": "Interchangeable",
"_substitutedproductid_value": "4e1d1dd7-b9e8-40db-9e15-c890b127e7b2",
"direction": 0,
"productsubstituteid": "839229d1-b9e8-40db-9e15-c890b127e7b2",
"interchangability": 928350000,
"type": 928350000
}
This results in the strange error message:
"statusCode": 502,
"headers": {
XXX
},
"body": {
"error": {
"code": 502,
"source": "logic-apis-westeurope.azure-apim.net",
"clientRequestId": "XXXX-XXX-4b5c-a4d5-XXXX",
"message": "BadGateway",
"innerError": {
"status": 502,
"message": "The other row for the product relationship is not available.",
"source": "XXXX.crm4.dynamics.com",
"errors": [],
"debugInfo": "XXXX-XXX-4b5c-a4d5-XXXX"
}
}
}
Both product IDs: 4e1d1dd7-b9e8-40db-9e15-c890b127e7b2 and 1f2017c1-b9e8-40db-9e15-c890b127e7b2 are correct and where obtained via lookups before the update requests.
This problem is reproducible, and as it looks its only happening on particular products.
Edit:
I rebuilt the update within a small C# component with the XRM SDK and I am getting the same error.
So its definitely crm related.
Edit2:
I have a MS ticket open they are aware of the issue.. and will come back on it on the 23.08 days.

Sprind data jpa - How to handle selective fields posted by client to rest web service

I am handling request through Spring data rest using jpa. I have a domain class say user, in this domain class there is lots of fields and mappings. When client want to update user data, they have to submit whole json body as per domain class. In want to handle it so that client can update user information by sending selective fields only. What is the best approach for doing this please suggest.
Sample JSON OBJECT mapped to User domain class:
{
"id": 1,
"oauthClientDetails": {
"clientId": "8909241111",
"resourceIds": null,
"clientSecret": "secret",
"scope": "read",
"authorizedGrantTypes": "client_credentials",
"webServerRedirectUri": null,
"authorities": null,
"accessTokenValidity": 18000,
"refreshTokenValidity": null,
"additionalInformation": "{}",
"autoApprove": null
},
"deviceNo": "SMR01-4417-0002",
"deviceMasterType": {
"id": 1,
"name": "Single Phase",
"description": "Single phase meter",
"createdDate": "21-02-2018 10:11:03",
"updatedDate": "24-02-2018 10:11:03",
"statusMaster": {
"id": 2,
"name": "Active",
"createdDate": "21-02-2018 10:11:03",
"updatedDate": "21-02-2018 10:11:05",
"status": "1"
}
},
"societyName": "M G ROad",
"flatNo": "51",
"firstName": "rohit",
"lastName": "yadav",
"roleMaster": {
"id": 1,
"name": "Super user",
"description": "This role provides all application permissions.",
"createdDate": "23-02-2018 10:15:05",
"updatedDate": "23-02-2018 10:15:05",
"statusMaster": {
"id": 1,
"name": "De-Active",
"createdDate": "21-02-2018 10:11:03",
"updatedDate": "21-02-2018 10:11:05",
"status": "1"
}
},
"statusMaster": {
"id": 2,
"name": "Active",
"createdDate": "21-02-2018 10:11:03",
"updatedDate": "21-02-2018 10:11:05",
"status": "1"
},
"email": null,
"countryMaster": {
"id": 1,
"countryCode": "BOL",
"countryName": "Bolivia, Plurinational State of",
"callingCode": "591",
"createdDate": "21-02-2018 10:11:05",
"updatedDate": "21-02-2018 10:11:05"
},
"otp": "1234",
"otpVerification": null,
"alternateMobile": "8800488281",
"createdDate": "28-02-2018 11:15:05",
"updatedDate": "02-03-2018 10:15:05",
"clientID": null
}
You could partition your domain into sub domains, e.g.
Device contains (deviceNo) and DeviceMaster (deviceMasterType)
Role, Status, Country for roleMaster, statusMaster, countryMaster
with the root level elements such as email, updatedDate etc part of a base domain object such as Client.
your REST endpoints could then expose this domain structure to allow updating of partial information:
https://api.com/device
https://api.com/deviceMaster
https://api.com/role
https://api.com/status
https://api.com/country
https://api.com/client
and update the domain in parts. If a subdomain such as /device only needs the deviceNo updated, ignore the missing JSON fields when creating a domain object.
While it's good idea to break into sub-domain classes as suggested by #codebrane.
But even your sub-domain classes can have selective fields.
So you should first define which are optional and mandatory fields.
This first check should tell your clients what are the mandatory items they should send.
You should use Bean validations to achieve this as supported by whichever vendor database you are using.
And, it is unlikely that all items in your JSON are dependent, for example, a user's address or device information cannot be created without first saving the user.
If you put all of them in a single API then it will be hard for you to implement Single responsibility principle, rather not good as well.
In this scenario, you would correctly first save the user and then address, etc in a different API call.
Separate your dependent entities as separate domain objects which will help you in designing your REST APIs accordingly.
If you follow this approach then it helps you in giving the right responses to your clients as well. For e.g., an API which only takes address and fails for whatever reason will inform client that a single entity failed. If you had used Address, Contact, Device, etc all in one API then at server they can fail or pass independently and your API response will not be informative to the client.

Resources