Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
twilkdaddy
Frequent Visitor

Does Power Query support OPTIONS METHOD?

I am trying to write a query using the OPTIONS method in order to pull URIs for contactIDs in my data set.  However, I cannot find any documentation on how to apply the OPTIONS METHOD to a Web.Contents query.

 

Does anyone know if this is possible and, if not, is there a workaround??

 

See code below:

 

let
Source = Json.Document(Web.Contents("https://ws-use.brightpearl.com/public-api/dude/contact-service/contact/", [Headers=[#"brightpearl-app-ref"="dude_powerbi-1", #"brightpearl-account-token"="GNVf5bK9ihanzifXke3BKkr2vp2fPntxOqJoKAXnsjI=", accept="application/json", #"accept-encoding"="gzip, deflate", #"accept-language"="en-US,en;q=0.8", #"Content-Type"="application/json"],#"Query"="OPTIONS"]))
in
Source

 

 

4 REPLIES 4
v-ljerr-msft
Employee
Employee

Hi @twilkdaddy,

 

Do you mean passing query parameters with the Query argument of Web.Contents? If that is the case, the code below is for your reference. Smiley Happy

let
Source = Json.Document(Web.Contents("https://ws-use.brightpearl.com/public-api/dude/contact-service/contact/", 

Query = [<insert record here of your query object>],

[Headers=[#"brightpearl-app-ref"="dude_powerbi-1", #"brightpearl-account-token"="GNVf5bK9ihanzifXke3BKkr2vp2fPntxOqJoKAXnsjI=", accept="application/json", #"accept-encoding"="gzip, deflate", #"accept-language"="en-US,en;q=0.8", #"Content-Type"="application/json"]))

in Source

An example of the Query record might be:

Query = [#"Argument 1" = "aaa", #"Argument 2" = "bbbb"]

 

Regards

Thanks for the reply.  However, maybe I wasn't clear what I'm trying to accomplish.  

 

In standard web querying, there are GET, POST, DELETE, etc. METHODS you can call for your query.  I'm attempting to call using the OPTIONS method; however, it doesn't look like the Power Query Web.Contents method supports the OPTIONS method.  

 

Here's an example of what a C# syntax looks like for swithing to OPTIONS METHOD:

 

myHttpWebRequest.Method = "OPTIONS";

 

So, I'm wondering if anyone has a workaround in Power BI to allow for writing a query using OPTIONS instead of GET. 

Hi @twilkdaddy,

 

Sorry for my misunderstanding.

 

I don't think the Power Query Web.Contents method supports the OPTIONS method currently. You can add it as an idea on Power BI Ideas to improve Power BI on this feature. Smiley Happy

 

Regards

Thanks for the respnse @v-ljerr-msft.  

 

Does anyone know if a System.Net HttpWebRequest query can be fed into the Power BI Query Advanced Editor?  I know the OPTIONS method is available using C# query code.  See general code below that I beleive I can modify to make an OPTIONS method request to the API service I'm trying to query from.

 

using System;
using System.IO;
using System.Net;
using System.Text;

public enum HttpVerb
{
GET,
OPTIONS
}

namespace HttpUtils
{
public class RestClient
{
public string EndPoint { get; set; }
public HttpVerb Method { get; set; }
public string ContentType { get; set; }
public string Accept { get; set; }
public string brightpearl-app-ref { get; set; }
public string brightpearl-account-token { get; set; }

public RestClient()
{
EndPoint = "";
Method = HttpVerb.OPTIONS;
ContentType = "application/json";
Accept = "application/json";
}
public RestClient(string endpoint)
{
EndPoint = endpoint;
Method = HttpVerb.OPTIONS;
ContentType = "application/json";
Accept = "application/json";
}
public RestClient(string endpoint, HttpVerb method)
{
EndPoint = endpoint;
Method = method;
ContentType = "application/json";
Accept = "application/json";
}

public RestClient(string endpoint, HttpVerb method, string postData)
{
EndPoint = endpoint;
Method = method;
ContentType = "application/json";
Accept = "application/json";
}


public string MakeRequest()
{
return MakeRequest("");
}

public string MakeRequest(string parameters)
{
var request = (HttpWebRequest)WebRequest.Create(EndPoint + parameters);

request.Method = Method.ToString();
request.ContentLength = 0;
request.ContentType = ContentType;

if (!string.IsNullOrEmpty(PostData) && Method == HttpVerb.OPTIONS)
{
var encoding = new UTF8Encoding();
var bytes = Encoding.GetEncoding("iso-8859-1").GetBytes(PostData);
request.ContentLength = bytes.Length;

using (var writeStream = request.GetRequestStream())
{
writeStream.Write(bytes, 0, bytes.Length);
}
}

using (var response = (HttpWebResponse)request.GetResponse())
{
var responseValue = string.Empty;

if (response.StatusCode != HttpStatusCode.OK)
{
var message = String.Format("Request failed. Received HTTP {0}", response.StatusCode);
throw new ApplicationException(message);
}

// grab the response
using (var responseStream = response.GetResponseStream())
{
if (responseStream != null)
using (var reader = new StreamReader(responseStream))
{
responseValue = reader.ReadToEnd();
}
}

return responseValue;
}
}

} // class

}

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors