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

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
EDO_01_1789
Helper I
Helper I

convert python code to M inside query

Hello everyone,

would anyone be able to help me translate this code which is written in python to M language in power query.

I can't convert

 

import http.client

conn = http.client.HTTPConnection("app.salsify.com")

payload = "{\n    \"configuration\": {\n        \"entity_type\": \"all\",\n        \"filter\": \"=list:default\",\n        \"properties\": \"'UPC','Product Name','Brand','Main Image','Short Description','Long Description'\",\n        \"include_all_columns\": false,\n        \"sort_order\": \"desc\",\n        \"sort_property\": \"Brand\"\n    }\n}"

headers = {
    'Content-Type': "application/json",
    'Authorization': "Bearer s-999-999-999-999",
    'User-Agent': "PostmanRuntime/7.19.0",
    'Accept': "*/*",
    'Cache-Control': "no-cache",
    'Host': "app.salsify.com",
    'Accept-Encoding': "gzip, deflate",
    'Content-Length': "304",
    'Cookie': "_cookie_id",
    'Connection': "keep-alive",
    'cache-control': "no-cache"
    }

conn.request("POST", "api,orgs,s-999-999-999-999,export_runs", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))

# where org_id = s-999-999-999-999, api_token = YOUR-AUTH-TOKEN, and cookie id = _cookie_id

 

thank you for your help.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @EDO_01_1789,

Any update on this? Did the above suggestions help with your scenario? if that is the case, you can consider Kudo or accept the helpful suggestions to help others who faced similar requirements.

If these also don't help, please share more detailed information to help us clarify your scenario to test.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

Hi @EDO_01_1789,

Any update on this? Did the above suggestions help with your scenario? if that is the case, you can consider Kudo or accept the helpful suggestions to help others who faced similar requirements.

If these also don't help, please share more detailed information to help us clarify your scenario to test.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

EDO_01_1789
Helper I
Helper I

@lbendlin ,

 

I just tried this code and it doesn't work
here is my error message

EDO_01_1789_0-1651146751794.png

 

here is the code I pasted in the query

let
    url = "https://app.salsify.com",
    payload = "{\""configuration\"": {\""entity_type\"": \""all\"",\""filter\"": \""=list:default\"",\""properties\"": \""'UPC','Product Name','Brand','Main Image','Short Description','Long Description'\"",\""include_all_columns\"": false,\""sort_order\"": \""desc\"",\""sort_property\"": \""Brand\""}}",
    Source = Web.Contents(url, [Headers=[#"Content-Type"="application/json", Authorization="abcde"]])
in
    Source

 

 

The message is clear on what you need to do.  Easiest will be to go to data source settings, remove the API source, and then refresh, specifying anonymous auth.

 

your "authorization"  header must have the format "Bearer abcde" , not just "abcde" .

it's starting to work, but do you know why I don't have any data?

EDO_01_1789_0-1651154855964.png

 

 

Your API call needs to be modified according to their documentation and based on what you are trying to accomplish.

lbendlin
Super User
Super User

You use the regular Web.Contents() call and specify the payload in the Content  section.

 

let
    url = "https://app.salsify.com",
    payload = "{\""configuration\"": {\""entity_type\"": \""all\"",\""filter\"": \""=list:default\"",\""properties\"": \""'UPC','Product Name','Brand','Main Image','Short Description','Long Description'\"",\""include_all_columns\"": false,\""sort_order\"": \""desc\"",\""sort_property\"": \""Brand\""}}",
    Source = Web.Contents(url,[Headers=[#"Content-Type"= "application/json",Authorization = "Bearer s-999-999-999-999"],Content=Text.ToBinary(payload)])
in
    Source

 

Without access to the API that's all the help we can provide.

Hello @lbendlin 
sorry for taking time to answer you.
I share with you below the link of the site which gives you more information about the API. https://developers.salsify.com/reference/get-export-status

I've been trying to connect to the site for more than a week.

The site tells me to use
org_id : in our example we will use ABCDE
export_id : in our example we will use XYZ

here is the code that the site generates for me in python and I would like to transform it into M language in the query.

is this possible ?

import http.client

conn = http.client.HTTPConnection("app.salsify.com")

payload = ""

headers = {
    'Content-Type': "application/json",
    'Authorization': "Bearer YOUR-AUTH-TOKEN",
    'User-Agent': "PostmanRuntime/7.19.0",
    'Accept': "*/*",
    'Cache-Control': "no-cache",
    'Host': "app.salsify.com",
    'Accept-Encoding': "gzip, deflate",
    'Cookie': "_cookie_id",
    'Connection': "keep-alive",
    'cache-control': "no-cache"
    }

conn.request("GET", "api,orgs,s-999-999-999-999,export_runs,19350473", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))

# where export_id = 19350473 org_id = s-999-999-999-999, api_token = YOUR-AUTH-TOKEN, cookie id = _cookie_id

thanks for your help

 

The process is the same as in my previous response, minus the payload. You switch between POST and GET by including a content option (or not).

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Kudoed Authors