How do I encode the names of Microsoft group and teams names to include them in an API call URL? - ms-office

If I have an Office 365 Group/Microsoft Team with the ID "testteam#example.onmicrosoft.com", and I want to query it using one of the beta APIs such as this one, I need to query a URL such as https://graph.microsoft.com/beta/groups/{id}/threads. However, I am stuck on encoding the team name. https://graph.microsoft.com/beta/groups/testteam#example.onmicrosoft.com/threads, https://graph.microsoft.com/beta/groups/testteam#example%2Eonmicrosoft%2E/threads, and https://graph.microsoft.com/beta/groups/testteam#example/threads, https://graph.microsoft.com/beta/groups/"testteam#example"/threads, and https://graph.microsoft.com/beta/groups/"testteam#example.onmicrosoft.com"/threads all return the following error
"error": {
"code": "Request_BadRequest",
"message": "Invalid object identifier 'whatever_I_entered'."

As far as I understand it's just regular URL Encode. For example in JS you may use function encodeURIComponent(str). If you want to try use online URL encoder. For example encoded version of testteam#example.onmicrosoft.com will looks like testteam%40example.onmicrosoft.com and your graph request would be https://graph.microsoft.com/beta/groups/testteam%40example.onmicrosoft.com/threads
EDIT:
In the request you need to use Id of the group. For example: Get Group request may looks like ... and the group id is c28c1cc9-e1ab-4c4d-98d1-d8fdf128b60f
https://graph.microsoft.com/v1,0/groups/c28c1cc9-e1ab-4c4d-98d1-d8fdf128b60f?$select=description,allowExternalSenders

Related

Azure Face Recognition gives "Attribute 'qualityForRecognition' is only supported for recognition_03 and recognition_04." error

I'm following the official MS Azure quickstart guide (https://learn.microsoft.com/en-gb/azure/cognitive-services/face/quickstarts/client-libraries?tabs=visual-studio&pivots=programming-language-rest-api), specifically the "Get face attributes" part and when replicating provided cURL examples in Postman, I'm getting the following error:
{
"error": {
"code": "BadArgument",
"message": "Attribute 'qualityForRecognition' is only supported for recognition_03 and recognition_04."
}
}
Any ideas? It seems like they've updated their API without updating documentation, which is something I wouldn've expected from a corp like Microsoft, but it's the only thing I can think of why it wouldn't be working. For reference, here's a screenshot of my Postman request.
As per documentation:
To extract face attributes, call the Detect API again, but set detectionModel to detection_01. Add the returnFaceAttributes query parameter as well.
Detect with stream example:
POST {Endpoint}/face/v1.0/detect?overload=stream&returnFaceAttributes=age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise&recognitionModel=recognition_01&returnRecognitionModel=True&detectionModel=detection_01
Ocp-Apim-Subscription-Key: {API key}
returnFaceAttributes: Analyze and return the one or more specified face attributes in the comma-separated string like "returnFaceAttributes=age,gender".
Note: detection_01 supports age, gender, headPose, smile, facialHair, glasses, emotion, hair, makeup, occlusion, accessories, blur, exposure, noise, and qualityForRecognition While detection_02 does not support any attributes and detection_03 only supports mask and qualityForRecognition. qualityForRecognition is only supported when the 'recognitionModel' is specified as 'recognition_03' or 'recognition_04'.
As per Add QualityForRecognition in Face how-to samples, detection_01 is used with recognition_04
var faces3 = await faceClient.Face.DetectWithUrlAsync(url: imageUrl, returnFaceId: true, returnFaceAttributes: requiredFaceAttributes, detectionModel: DetectionModel.Detection01, recognitionModel: RecognitionModel.Recognition04);
You can also refer to Add qualityForRecognition attribute to Face Detection

Azure : How to write path to get a file from a time series partitioned folder using the Azure logic apps

I am trying to retrieve a csv file from the Azure blob storage using the logic apps.
I set the azure storage explorer path in the parameters and in the get blob content action I am using that parameter.
In the Parameters I have set the value as:
concat('Directory1/','Year=',string(int(substring(utcNow(),0,4))),'/Month=',string(int(substring(utcnow(),5,2))),'/Day=',string(int(substring(utcnow(),8,2))),'/myfile.csv')
So during the run time this path should form as:
Directory1/Year=2019/Month=12/Day=30/myfile.csv
but during the execution action is getting failed with the following error message
{
"status": 400,
"message": "The specifed resource name contains invalid characters.\r\nclientRequestId: 1e2791be-8efd-413d-831e-7e2cd89278ba",
"error": {
"message": "The specifed resource name contains invalid characters."
},
"source": "azureblob-we.azconn-we-01.p.azurewebsites.net"
}
So my question is: How to write path to get data from the time series partitioned path.
The response of the Joy Wang was partially correct.
The Parameters in logic apps will treat values as a String only and will not be able to identify any functions such as concat().
The correct way to use the concat function is to use the expressions.
And my solution to the problem is:
concat('container1/','Directory1/','Year=',string(int(substring(utcNow(),0,4))),'/Month=',string(int(substring(utcnow(),5,2))),'/Day=',string(int(substring(utcnow(),8,2))),'/myfile.csv')
You should not use that in the parameters, when you use this line concat('Directory1/','Year=',string(int(substring(utcNow(),0,4))),'/Month=',string(int(substring(utcnow(),5,2))),'/Day=',string(int(substring(utcnow(),8,2))),'/myfile.csv') in the parameters, its type is String, it will be recognized as String by logic app, then the function will not take effect.
And you need to include the container name in the concat(), also, no need to use string(int()), because utcNow() and substring() both return the String.
To fix the issue, use the line below directly in the Blob option, my container name is container1.
concat('container1/','Directory1/','Year=',substring(utcNow(),0,4),'/Month=',substring(utcnow(),5,2),'/Day=',substring(utcnow(),8,2),'/myfile.csv')
Update:
As mentioned in #Stark's answer, if you want to drop the leading 0 from the left.
You can convert it from string to int, then convert it back to string.
concat('container1/','Directory1/','Year=',string(int(substring(utcNow(),0,4))),'/Month=',string(int(substring(utcnow(),5,2))),'/Day=',string(int(substring(utcnow(),8,2))),'/myfile.csv')

How to pass DateTime for a SOAP request to a azure web api?

I am creating a web api on Azure (APIM). This web api access a method on from an on prem service.
The request object passed should be SOAP. This request object also contains a Date time field. I am trying from quite sometime now but my request is failing with the following error:
There was an error deserializing the object of type Core.Service.DataContracts.ExternalData. The value '' cannot be parsed as the type 'DateTime'.
I am passing the following Request Object, through Postman to test my web api:
{
"integrationpartnername" : "Hi-Marley",
"actioncategory" : "TextChat",
"actioncode" : "OpenClaim",
"actiondescription" : "Text Chat Open Claim",
"transmissionmethod" : "WebService",
"requeststatus" : "Complete",
"requestdate" : "2019-08-02T10:22:49",
"requestmessage" : "Hi Marley first third party log from apim.",
"responsedate" : "2019-08-02T10:22:49"
}
Any pointers are much appreciated.
Edit: Adding the screenshot of the Postman:
This issue may caused by the date/time string is not the expected format, you can have a try with this format: "2019-08-12T12:00:00.000Z" and change the format code in your api.
For further information, you may refer to the pages below:
http://www.mirthproject.org/community/forums/showthread.php?t=9407
http://tech.forums.softwareag.com/techjforum/posts/list/31905.page
Running the test in the portal I could see in the trace that the date was being converted from 2019-08-02T10:22:49.463Z in the JSON body to 8/12/2019 10:22:49 AM in the SOAP body. The WCF service was throwing a deserialization exception because that datetime format cannot be parsed. The solution is to format the date in the liquid syntax, like this
{{body.RequestDate | Date: "yyyy-MM-ddTHH:mm:ss"}}. The correct date format to use was not as straight forward to find since the liquid documentation says to use Ruby strftime format, but that did not work for me https://shopify.github.io/liquid/filters/date/. Apparently the APIM uses dotLiquid and not basic liquidSee https://azure.microsoft.com/en-us/blog/deep-dive-on-set-body-policy/ for reference.

Can't seem to find the issue with the requestID parameter for the request header

I am trying to pull data from a REST API that uses a "similar standard to JSON RPC". The params I am passing look right according to the documentation here and here.
The error I am receiving is ...message:"Header missing request ID".... I am unsure what I am missing that would properly declare the requestID.
I have looked at the documentation provided via the API I am trying to pull data from but it's not very helpful considering it's all in PHP and cURL. I am trying to complete this task using python-requests.
getParams = {'method': 'getCustomers', 'params':{'where':'', 'limit': 2}, 'id': 'getCustomers'}
Result:
{"result":null,"error":{"code":102,"message":"Header missing request ID","data":[]},"id":null}
The return result should contain a list of All Customers and their attributes in JSON format.
Turns out there is nothing wrong with the code I am using. There is an issue with the API I am attempting to call.
In my situation, I was getting the same error back and was required to send a X-Request-ID header. I fixed it by adding the following to my headers:
headers = {
'X-Request-ID': str(uuid.uuid1()) # generate GUID based on host & time
...
Note that (for me) the GUID needed to be of a specific format (e.g. matching the Regex ^[{]?[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}[}]?$
taken from https://www.geeksforgeeks.org/how-to-validate-guid-globally-unique-identifier-using-regular-expression/). For example, it still gave the same error if I just sent "test".

Getting image link to Sharepoint list picture using Microsoft Graph

Im trying to retrieve some information from a Sharepoint list that contains our Company news. I have looked through our columns that exists and realized that the image is located at a column named PublishingRollupImage.
My call to microsoft looks like this:
https://graph.microsoft.com/v1.0/sites/{tenant id}/lists/posts/items?$expand=fields($select=Title,body,DepartmentCompany,PublishingRollupImage)
BUT - if i make this call, the response will be:
{
"error": {
"code": "-1, Microsoft.SharePoint.Client.ClientServiceException",
"message": "Cannot serialize data for type Microsoft.SharePoint.Publishing.Fields.ImageFieldValue.",
"innerError": {
"request-id": "f885269e-da21-45a0-b3e4-e304f4e01edb",
"date": "2018-12-10T12:12:25"
}
}
}
This is of corse due to that i'm getting the whole image sent by adding this. But i read that i could use .ImageUrl to cast it to a link instead, but i'm not sure if this could be done in a call like this.
Has anyone any pointers to give?
The Object Model(CSOM/JSOM) way return object list but not JSON, so it does not need to serialize. Graph way return JSON, it need serialize operation.
No available workaround for this now, so you may not use the field by Graph now. You could submit one feature request on the UserVoice.

Resources