Sending Messages through Microsoft Graph API with SchemaExtension Data - c#

I'm looking for some help formatting schema extension data in Microsoft's Graph API. I've been able to successfully send Office 365 messages in code and through the Graph Explorer using this body:
{
"message": {
"subject": "Test Subject",
"body": {
"contentType": "Text",
"content": "Test Body "
},
"toRecipients": [
{
"emailAddress": {
"address": "foo#email.com"
}
}
]
}
}
I created a schema extension and promoted it to "Available" status. I can query the extension to verify it's available and get this response body:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#schemaExtensions",
"value": [
{
"id": "extc5bnq6uk_TestExtension",
"description": "Test Extension",
"targetTypes": [
"Message"
],
"status": "Available",
"owner": "mysecretclienttenantgoeshere",
"properties": [
{
"name": "ValueOne",
"type": "String"
},
{
"name": "ValueTwo",
"type": "String"
}
]
}
]
}
So far I haven't been able to append extension data to a new message. I've tried formatting my request body like this:
{
"message": {
"subject": "Test Subject",
"body": {
"contentType": "Text",
"content": "Test Body "
},
"toRecipients": [
{
"emailAddress": {
"address": "foo#email.com"
}
}
],
"extc5bnq6uk_TestExtension": {
"ValueOne": "TestValue",
"ValueTwo": "TestValue"
}
}
}
and like this:
{
"message": {
"subject": "Test Subject",
"body": {
"contentType": "Text",
"content": "Test Body "
},
"toRecipients": [
{
"emailAddress": {
"address": "foo#email.com"
}
}
],
"extensions":[
{
"extc5bnq6uk_TestExtension" : {
"ValueOne" : "TestValue"
"ValueTwo" : "TestValue"
}
}
]
}
}
Both formats return a 400 code with response body:
{
"error": {
"code": "RequestBodyRead",
"message": "The property 'extc5bnq6uk_TestExtension' does not exist on type 'Microsoft.OutlookServices.Message'. Make sure to only use property names that are defined by the type or mark the type as open type.",
"innerError": {
"request-id": "21792fd0-44d1-42aa-8d51-f8abc92cbd04",
"date": "2018-08-14T16:39:31"
}
}
}
I'm posting to this URL in the graph explorer:
https://graph.microsoft.com/v1.0/me/sendMail
and to the "messages" and "sendMail" endpoints in code.

I found the answer in the Known Limitations of the documentation. Certain resource types, including messages, have to be done in two stages, an initial post and then a follow up patch.
Creating the message and then patching with this JSON returned a valid response.
{
"extc5bnq6uk_TestExtension": {
"ValueOne": "Test Value One",
"ValueTwo": "Test Value Two"
}
}
Unfortunately, another limitation for schema extensions on messages is that they can't be used to filter messages, which is what I was ultimately after.
Filtering on schema extension properties (using the $filter
expresssion) is not supported for Outlook entity types - contact,
event, message, or post.

Jeff
Based on your question you posted, you have created a schemaExtension successfully. I think you want to send an email with this schemaExtension, but when you send an email with this schemaExtension, we get the 400 code in the response.
Based on my test, I think we can use the request body as blow.
1.Create a schemaExtension like this:
{
"#odata.context":"https://graph.microsoft.com/v1.0/$metadata#schemaExtensions/$entity",
"id":"{extensionId}",
"description":"sample description",
"targetTypes":[
"Message"
],
"status":"Available",
"owner":"{owner id}",
"properties":[
{
"name":"p1",
"type":"String"
},
{
"name":"p2",
"type":"String"
}
]
}
Create a message
POST https://graph.microsoft.com/v1.0/me/messages
{
"message":{
"subject":"Meet for lunch?",
"body":{
"contentType":"Text",
"content":"The new cafeteria is open."
},
"toRecipients":[
{
"emailAddress":{
"address":"{toRecipients email address}"
}
}
],
"extensions":[
{
"#odata.type":"Microsoft.Graph.OpenTypeExtension",
"extensionName":"{extensionName}",
"p1":"Wingtip Toys",
"p2":"10000"
}
]
},
"saveToSentItems":"false"
}
when we send this message with the request, we will get the 202 code. The {toRecipients email address} will receive the email.

