Found this content helpful? Log in or sign up to leave a like!

GraphQL Masquerading

Jump to solution
PhillipJacobs
Community Member

Hello!

I am working on a process to pull messages sent through the Canvas Inbox and the conversations APIs only work in the self-scope.

The documentation is very clear on how to use masquerading (act-as) with the APIs: https://developerdocs.instructure.com/services/canvas/basics/file.masquerading

What I am not seeing is anything on how to do the same with GraphQL: https://developerdocs.instructure.com/services/canvas/basics/file.graphql

Any chance you can point me in the right direction?

For reference the GraphQL query is:

query getConvMsgs($conversationId: ID!, $authorId: [ID!], $nextCursor: String!) {
legacyNode(_id: $conversationId, type: Conversation) {
... on Conversation {
conversationMessagesConnection(participants: $authorId, first: 100, after: $nextCursor) {
nodes {
body
createdAt
_id
author {
_id
}
conversationId
}
pageInfo {
hasNextPage
endCursor
startCursor
}
}
}
}
}

 

Thank you!

-Phil

Labels (2)
0 Likes
1 Solution
James
Community Champion

Masquerading can work the same way with GraphQL.

Instead of POST /api/graphql, use POST /api/graphql?as_user_id=1234

The body of the GraphQL doesn't change when you do it this way.

 

The second way to do it is to add as_user_id as a property to the body. Instead of just query and variables, you now have as_user_id as well. For example:

{
  "query": "GraphQL query goes here",
  "variables": { variables },
  "as_user_id": 1234
}

 

 

 

View solution in original post