post request - errors

%3CLINGO-SUB%20id%3D%22lingo-sub-1179328%22%20slang%3D%22en-US%22%3Epost%20request%20-%20errors%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1179328%22%20slang%3D%22en-US%22%3E%3CP%3EHello%20Everyone%2C%3C%2FP%3E%3CP%3EI%20created%20URL%20for%20post%20request%20by%20using%20MSFlow.%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20share%20point%20framework%2C%20I%20am%20sending%20a%20post%20request%20and%20just%20expecting%20response%20by%20writing%20the%20below%20lines%20of%20code%3C%2FP%3E%3CP%3E%26nbsp%3Bprivate%20_getListData()%3A%20Promise%3CANY%3E%20%7B%3CBR%20%2F%3Econst%20spOpts%3AISPHttpClientOptions%3D%20%7Bheaders%3A%20%7B%20'Content-Type'%3A%20'value'%20%7D%2C%20body%3A%22value%22%20%7D%3B%3CBR%20%2F%3Econst%20postURl%20%3D%20%22%3C%2FANY%3E%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fprod-47.westeurope.logic.azure.com%3A443%2Fworkflows%2Fe3b6a1d38c654c76b7853e67c14b1ff1%2Ftriggers%2Fmanual%2Fpaths%2Finvoke%3Fapi-version%3D2016-06-01%26amp%3Bsp%3D%252Ftriggers%252Fmanual%252Frun%26amp%3Bsv%3D1.0%26amp%3Bsig%3D0RTMbBNtEVHqn5NBu-UiMMLWRLAQdV1FKJHGTqpTQsA%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fprod-47.westeurope.logic.azure.com%3A443%2Fworkflows%2Fe3b6a1d38c654c76b7853e67c14b1ff1%2Ftriggers%2Fmanual%2Fpaths%2Finvoke%3Fapi-version%3D2016-06-01%26amp%3Bsp%3D%252Ftriggers%252Fmanual%252Frun%26amp%3Bsv%3D1.0%26amp%3Bsig%3D0RTMbBNtEVHqn5NBu-UiMMLWRLAQdV1FKJHGTqpTQsA%3C%2FA%3E%22%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CP%3E%22%3B%3CBR%20%2F%3Ereturn%20this.context.spHttpClient%3CBR%20%2F%3E.post(postURl%2C%20SPHttpClient.configurations.v1%2C%20spOpts)%3CBR%20%2F%3E.then((response%3A%20any)%20%3D%26gt%3B%20%7B%3CBR%20%2F%3Econsole.log('Post%20request%20is%20success'%2C%20response)%3B%3CBR%20%2F%3Ereturn%20response.json()%3B%3CBR%20%2F%3E%7D)%3B%3CBR%20%2F%3E%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhen%20i%20check%20the%20URL%20in%20Postman%2C%20the%20post%20request%20is%20working%20okay%20and%20i%20am%20receiving%20the%20response%20back.%20but%20When%20i%20try%20that%20URL%20in%20share%20point%20framework(HelloWorldWebPart.ts)%2C%26nbsp%3B%20I%20get%20error%3C%2FP%3E%3CP%3EUncaught%20(in%20promise)%20Error%3A%20Unable%20to%20determine%20web%20URL%3CBR%20%2F%3Eat%20Function.e.getWebUrlFromRequestUrl%20(sp-webpart-workbench-assembly_en-us_8c5f51c6434ef13aebeff59cb3564410.js%3A19)%3CBR%20%2F%3Eat%20sp-webpart-workbench-assembly_en-us_8c5f51c6434ef13aebeff59cb3564410.js%3A19%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPlease%20could%20some%20one%20help%20me%20to%20fix%20this%20error%2C%20i%20am%20not%20sure%20where%20i%20am%20doing%20it%20incorrect.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1265994%22%20slang%3D%22en-US%22%3ERe%3A%20post%20request%20-%20errors%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1265994%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F540178%22%20target%3D%22_blank%22%3E%40Vani_metamicro%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDid%20you%20ever%20figure%20this%20out%3F%26nbsp%3B%20I'm%20having%20the%20same%20issue%20in%20my%20code.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1423575%22%20slang%3D%22en-US%22%3ERe%3A%20post%20request%20-%20errors%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1423575%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F540178%22%20target%3D%22_blank%22%3E%40Vani_metamicro%3C%2FA%3E%26nbsp%3B%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESPHttpClient%20class%26nbsp%3BgetWebUrlFromRequestUrl(requestUrl)%20method%20a%3CSPAN%3Ettempts%20to%20infer%20the%20SPWeb%20URL%20associated%20with%20the%20provided%20REST%20URL%2C%20by%20looking%20for%20common%20SharePoint%20path%20components%20such%20as%20%22_api%22%2C%20%22_layouts%22%2C%20or%20%22_vit_bin%22.%20So%2C%20if%20the%20requestUrl%20is%20%22%3CA%20href%3D%22http%3A%2F%2Fexample.com%2F_layouts%2Fservice%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ehttp%3A%2F%2Fexample.com%2F_layouts%2Fservice%3C%2FA%3E%22%2C%20the%20returned%20URL%20would%20be%20%22%3CA%20href%3D%22http%3A%2F%2Fexample.com%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ehttp%3A%2F%2Fexample.com%3C%2FA%3E%22.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EBut%20here%2C%20the%20url%20generated%20is%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3Econst%20postURl%20%3D%20%22%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3E-ERR%3AREF-NOT-FOUND-%3CA%20href%3D%22https%3A%2F%2Fprod-47.westeurope.logic.azure.com%3A443%2Fworkflows%2Fe3b6a1d38c654c76b7853e67c14b1ff1%2Ftriggers%2Fm%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fprod-47.westeurope.logic.azure.com%3A443%2Fworkflows%2Fe3b6a1d38c654c76b7853e67c14b1ff1%2Ftriggers%2Fm%3C%2FA%3E...%22%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CP%3E%22%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%2C%20it%20could%20not%20infer%20any%20SPWebUrl%20from%20it.%20So%2C%20instead%20of%20SPHttpClient%2C%20use%20HttpClient%20class.%20Also%2C%20the%20flow%20will%20be%20triggered%20by%20a%20HttpRequest.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20modified%20code%20is%3A%3C%2FP%3E%3CP%3Eprivate%20_getListData()%3A%20Promise%3CANY%3E%20%7B%3CBR%20%2F%3Econst%20spOpts%3AIHttpClientOptions%3D%20%7Bheaders%3A%20%7B%20'Content-Type'%3A%20'value'%20%7D%2C%20body%3A%22value%22%20%7D%3B%3CBR%20%2F%3Econst%20postURl%20%3D%20%22%3C%2FANY%3E%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fprod-47.westeurope.logic.azure.com%2Fworkflows%2Fe3b6a1d38c654c76b7853e67c14b1ff1%2Ftriggers%2Fmanual%2Fpaths%2Finvoke%3Fapi-version%3D2016-06-01%26amp%3Bsp%3D%252Ftriggers%252Fmanual%252Frun%26amp%3Bsv%3D1.0%26amp%3Bsig%3D0RTMbBNtEVHqn5NBu-UiMMLWRLAQdV1FKJHGTqpTQsA%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fprod-47.westeurope.logic.azure.com%3A443%2Fworkflows%2Fe3b6a1d38c654c76b7853e67c14b1ff1%2Ftriggers%2Fm...%3C%2FA%3E%22%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CP%3E%22%3B%3CBR%20%2F%3Ereturn%20this.context.HttpClient%3CBR%20%2F%3E.post(postURl%2C%20HttpClient.configurations.v1%2C%20spOpts)%3CBR%20%2F%3E.then((response%3A%20any)%20%3D%26gt%3B%20%7B%3CBR%20%2F%3Econsole.log('Post%20request%20is%20success'%2C%20response)%3B%3CBR%20%2F%3Ereturn%20response.json()%3B%3CBR%20%2F%3E%7D)%3B%3CBR%20%2F%3E%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20more%20info%2C%20refer%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fjavascript%2Fapi%2Fsp-http%2Fsphttpclient%3Fview%3Dsp-typescript-latest%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fjavascript%2Fapi%2Fsp-http%2Fsphttpclient%3Fview%3Dsp-typescript-latest%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