Related

C# How to get exact error message from Logic App triggered by HttpRequest instead of default error message?

I have a simple console application and it calls a Logic App by HttpRequest.
When the Logic App fails at any step I want to get exact the error message saying why it fails.
In the Logic App I can see the error.
Example: in the image, it fails at step 2 which it can't convert a string into an int. It's saying:
InvalidTemplate. Unable to process template language expressions in action 'Parse_JSON' inputs at line '0' and column '0': 'Required property 'content' expects a value but got null. Path ''.'.
which is what's I expect.
Here is my Logic App design:
But when I debug in a console application, it gives me a message "The server did not receive a response from an upstream server. Request tracking id 'some random Ids'." which is not very useful.
Here is my console application:
var obj = new
{
Age = "Twenty",
Name = "James"
};
using (var client = new HttpClient())
{
var content = new StringContent(JsonConvert.SerializeObject(obj));
content.Headers.ContentType.MediaType = "application/json";
var response = await client.PostAsync(url, content);
var errorMessage = await response.Content.ReadAsStringAsync();
//errorMessage: {"error":{"code":"NoResponse","message":"The server did not receive a response from an upstream server. Request tracking id 'some random Ids'."}}
}
So is there anyway to make the C# response return the error message in the step 2 of the Logic App?
What I expect is:
InvalidTemplate. Unable to process template language expressions in action 'Parse_JSON' inputs at line '0' and column '0': 'Required property 'content' expects a value but got null. Path ''.'.
Not:
{"error":{"code":"NoResponse","message":"The server did not receive a response from an upstream server. Request tracking id 'some random Ids'."}}
Thank you in advanced.
You can use actions('<Your_Previous_Step>')['error'] in your case actions('Parse_JSON')['error'] doing so you can able to retrieve the error message of that particular action.
Here is my logic app
I'm testing this through postman. Below is the response I received in postman.
Make sure you set Configure run after options to make the flow work even after it gets failed.
Updated Answer (General Solution)
In this case you can initialise a string variable and then add Append to string variable for each step so that it can catch the previous steps error. Below is the screenshot of my logic app.
Response in my postman
NOTE: Make sure you set Configure run after property for each action.
You can use the Scope action to encase the vast majority of other actions and then if something fails, you can catch the step for which it fails at.
You can load this JSON definition into your own tenant and see a working version.
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Filter_array": {
"inputs": {
"from": "#variables('Result')",
"where": "#equals(item()['status'], 'Failed')"
},
"runAfter": {
"Initialize_Result": [
"Succeeded"
]
},
"type": "Query"
},
"Initialize_Error_Message": {
"inputs": {
"variables": [
{
"name": "Error Message",
"type": "string",
"value": "#{body('Filter_array')[0]['error']['message']}"
}
]
},
"runAfter": {
"Filter_array": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Initialize_Integer_Variable": {
"inputs": {
"variables": [
{
"name": "Integer Variable",
"type": "integer",
"value": 1
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Initialize_Result": {
"inputs": {
"variables": [
{
"name": "Result",
"type": "array",
"value": "#result('Scope')"
}
]
},
"runAfter": {
"Scope": [
"Succeeded",
"FAILED"
]
},
"type": "InitializeVariable"
},
"Scope": {
"actions": {
"Set_Integer_Variable_(Step_1)": {
"inputs": {
"name": "Integer Variable",
"value": 2
},
"runAfter": {},
"type": "SetVariable"
},
"Set_Integer_Variable_(Step_2)": {
"inputs": {
"name": "Integer Variable",
"value": "#string('Test')"
},
"runAfter": {
"Set_Integer_Variable_(Step_1)": [
"Succeeded"
]
},
"type": "SetVariable"
},
"Set_Integer_Variable_(Step_3)": {
"inputs": {
"name": "Integer Variable",
"value": 3
},
"runAfter": {
"Set_Integer_Variable_(Step_2)": [
"Succeeded"
]
},
"type": "SetVariable"
}
},
"runAfter": {
"Initialize_Integer_Variable": [
"Succeeded"
]
},
"type": "Scope"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"Recurrence": {
"evaluatedRecurrence": {
"frequency": "Month",
"interval": 12
},
"recurrence": {
"frequency": "Month",
"interval": 12
},
"type": "Recurrence"
}
}
},
"parameters": {}
}
Naturally, it's a little more intensive and follows the same principals as a normal flow for continuing to the next step after a failure but this will help you with larger flows.
This is what the test flow looks like ...
To explain it quickly, the middle steps are simple Set Variable actions that can be changed to cause the failure.
In the definition I've given you, step 2 will fail but you can change it to step 1 or 3 and you should still see the error come out at the end regardless of the step in the scope action that fails.
I suggest playing with it and looking at the output to the scope action, which is written to variable Result in the Initialize Result step.
For reference, this is the sort of information that comes out of the Scope action that you can use to determine what has failed.
{
"variables": [
{
"name": "Result",
"type": "Array",
"value": [
{
"name": "Set_Integer_Variable_(Step_1)",
"inputs": {
"name": "Integer Variable",
"value": 2
},
"outputs": {
"body": {
"name": "Integer Variable",
"value": 2
}
},
"startTime": "2022-04-22T06:55:57.8965917Z",
"endTime": "2022-04-22T06:55:57.9281959Z",
"trackingId": "0c93fa70-a552-4776-bce1-8ac889933de9",
"clientTrackingId": "08585509963278112157168286283CU11",
"status": "Succeeded"
},
{
"name": "Set_Integer_Variable_(Step_2)",
"startTime": "2022-04-22T06:55:57.9434709Z",
"endTime": "2022-04-22T06:55:57.9434709Z",
"trackingId": "f82b494b-0ecd-412b-887a-d4b08f4a5751",
"clientTrackingId": "08585509963278112157168286283CU11",
"code": "BadRequest",
"status": "Failed",
"error": {
"code": "BadRequest",
"message": "The variable 'Integer Variable' of type 'Integer' cannot be initialized or updated with value of type 'String'. The variable 'Integer Variable' only supports values of types 'Integer'."
}
},
{
"name": "Set_Integer_Variable_(Step_3)",
"startTime": "2022-04-22T06:55:57.9590957Z",
"endTime": "2022-04-22T06:55:57.9590957Z",
"trackingId": "f761d71f-8ec0-4a29-9a8a-a39a81faf660",
"clientTrackingId": "08585509963278112157168286283CU11",
"code": "ActionSkipped",
"status": "Skipped",
"error": {
"code": "ActionConditionFailed",
"message": "The execution of template action 'Set_Integer_Variable_(Step_3)' is skipped: the 'runAfter' condition for action 'Set_Integer_Variable_(Step_2)' is not satisfied. Expected status values 'Succeeded' and actual value 'Failed'."
}
}
]
}
]
}
Take note, you still need to apply the Configure run after properties to ensure it continues on after the Scope action finishes ...
You'd need to put some more error checking in but my suggestion would be to wrap all of that functionality into another LogicApp that you can reuse across your tenant. That's the thinking anyway.

Error using Google wallet in Xamarin Android

I'm trying to use Google Pay in my Xamarin app. First I added the GooglePlayServices package from nuget
then I followed the documentation from here
here is my JSON
{
"apiVersion": 2,
"apiVersionMinor": 0,
"merchantInfo": { "merchantName": "testName" },
"allowedPaymentMethods": [
{
"type": "CARD",
"parameters": {
"allowedAuthMethods": ["PAN_ONLY", "CRYPTOGRAM_3DS"],
"allowedCardNetworks": ["AMEX", "DISCOVER", "MASTERCARD", "VISA"]
}
},
{
"type": "PAYMENT_GATEWAY",
"parameters": { "gateway": "firstdata", "gatewayMerchantId": "12365" }
}
],
"transactionInfo": {
"totalPriceStatus": "FINAL",
"totalPrice": "4.10",
"currencyCode": "USD",
"checkoutOption": "COMPLETE_IMMEDIATE_PURCHASE"
}
}
code:
paymentsClient = WalletClass.GetPaymentsClient(
Xamarin.Essentials.Platform.CurrentActivity,
new WalletClass.WalletOptions.Builder()
.SetEnvironment(WalletConstants.EnvironmentTest)
.Build());
var request = PaymentDataRequest.FromJson(json);
AutoResolveHelper.ResolveTask(paymentsClient.LoadPaymentData(request),
Xamarin.Essentials.Platform.CurrentActivity, 999);
but I get an error Code 10: Developer Error
and if I do it like this
var result = await paymentsClient.LoadPaymentDataAsync(request);
I get the following error 6: BuyFlow UI needs to be shown.
after rereviewing the documentation I realized that my json object was wrong instead of
{
"type": "CARD",
"parameters": {
"allowedAuthMethods": ["PAN_ONLY", "CRYPTOGRAM_3DS"],
"allowedCardNetworks": ["AMEX", "DISCOVER", "MASTERCARD", "VISA"]
}
},
{
"type": "PAYMENT_GATEWAY",
"parameters": { "gateway": "firstdata", "gatewayMerchantId": "12365" }
}
it needs to look like this: as tokenizationSpecification part of the payment method object
{
"type": "CARD",
"parameters": {
"allowedAuthMethods": ["PAN_ONLY", "CRYPTOGRAM_3DS"],
"allowedCardNetworks": ["AMEX", "DISCOVER", "MASTERCARD", "VISA"]
},
"tokenizationSpecification": {
"type": "PAYMENT_GATEWAY",
"parameters": { "gateway": "firstdata", "gatewayMerchantId": "12365" }
}
what I'm wondering is why didnt it throw an error when I called PaymentDataRequest.FromJson(json)

Microsoft Graph API - Approve Moderation Request

I want to be able approve a moderation request through Graph API. I have referred to Approve Moderation Request. I was not able to get it to work. Although, there is a PowerShell script available at EWS Managed API and Powershell How-To Series Part 11 Moderation that I managed to get working.
This is not a supported feature in Graph API and therefore requires some tinkering. I would like some guidance on how to do this.
This is the JSON I am sending to the end point https://graph.microsoft.com/v1.0/me/sendMail
{
"message": {
"subject": "Approve:MessageName"
},
"toRecipients": [
{
"emailAddress": {
"name": "Microsoft Exchange",
"address": "systemmailbox#domain.com"
}
}
],
"singleValueExtendedProperties": [
{
"id": "Binary 0x31",
"value": "7gd324tgcxJJNkEuxk2DP2Xk+M/fxw=="
},
{
"id": "String 0x001A",
"value": "IPM.Note.Microsoft.Approval.Reply.Approve"
}
]
}
This is the response I receive
{
"error": {
"code": "ErrorInvalidRecipients",
"message": "At least one recipient isn't valid., A message can't be sent because it contains no recipients.",
"innerError": {
"date": "2020-08-19T23:40:07",
"request-id": "7g5h732v-6uhb-3212-b6f1-43f6eeb139wq"
}
}
}
Any help would be appreciated.
You have a syntax issue in your Json request eg look closely at the Message after subject you have a closing } which means the only thing your posting is the subject of the message it should be
{
"message": {
"subject": "Approve:MessageName",
"toRecipients": [
{
"emailAddress": {
"name": "Microsoft Exchange",
"address": "address.com"
}
}
],
"singleValueExtendedProperties": [
{
"id": "Binary 0x31",
"value": "7gd324tgcxJJNkEuxk2DP2Xk+M/fxw=="
},
{
"id": "String 0x001A",
"value": "IPM.Note.Microsoft.Approval.Reply.Approve"
}
]
}
}
Additional
To make this work correctly you need to get the Approval Request from an app rovers mailbox for the Graph a query like this
https://graph.microsoft.com/v1.0/me/mailFolders('Inbox')/messages?$filter=singleValueExtendedProperties/any(ep:ep/id eq 'String 0x001a' and ep/value eq 'IPM.Note.Microsoft.Approval.Request')&$expand=singleValueExtendedProperties($filter%3D(Id eq 'Binary 0x0031') or (Id eq 'String 0x0E1D'))
This will give you the report tag 0x0031 value that you need to use in your Send and you also need to include the Approve Verb Extended property
{
id = "String {00062008-0000-0000-C000-000000000046} Id 0x8524"
value = "Approve"
}
I converted the script from my blog which I'll get around to posting this week that just approves the last email in a Mailbox you can look at it https://github.com/gscales/Powershell-Scripts/blob/master/Graph101/Moderation.ps1 (look at Invoke-ApproveModerationRequest)

How to know the interactions happened with the feed in stream?

My query goes like this: If I have a feedItem (an image posted on facebook), how can I verify that I have liked it or not? Can I verify all the interactions which I have done to the feedItem or the interactions other people have done to it (like, dislike, pin, share)? Is there any way in getstream.io to retrieve these interactions?
Thanks in advance...
Graph API provides all functions you need. Here are some examples:
Read shares[it's a field of an object]: https://developers.facebook.com/docs/graph-api/reference/v3.1/post#read
Read Shared posts: https://developers.facebook.com/docs/graph-api/reference/v3.1/object/sharedposts
read likes:
https://developers.facebook.com/docs/graph-api/reference/v3.1/object/likes#read
/likes returns only the profile for the current user if read with a
user access token:
Album, Photo, Post, Video
all returns are JSON, which you can directly Deserialize Anonymous Type without using stream, for example, likes:
{
"likes": {
"data": [
{
"name": "Bill the Cat",
"id": "155111347875779",
"created_time": "2017-06-18T18:21:04+0000"
},
{
"name": "Calvin and Hobbes",
"id": "257573197608192",
"created_time": "2017-06-18T18:21:02+0000"
},
{
"name": "Berkeley Breathed's Bloom County",
"id": "108793262484769",
"created_time": "2017-06-18T18:20:58+0000"
}
],
"paging": {
"cursors": {
"before": "Nzc0Njg0MTQ3OAZDZD",
"after": "NTcxODc1ODk2NgZDZD"
},
"next": "https://graph.facebook.com/vX.X/me/likes?access_token=user-access-token&pretty=0&summary=true&limit=25&after=NTcxODc1ODk2NgZDZD"
},
"summary": {
"total_count": 136
}
},
"id": "user-id"
}

ArcGIS Rest API in C#. submitting the job to ConnectOriginsToDestinations service

I'm getting started with the online ArcGIS analysis services API. I've hit a dead-end with the connectOriginsToDestinations analysis task; even with a minimal request, I get a job failure with the response "Operation failed. Invalid URL (code = 400)".
Unfortunately, that's not much to go on, as I can't figure out from the error exactly which field in the job request the api is complaining about. The response from the job submission is "esriJobSubmitted", with a jobId to lookup, but when polling for job status, the first poll always gives me the failure message.
{
"type": "esriJobMessageTypeError",
"description": "Operation failed. Invalid URL (code = 400)."
}
Request parameters:
Job submission URL: >>https://analysis2.arcgis.com/arcgis/rest/services/tasks/GPServer/connectOriginsToDestinations/submitJob?
Job status poll URL : >>https://analysis2.arcgis.com/arcgis/rest/services/tasks/GPServer/connectOriginsToDestinations/jobs/jc004ad8813c14d75b4bf157c43b2149d?f=json&token=MYTOKEN
Submitted Task contents (a form-encoded POST body with the following fields):
f: json
token: <my token>
originsLayer: <json blob below>
destinationsLayer: <json blob below>
measurementType: "StraightLine"
Detail: originsLayer:
{
"layerDefinition": {
"geometryType": "esriGeometryPoint",
"fields": [
{
"name": "Id",
"type": "esriFieldTypeString",
"alias": "Id"
}
]
},
"featureSet": {
"geometryType": "esriGeometryPoint",
"spatialReference": {
"wkid": 4326
},
"features": [
{
"geometry": {
"x": -77.694145,
"y": 45.478969
},
"attributes": {
"Id": "id1"
}
}
]
}
}
Detail: destinationsLayer:
{
"layerDefinition": {
"geometryType": "esriGeometryPoint",
"fields": [
{
"name": "Id",
"type": "esriFieldTypeString",
"alias": "Id"
}
]
},
"featureSet": {
"geometryType": "esriGeometryPoint",
"spatialReference": {
"wkid": 4326
},
"features": [
{
"geometry": {
"x": -77.694145,
"y": 45.478969
},
"attributes": {
"Id": "id1"
}
},
{
"geometry": {
"x": -77.476424,
"y": 46.090899
},
"attributes": {
"Id": "id2"
}
}
]
}
}

Categories