Asana user photo API request misses photo field in json response - asana

We make requests to the Asana API for user photo opt_field. We constructed the asana users query like this:
https://app.asana.com/api/1.0/users\?opt_fields\=name,email,photo,workspaces
The reponse returned is
data = (
{
email = "user2#gmail.com";
id = xxooiio1664;
name = "User 2";
workspaces = (
{
id = 104764788xxxyyy;
},
{
id = 4983461zzzjjjj;
}
);
},
But the photo field has been missing. Did we miss anything in the request?

When you use opt_fields, it only returns fields you explicitly request, and each of the images is considered its own field for this purpose. So you would need to specify e.g. opt_fields=photo.image_60x60.

Related

How to do a POST batch request in Miscrosoft Graph .NET SDK

I'm trying to do a batch request using MS Graph .NET SDK as shown here: https://learn.microsoft.com/en-us/graph/sdks/batch-requests?tabs=csharp
The only problem is that when I run the code, nothing happens.
I'm trying to move a set of emails (stored in a list) to another mail folder.
Am I missing anything?
The move request is here https://learn.microsoft.com/en-us/graph/api/message-move?view=graph-rest-1.0&tabs=http
When used in a single query it works, but not when batching.
Below you will find the code, in this case I'm looping to 20 just to test as 20 is the maximum queries per batch.
Thanks in advance.
for (int i = 0; i < 20; i++)
{
var mail = invalidMessages[i];
var userRequest = client.Me.Messages[mail.Id]
.Move(failureFolderID)
.Request();
requestID = batchRequestContent.AddBatchRequestStep(userRequest);
}
var returnedResponse = await client.Batch.Request().PostAsync(batchRequestContent);
EDIT: I tried to change the method to POST
userRequest.Method = System.Net.Http.HttpMethod.Post;
but I get a ServiceException: 'Code: BadRequest
Message: Write request id : fe23b1c1-663d-4499-829a-291d04a12b48 does not contain Content-Type header or body.'
The Microsoft Graph message-move API call you are attempting to use is a POST request
The Microsoft Batch API handles POST requests differently than the other API methods.
As per https://learn.microsoft.com/en-us/graph/sdks/batch-requests?tabs=csharp
POST requests are handled a bit differently.
The SDK request builders generate GET requests, so
you must get the HttpRequestMessage and convert to a POST
To have a successful post with the batch API you need to
Create an HttpRequestMessage
provide a value for the HttpRequestMessage's Content property which houses the POST requests payload
So if I applied this to your code I would first create a class to represent the POST payload for the message-move API. As per https://learn.microsoft.com/en-us/graph/api/message-move?view=graph-rest-1.0&tabs=http
the POST API has one property called destinationId
destinationId - The destination folder ID, or a well-known folder name. For a list of supported well-known folder names, see mailFolder resource type.
public class MailMovePayload
{
public string destinationId { get; set; }
}
then I would use an instance of this class in this modified version of you code
string str = events.Content.ReadAsStringAsync().Result;
events.Method = HttpMethod.Post;
for (int i = 0; i < 20; i++)
{
var mail = invalidMessages[i];
//get the request message object from your request
var userRequestMessage = client.Me.Messages[mail.Id]
.Move(failureFolderID)
.GetHttpRequestMessage();
//set the message API method
userRequestMessage.Method = HttpMethod.Post;
//create the payload, I am assuming failureFolderID is
//the name of the folder where the mail will be moved to
var payloadData = new MailMovePayload { destinationId = failureFolderID };
//make the JSON payload for the request message
userRequestMessage.Content = new StringContent(JsonConvert.SerializeObject(payloadData), Encoding.UTF8, "application/json")
requestID = batchRequestContent.AddBatchRequestStep(userRequestMessage);
}
var returnedResponse = await client.Batch.Request().PostAsync(batchRequestContent);
return httpRequestMessage;
}

Render Embedded Image in Email Body using Microsoft Graph or Outlook REST API

When we get email using Microsoft Graph/Outlook REST API it's body contains the references for embedded images like below.
<img src="cid:image001.jpg#1D3E60C.5A00BC30">
I am looking to find out a way so i can display the embedded images properly as the above image tag does not display any image. I have done some search but did not found any help on that.
Below is sample code for getting an email by id using Microsoft Graph API.
// Get the message.
Message message = await graphClient.Me.Messages[id].Request(requestOptions).WithUserAccount(ClaimsPrincipal.Current.ToGraphUserAccount()).GetAsync();
For getting attached resources with email using Microsoft Graph API you need to get email like below.
// Get the message with all attachments(Embedded or separately attached).
Message message = await graphClient.Me.Messages[id].Request(requestOptions).WithUserAccount(ClaimsPrincipal.Current.ToGraphUserAccount()).Expand("attachments").GetAsync();
Once you have all attachments with email detail you need to iterate through attachments list and check if attachment IsInline property is set as true then simply replace the
cid:image001.jpg#1D3E60C.5A00BC30
with Base64String created from bytes array of attachment.
string emailBody = message.Body.Content;
foreach (var attachment in message.Attachments)
{
if (attachment.IsInline.HasValue && attachment.IsInline.Value)
{
if ((attachment is FileAttachment) &&(attachment.ContentType.Contains("image")))
{
FileAttachment fileAttachment = attachment as FileAttachment;
byte[] contentBytes = fileAttachment.ContentBytes;
string imageContentIDToReplace = "cid:" + fileAttachment.ContentId;
emailBody = emailBody.Replace(imageContentIDToReplace,
String.Format("data:image;base64,{0}", Convert.ToBase64String(contentBytes as
byte[])));
}
}
}
Now render the email body using emailBody variable it will display all embedded images.
Use below code to display logo image on image tag using graph Api in C#.
var fileAttachment = new FileAttachment
{
ODataType = "#microsoft.graph.fileAttachment",
Name = Path.GetFileName(attachment),
ContentLocation = attachment,
ContentBytes = contentBytes,
ContentType = contentType,
ContentId= contentId,
IsInline = true
};
Note : Here IsInline = true must need to be added if you want to display image on image tag only not as attachment.

Creating multiple entities in single request in Microsoft Dynamics CRM (OData)

I know how to create a single entity in single request. However, one requirement wants me to create multiple entities (in my case it's multiple entries in ContactSet). I tried putting array to
POST /XRMServices/2011/OrganizationData.svc/ContactSet
[{
"MobilePhone": "+0012 555 555 555",
"YomiFullName" : "Demo User 1",
"GenderCode" : {
"Value" : 1
}
.....
<data removed for sanity>
.....
},
{
"MobilePhone": "+0012 555 555 111",
"YomiFullName" : "Demo User 2",
"GenderCode" : {
"Value" : 1
}
.....
<data removed for sanity>
.....
}]
However this does not work and I could not find any documentation explaining me ways to achieve this. Any help would be greatly appreciated.
You need to use an ExecuteMultipleRequest, I don't believe this is available in Rest service however, but is available in the SOAP service.
// Get a reference to the organization service.
using (_serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri, serverConfig.HomeRealmUri,serverConfig.Credentials, serverConfig.DeviceCredentials))
{
// Enable early-bound type support to add/update entity records required for this sample.
_serviceProxy.EnableProxyTypes();
#region Execute Multiple with Results
// Create an ExecuteMultipleRequest object.
requestWithResults = new ExecuteMultipleRequest()
{
// Assign settings that define execution behavior: continue on error, return responses.
Settings = new ExecuteMultipleSettings()
{
ContinueOnError = false,
ReturnResponses = true
},
// Create an empty organization request collection.
Requests = new OrganizationRequestCollection()
};
// Create several (local, in memory) entities in a collection.
EntityCollection input = GetCollectionOfEntitiesToCreate();
// Add a CreateRequest for each entity to the request collection.
foreach (var entity in input.Entities)
{
CreateRequest createRequest = new CreateRequest { Target = entity };
requestWithResults.Requests.Add(createRequest);
}
// Execute all the requests in the request collection using a single web method call.
ExecuteMultipleResponse responseWithResults =
(ExecuteMultipleResponse)_serviceProxy.Execute(requestWithResults);
// Display the results returned in the responses.
foreach (var responseItem in responseWithResults.Responses)
{
// A valid response.
if (responseItem.Response != null)
DisplayResponse(requestWithResults.Requests[responseItem.RequestIndex], responseItem.Response);
// An error has occurred.
else if (responseItem.Fault != null)
DisplayFault(requestWithResults.Requests[responseItem.RequestIndex],
responseItem.RequestIndex, responseItem.Fault);
}
}
ExecuteMultipleRequest is a good but not the only way. If you use CRM 2016 you can use Batch operations that is available in new WebApi. Check article that describes it - https://msdn.microsoft.com/en-us/library/mt607719.aspx
You can use a Web API action (see MSDN) to execute an ExecuteTransactionRequest, as described here. Subject of the example on MSDN is the WinOpportunityRequest, but it should work with any supported request, including custom actions.