Hello Everyone,

I created URL for post request by using MSFlow. 

In share point framework, I am sending a post request and just expecting response by writing the below lines of code

 private _getListData(): Promise<any> {
const spOpts:ISPHttpClientOptions= {headers: { 'Content-Type': 'value' }, body:"value" };
const postURl = "

";
return this.context.spHttpClient
.post(postURl, SPHttpClient.configurations.v1, spOpts)
.then((response: any) => {
console.log('Post request is success', response);
return response.json();
});
}

 

When i check the URL in Postman, the post request is working okay and i am receiving the response back. but When i try that URL in share point framework(HelloWorldWebPart.ts),  I get error

Uncaught (in promise) Error: Unable to determine web URL
at Function.e.getWebUrlFromRequestUrl (sp-webpart-workbench-assembly_en-us_8c5f51c6434ef13aebeff59cb3564410.js:19)
at sp-webpart-workbench-assembly_en-us_8c5f51c6434ef13aebeff59cb3564410.js:19

 

Please could some one help me to fix this error, i am not sure where i am doing it incorrect. 

 

2 Replies

@Vani_metamicro 

Did you ever figure this out?  I'm having the same issue in my code.

Hi @Vani_metamicro ,

 

SPHttpClient class getWebUrlFromRequestUrl(requestUrl) method attempts to infer the SPWeb URL associated with the provided REST URL, by looking for common SharePoint path components such as "_api", "_layouts", or "_vit_bin". So, if the requestUrl is "http://example.com/_layouts/service", the returned URL would be "http://example.com".

 

But here, the url generated is 

const postURl = "

";

 

So, it could not infer any SPWebUrl from it. So, instead of SPHttpClient, use HttpClient class. Also, the flow will be triggered by a HttpRequest.

 

The modified code is:

private _getListData(): Promise<any> {
const spOpts:IHttpClientOptions= {headers: { 'Content-Type': 'value' }, body:"value" };
const postURl = "

";
return this.context.HttpClient
.post(postURl, HttpClient.configurations.v1, spOpts)
.then((response: any) => {
console.log('Post request is success', response);
return response.json();
});
}

 

For more info, refer https://docs.microsoft.com/en-us/javascript/api/sp-http/sphttpclient?view=sp-typescript-latest