Loopback: How to update multiple objects over REST? - node.js

On my current project I'm using a loopback backend as the REST API. My question is actually quite simple, but I wasn't able to figure it out on my own.
On my client I have a bulk of message objects which are updated by the user - these can add up to 50-100 messages.
Now I want to update the items using the loopback backend. There are some default endpoints which support PUT or PATCH methods. However, as soon as I pass an array I receive an error message, complaining that the item with the id already exists.
It seems wrong to me to just fire up 100 HTTP-Requests just to update a bunch of items. Any suggestions?
For completeness - here the error message.
{
"error": {
"name": "Error",
"status": 500,
"message": "Failed with multiple errors, see `details` for more information.",
"details": [
{
"code": 11000,
"index": 0,
"errmsg": "E11000 duplicate key error collection: xxx.Message index: _id_ dup key: { : ObjectId('588bc0afcf8d8c7b13ff44e2') }",
"op": {
// message object
}
}
}

I would create a custom remote method that can receive all of your messages. Then on the server loopback will offer multiple options to update/insert in batch.
Disclaimer: Remote method is a notion in Loopback 3.x. I'm not sure what the 4.x equivalent is.

Related

Whatsapp Cloud API webhook not sending back the messages object

One of my WA cloud Apps suddenly stopped working,
I went to the webhook and it is not sending the messages object back,
I am sure this happened suddenly
here is the result from webhook:
{
"object": "whatsapp_business_account",
"entry": [
{
"id": "1900820329959633",
"changes": [
{
"value": {
"messaging_product": "whatsapp",
"metadata": {
"display_phone_number": "16315551234",
"phone_number_id": "16315551234"
},
"statuses": []
},
"field": "messages"
}
]
}
]
}
Meanwhile if you go to official WA Postman collection you will find that it already includes messages object.
Edit 1:
After some investigation I found that developer.facebook health check page has the following:
But still not sure if that's related.
Is there anything I can do to fix this?
Edit 2:
I tried another developer account that has cloud API, it works and sends back the messages Object correctly.
EDIT 3:
Now they are describing the same issue occurred.
I have been able to report a bug to WA Team, and they were able to reproduce the error.

MS Bot Framework Direct Line API 3.0: Get starting message

I published a bot using the Azure bot framework to the Azure cloud servers, and made an application that uses the Direct Line API 3.0 to send user responses and receive bot messages through HTTP requests. Everything works except that I'm not sure how to get the starting message of the bot at the start of the conversation. I open the conversation with the /v3/directline/conversations endpoint, but I'm not sure how to receive the first message of the bot (that is normally sent without any user interaction). A message request after opening the conversation doesn't include any bot responses, but the next message request after sending the first user input includes the first two messages of the bot (starting message and response to the user).
EDIT: From reading this I came to the conclusion that it will be easier to just use a custom event as a trigger for the welcome message. I updated my bot as follows to reflect this within bot composer, adding a new CUSTOM event trigger with a test response message:
However, I still can't seem to trigger this event via the Direct Line API. Currently, I send a request as follows, following the event activity structure:
{
"type": "event",
"channelId": "directline",
"from": { "id": "UnityUserId", "name": "Unity User 1" },
"value": "test",
"name": "welcome"
}
I then get a response with ID, normally indicating that the request was successfull. However, upon requesting the bot response messages, I get the following:
{
"activities": [
{
"type": "event",
"id": "5FZsHpWBxm1hjhWQYY7gr-eu|0000000",
"timestamp": "2022-04-09T14:39:15.90169Z",
"serviceUrl": "https://directline.botframework.com/",
"channelId": "directline",
"from": {
"id": "UnityUserId",
"name": "Unity User 1"
},
"conversation": {
"id": "5FZsHpWBxm1hjhWQYY7gr-eu"
},
"value": "test",
"name": "welcome"
}
],
"watermark": "0"
}
Indicating that the bot has no responses, which doesn't seem quite right when looking at the bot composer screenshot above. Is there something wrong with my current method?
Regards
The onMembersAdded event usually does the trick. Sample code is in https://learn.microsoft.com/en-us/azure/bot-service/bot-builder-send-welcome-message?view=azure-bot-service-4.0&tabs=csharp
I thought I remembered seeing the bot's welcome message when using Direct Line, so I tried to quickly repro it again. I connected a simple echo bot via Direct Line. Then I created a conversation, sent a simple message, and then retrieved all activities (all via REST calls), and the bot's welcome message was indeed present in the response, as you can see in this screenshot:
Perhaps you should use these Direct Line 3.0 API reference docs as opposed to the one you linked above. I followed these steps using the basic Echo bot sample, Postman, and a bot resource in Azure for simple and easy testing, but you could use a full application if you wish.

How do you update your profile picture using Microsoft Graph API?

I'm experimenting on Microsoft Graph API to update the profile picture.
Although there is a documentation about it (See Link Here: https://learn.microsoft.com/en-us/graph/api/profilephoto-update?view=graph-rest-1.0&tabs=javascript), I can't seem to understand it.
I tried sending a random data to see if something would work, however I can only get the GET Method to work but somehow trying to make the PUT Method work returns an error.
{
"error": {
"code": "ErrorInsufficientPermissionsInAccessToken",
"message": "Exception of type 'Microsoft.Fast.Profile.Core.Exception.ProfileAccessDeniedException' was thrown.",
"innerError": {
"date": "2022-04-15T07:10:11",
"request-id": "********-****-****-****-************",
"client-request-id": "********-****-****-****-************"
}
}
}
Basically the two concerns are:
How to use the PUT Method for updating the profile picture using Microsoft Graph API
Why am I receiving the error as if I'm not allowed to update?
Is it because I'm doing the PUT Method incorrectly?
Is it because I need some sort of subscription to use the API?

expand=fields($select=***,****) on the SharePoint Graph resource doesn't work and how about filtering?

I'm playing with the microsoft graph and especially the sharepoint beta api and i am constantly running into issues. I know its beta, but still;)
I'm getting out my expanded fields but i'm not able to select other than id.
/items?expand=fields(select=id) <-- works
/items?expand=fields(select=Title) <-- fails with response being
{
"error": {
"code": "invalidRequest",
"message": "The request is malformed or incorrect.",
"innerError": {
"request-id": "f460cded-46da-468c-a027-f027707a62fc",
"date": "2017-05-10T09:00:10"
}
}
}
Further on trying to filter the request with the request /items?expand=fields&$filter=fields/id eq '421' doesn't work and after a long period just returns a response without taken the filter into account.
Can someone respond if the experience the same or if my syntax is wrong or whatever would be nice. Thanks in advance. Ole Bergtun
i changed /items?expand=fields(select=Title) to /items?expand=fields(select%3DTitle) and it works for me.

Api version change but docs not updated?

I've been trying to do various things through your Mail REST API today and not having much success... My project (using the api) has been running for at least a month now, but requests to your api are failing.
For example:
GET https://outlook.office365.com/EWS/OData/Me/messages (works)
GET https://outlook.office365.com/EWS/OData/Me/inbox (doesn't work)
Looking at the documentation, still says its available.
Trying to send an email using:
POST https://outlook.office365.com/EWS/OData/Me/Messages?MessageDisposition=SendAndSaveCopy also just returns 400 (Bad Request)
Any info about this?
Also, the http status codes returned are not useful at all; almost all errors return as 400's. In one instance, I didn't provide auth creds, and a 400 was returned instead of the appropriate 401. The accompanying status code detail could also be more helpful.
Thanks for the feedback and sorry for the inconvenience. We are currently deploying some non-backwards compatible changes described here, and this is causing your issues. The current set of changes including versioning support, and deploying non-backwards compatible changes won't cause issues for your app in the future. For the queries, that don't work, please use the following:
Accessing Inbox: https://outlook.office365.com/ews/odata/me/folders/inbox
Send email (new action called SendMail):
POST https://outlook.office365.com/ews/odata/me/sendmail
{
"Message":
{
"Subject": "Test message",
"Body":
{
"Content": "This is test message!"
},
"ToRecipients":
[
{ "EmailAddress": { "Address": "John#contoso.com", "Name": "John Doe" }},
{ "EmailAddress": { "Address": "Jane#fabrikam.com", "Name": "Jane Smith" }}
]
},
"SaveToSentItems": true
}
Hope this helps. We are updating the documentation to reflect the changes, and it should be available shortly. Thanks for the feedback on the HTTP status codes, we will review the status codes returned currently and make any fixes required.
Conversation support is in our roadmap but we don't yet have a timeline to share. Currently, you can search using https://outlook.office365.com/ews/odata/Folders/FolderId/Messages?$filter=ConversationId%20eq%20%%27ConversationID%27 but this will only return messages within the specified folder belonging to that conversation.
Let me know if you have any questions or need more info.
Thanks,
Venkat

Resources