Handling apostrophes in graph query

Michael Fleet 101 Reputation points
2025-04-29T08:59:49.36+00:00

@RithwikBojja

My graph query fails if the user has an apostrophe in their name e.g. -

https://graph.microsoft.com/v1.0/deviceManagement/managedDevices?$select=azureADDeviceId&$filter=startswith(userPrincipalName,'bob.o'******@domain.com')

This is called from within a for loop in my Logic App, iterating through members of an Entra group.

I understand that this can be handled by double escaping -

https://learn.microsoft.com/en-us/graph/query-parameters?view=graph-rest-1.0&tabs=http#escaping-single-quotes

What's the best way of handling this?

I have an existing codeblock, so wonder if I can replace the text (if it exists) inline? The field is user.userPrincipalName.

const entradata = workflowContext.actions.Parse_the_Entra_data.outputs.body;
const entra_users = Array.isArray(entradata) ? entradata : entradata.value;
const defaultdate = new Date("2000-01-01T00:00:00Z");
function parseDate(user) {
    return user.signInActivity && user.signInActivity.lastSignInDateTime
        ? new Date(user.signInActivity.lastSignInDateTime)
        : defaultdate;
}
const ri_sort_json = [...entra_users].sort((a, b) => {
    const dateA = parseDate(a);
    const dateB = parseDate(b);
    return dateB - dateA;
});
ri_sort_json.forEach(user => {
    if (!user.signInActivity) {
        user.signInActivity = {};
    }
    if (!user.signInActivity.lastSignInDateTime) {
        user.signInActivity.lastSignInDateTime = defaultdate.toISOString();
    }
});
return ri_sort_json;
Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,470 questions
{count} votes

Accepted answer
  1. RithwikBojja 2,080 Reputation points Microsoft External Staff
    2025-04-29T11:25:03.28+00:00

    Hi @Michael Fleet ,

    If there is any apostrophes in names you can use below action which makes the logic app call the api correctly:

    
    replace(nameofuser or userprincipalname, '''', '''''')}
    
    

    Then changed it like below to make it work:

    
    https://graph.microsoft.com/v1.0/deviceManagement/managedDevices?$select=azureADDeviceId&$filter=startswith(userPrincipalName,replace(colleen.o'******@barnardos.org.uk, '''', ''''''))
    
    

    If this answer was helpful, please click "Accept the answer" and mark Yes, as this can help other community members.

    enter image description here

    If you have any other questions or are still experiencing issues, feel free to ask in the "comments" section, and I'd be happy to help.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.