Mendeley Implicit auth type not returning full data

This question relates to the Mendeley API.
http://dev.mendeley.com/
When using the implicit auth type: http://dev.mendeley.com/reference/topics/authorization_overview.html
I seem to only receive a subset of data for a given document. For example, the 'websites' field seems to not come through even when it is populated.
I am only experiencing this issue using the implicit auth type and not other auth types.
Are any other Mendeley API users experiencing this? It seems like a bug.
Certain fields get returned depending on the document view that you specify. This was implemented to be able to support the needs of multiple clients e.g. mobile clients require smaller datasets than larger web clients
Please read - http://dev.mendeley.com/methods/#document-views
You need to specify 'view=bib' on your endpoint call.
Here is a very crude worked example just using Java
#Test
public void testImplicitGrantFlow() {
String random = RandomStringUtils.random(5);
String query = String.format(
"?client_id=%s&redirect_uri=%s&response_type=token&scope=all&state=%s", IMPLICIT_GRANT_FLOW_CLIENT_ID, "http://localhost:5000/callback", random);
ClientResponse authorise = jerseyClient.resource(AUTH_URL + query)
.accept(MediaType.APPLICATION_JSON)
.get(ClientResponse.class);
assertThat(authorise.getStatus()).isEqualTo(200);
ClientResponse postFormDataResponse = jerseyClient.resource(AUTH_URL + query)
.entity("username=joyce.stack#mendeley.com&password=spuds", MediaType.APPLICATION_FORM_URLENCODED_TYPE)
.accept(MediaType.APPLICATION_JSON)
.post(ClientResponse.class);
assertThat(postFormDataResponse.getStatus()).isEqualTo(302);
String queryString = postFormDataResponse.getHeaders().get("Location").get(0);
Matcher matcher = ACCESS_TOKEN_REGEX.matcher(queryString);
matcher.find();
String accessToken = matcher.group(1);
matcher = STATE_REGEX.matcher(queryString);
matcher.find();
String state = matcher.group(1);
assertNotNull(accessToken);
assertThat(queryString).contains(accessToken);
assertNotNull(state);
assertThat(queryString).contains(state);
ClientResponse response = jerseyClient.resource(OAuthBaseClass.DOCUMENTS_URL)
.header("Authorization", "Bearer " + accessToken)
.get(ClientResponse.class);
assertThat(response.getStatus()).isEqualTo(200);
List<Document> documents = response.getEntity(new GenericType<List<Document>>() {
});
assertThat(documents.size()).isGreaterThan(0);
ListIterator<Document> documentListIterator = documents.listIterator();
while (documentListIterator.hasNext()) {
Document next = documentListIterator.next();
System.out.println(next.getTitle());
System.out.println(next.getWebsites());
}
}

DotNetOpenAuth detect fetch request like google

With google, you can fetch the user's email like this:
var fetch = new FetchRequest();
fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
request.AddExtension(fetch);
and get it back like this:
var fetch = response.GetExtension<FetchResponse>();
string email = "";
if (fetch != null)
{
email = fetch.GetAttributeValue(WellKnownAttributes.Contact.Email);
}
When writing a provider, how can I return the values asked for?
The OpenIdProviderWebForms sample that comes with DotNetOpenAuth includes returning user attributes. Have you checked it out?

Resources