microsoftgraph / msgraph-sdk-java

Microsoft Graph SDK for Java
https://docs.microsoft.com/en-us/graph/sdks/sdks-overview
MIT License
387 stars 132 forks source link

Archiving (and un-archiving) a channel #2097

Closed marusic1514 closed 1 month ago

marusic1514 commented 3 months ago

Describe the bug

I am trying to archive a channel, following these instructions: https://learn.microsoft.com/en-us/graph/api/channel-archive?view=graph-rest-1.0&tabs=java but there is no .archive() method that I can find. I can delete a channel, following the delete instructions and it works just fine.

Needless to say, unarchive also does not work

Expected behavior

Channel gets archived

How to reproduce

    val credential = ClientSecretCredentialBuilder()
        .clientId(<clientId>)
        .tenantId(<tenantId>)
        .clientSecret(<secret>)
        .build()
    val graphClient = GraphServiceClient(credential, "https://graph.microsoft.com/.default")

    // delete channel -- this works
    graphClient.teams().byTeamId(<teamId>).channels().byChannelId(<channelId>).delete()

    // archive channel -- archive() does not appear as a valid function
    graphClient.teams().byTeamId(<teamId>).channels().byChannelId(<channelId>).archive()

SDK Version

6.13.0

Latest version known to work for scenario above?

No response

Known Workarounds

Managed to find this workaround for now:

val rest: TqRestClient = TqRestClient()
val token = credential.getTokenSync(TokenRequestContext().setTenantId(tenantId).setScopes(listOf(scope)))
rest.post(
    url = "https://graph.microsoft.com/v1.0/teams/$teamId/channels/$channelId/archive",
    json = mapOf(
        "client_id" to clientId,
        "client_secret" to clientSecret,
        "scope" to scope,
    ),
    headers = mapOf(
        "Content-Type" to "application/json",
        "Authorization" to "Bearer ${token.token}"
    )
)

Debug output

Click to expand log ``` ```

Configuration

No response

Other information

No response

sepatel commented 3 months ago

+1

Ndiritu commented 2 months ago

Thanks for raising this @marusic1514 @sepatel Apologies for the experience.

We are soon to release a new update of the SDK that will contain this method and unarchive

As a temporary workaround, you can use:


client.teams().byTeamId("{team-id}").channels().withUrl(
    "https://graph.microsoft.com/v1.0/teams/{team-id}/channels/{channel-id}/archive"
).post(body);
Ndiritu commented 1 month ago

@marusic1514 the archive() and unarchive() methods are now available in the latest version of the SDK.