API Post call returns "Failed to Fetch"

Copper Contributor

> I have created a SPFx Web Part using React.

> It implict authenticates and acquires access token.

> When i am calling graph api for GET it works fine.

> When i am calling graph api for POST call for creating user. It is creating user in AD as well as throws error of "Failed to Fetch" and not getting updated user object in response.

 

Find code below to call this api.

 

private static createADUser(accessToken: string, httpClient: HttpClient, objUser: string): Promise<IUser> {
return new Promise<IUser>((resolve: (newUser: IUser) => void, reject: (error: any) => string): void => {
httpClient.post(`https://graph.microsoft.com/v1.0/users`, HttpClient.configurations.v1, {
headers: {
'Content-type': 'application/json;odata.metadata=none',
'Authorization': 'Bearer ' + accessToken,
},
body: objUser
})
.then((response: HttpClientResponse): Promise<any> => {
return response.json();
}).then((objUser: any) => {
resolve(objUser);
}, (error: any): string => {
var strError: string = error.message;
if (strError.toLowerCase() == "failed to fetch")
resolve(null);
else
reject(strError);
return;
});
});
}
 

Does anyone know about it? What may be the cause of it and what will be the solution?

 Thank you in advance.

2 Replies

Have you tried with Graph Explorer? Does this work:

 

https://developer.microsoft.com/en-us/graph/graph-explorer

Yes its working fine with graph explorer.

 

It also creates user but not returning response.