microsoftgraph / msgraph-sdk-javascript

Microsoft Graph client library for JavaScript
https://graph.microsoft.com
MIT License
730 stars 220 forks source link

ReadableStream returned on create/post #1663

Closed gRoberts84 closed 2 months ago

gRoberts84 commented 2 months ago

Bug Report

Prerequisites

For more information, see the CONTRIBUTING guide.

Description

When attempting to create an item (e.g. Team), it returns a ReadableStream with no response.

Steps to Reproduce

require('isomorphic-fetch');
const consumers = require('stream/consumers');
const azure = require('@azure/identity');
const graph = require('@microsoft/microsoft-graph-client');
const authProviders = require('@microsoft/microsoft-graph-client/authProviders/azureTokenCredentials');

const clientSecretCredential = new azure.ClientSecretCredential(
    tenantId,
    clientId,
    clientSecret
);

const authProvider = new authProviders.TokenCredentialAuthenticationProvider(
    clientSecretCredential, {
    scopes: ['https://graph.microsoft.com/.default']
});

const client = graph.Client.initWithMiddleware({
    authProvider: authProvider
});

const team = await client.api('/teams').post({
    '@microsoft.graph.teamCreationMode': 'migration',
    'template@odata.bind': "https://graph.microsoft.com/v1.0/teamsTemplates('standard')",
    'displayName': 'Clients',
    'description': 'Description for clients team',
    'createdDateTime': '2020-03-14T11:22:17.067Z'
});

Expected behavior:

Based on the documentation, I should receive a response object containing information relating to the object I've just created.

Actual behavior:

When console logging team, I receive:

ReadableStream { locked: false, state: 'readable', supportsBYOB: true }

If I try to use consumables to convert the stream to text/json, it returns an empty string or error that it's invalid json.

Additional Context

I am currently trying to create a team/channel etc in migration mode to import messages from another platform.

If I send an invalid request, it correctly returns the error.

Package versions:

Usage Information

Request ID - Value of the requestId field if you are receiving a Graph API error response

SDK Version - [SDK version you are using]

Node Version - v21.7.2

Browser Name - [The name of Browser that you are using for SDK]

Version - [The version of the browser you are using]

gRoberts84 commented 2 months ago

Apologies, I didn't read the documentation properly 🤦‍♂️

let response = await client.api('/teams').responseType(graph.ResponseType.RAW).post({
    '@microsoft.graph.teamCreationMode': 'migration',
    'template@odata.bind': "https://graph.microsoft.com/v1.0/teamsTemplates('standard')",
    'displayName': 'Clients',
    'description': 'Description for clients team',
    'createdDateTime': '2020-03-14T11:22:17.067Z'
});
const team_id = response.headers.get('content-location').replace('/teams(\'', '').replace('\')', '');

I don't know why but I misread the documentation and thought it would return the team object as if you had done a get on one.