Forum Discussion

Vani_metamicro's avatar
Vani_metamicro
Copper Contributor
Feb 18, 2020

post request - errors

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 = "

https://prod-47.westeurope.logic.azure.com:443/workflows/e3b6a1d38c654c76b7853e67c14b1ff1/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=0RTMbBNtEVHqn5NBu-UiMMLWRLAQdV1FKJHGTqpTQsA"

";
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

  • MadhuriCh's avatar
    MadhuriCh
    Copper Contributor

    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 = "

    https://prod-47.westeurope.logic.azure.com/workflows/e3b6a1d38c654c76b7853e67c14b1ff1/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=0RTMbBNtEVHqn5NBu-UiMMLWRLAQdV1FKJHGTqpTQsA"

    ";

     

    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 = "

    https://prod-47.westeurope.logic.azure.com/workflows/e3b6a1d38c654c76b7853e67c14b1ff1/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=0RTMbBNtEVHqn5NBu-UiMMLWRLAQdV1FKJHGTqpTQsA"

    ";
    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