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
nicolast29
Helper V
Helper V

post request

Hi folks, I wish to connect to our new software provider via Api

https://docs.api.myunisoft.fr/#b953be72-03e7-4be6-8638-d14025bdab46

 

I have no problem to make get request, but the post didn't work with PowerBi

I arrive to make the post request with https://web.postman.co/ 

https://api.myunisoft.fr/api/v1/export/fec?export_type=1&from=2021-01-01&to=2021-12-30

I cannot give you the real values, but here my code

let
    vToken = "Bearer "&"TokenXXX",
    vSecret="SecretXXX",
    vsociety="XXXX",
    vUrl = "https://api.myunisoft.fr/api/v1/export/FEC?export_type=1&from=2021-01-01&to=2021-12-30",
    body = "{""}",
    Source = Json.Document(Web.Contents(vUrl, [Headers=[Authorization="vToken", #"X-Third-Party-Secret"="vSecret", #"society-id"="vsociety",#"Content-Type"="application/json"],Content = Text.ToBinary(body)])) 

in
    Source

I try without content = text.tobinary or content = text.tobinary ="" etc ... 

My last reseach make me think that i come from that i should send a empty body information ...

 

The last error return unable to convert a value type binary in text

 

Normally the value are a FEC, a text file with value, example from postman:

 

JournalCode|JournalLib|EcritureNum|EcritureDate|CompteNum|CompteLib|CompAuxNum|CompAuxLib|PieceRef|PieceDate|EcritureLib|Debit|Credit|EcritureLet|DateLet|ValidDate|Montantdevise|Idevise|RefInterne
RAN|RAN|2101RAN3182509|20210101|10130000|Capital souscrit appelé versé|||CEX0121|20210101|S.A.N.|0|1000|||20210101|||E3182509
RAN|RAN|2101RAN3182509|20210101|11900000|Report à nouveau débit|||CEX0121|20210101|S.A.N.|9706,25|0|||20210101|||E3182509

 

 

thanks

 

6 REPLIES 6
nicolast29
Helper V
Helper V

thanks for helping, but still not working, i will try to call the editor

 

v-shex-msft
Community Support
Community Support

Hi @nicolast29,

I modify the code to split the URL to root and relativepath and add a query to the connection. You can try to use the following query if they suitable for your requirement:

 

let
    vToken = "Bearer " & "TokenXXX",
    vSecret = "SecretXXX",
    vsociety = "XXXX",
    rootURL = "https://api.myunisoft.fr/api",
    relativePath = "/v1/export/FEC",
    //vUrl = "https://api.myunisoft.fr?export_type=1&from=2021-01-01&to=2021-12-30",
    Source =
        Json.Document(
            Web.Contents(
                rootURL,
                [
                    Headers = [
                        Authorization = vToken,
                        #"X-Third-Party-Secret" = vSecret,
                        #"society-id" = vsociety,
                        #"Content-Type" = "application/json"
                    ],
                    RelativePath = relativePath,
                    Query = [
                        export_type = "1",
                        from = "2021-01-01",
                        to = "2021-12-30"
                    ]
                ]
            )
        )
in
    Source

 

Chris Webb's BI Blog: Using The RelativePath And Query Options With Web.Contents() In Power Query An...

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Thanks for your answer

I modify my code with your informations but i still have a reponse error:

 

DataSource.Error : Web.Contents n'a pas réussi à obtenir le contenu de « https://api.myunisoft.fr/api/v1/export/FEC?export_type=1&from=2021-01-01&to=2021-12-31 » (405) : Method Not Allowed
Détails :
DataSourceKind=Web
DataSourcePath=https://api.myunisoft.fr/api/v1/export/FEC
Url=https://api.myunisoft.fr/api/v1/export/FEC?export_type=1&from=2021-01-01&to=2021-12-31

I make further search, 

It seem that i should have a body in order to make a POST request

https://developer.genesys.cloud/forum/t/connecting-with-power-bi/14366

 

but in my case i should send a empty body

I try by adding this 

vbody = "the post method",

 

Source =
Json.Document(
Web.Contents(
//vURL,
rootURL,
[
Headers = [
Content=Text.ToBinary(vbody),
Authorization = vToken,
#"X-Third-Party-Secret" = vSecret,
#"society-id" = vsociety,
#"Content-Type" = "application/json"
],
RelativePath = relativePath,
Query = [
export_type = "1",
from = "2021-01-01",
to = "2021-12-31"
]
]
)
)


in
Source

 

 

but i still have a error :

Expression.Error : Désolé... Nous n'avons pas pu convertir une valeur de type Binary en type Text.
Détails :
Value=[Binary]
Type=[Type]

 

 

It is the same with Content=Text.ToBinary("")

Hi @nicolast29,

In fact, 'Content' is an optional parameter in web connector and it should list at the same level as 'Header':

let
    vToken = "Bearer " & "TokenXXX",
    vSecret = "SecretXXX",
    vsociety = "XXXX",
    rootURL = "https://api.myunisoft.fr/api",
    body = "{}",
    relativePath = "/v1/export/FEC",
    //vUrl = "https://api.myunisoft.fr?export_type=1&from=2021-01-01&to=2021-12-30",
    Source =
        Json.Document(
            Web.Contents(
                rootURL,
                [
                    Headers = [
                        Authorization = vToken,
                        #"X-Third-Party-Secret" = vSecret,
                        #"society-id" = vsociety,
                        #"Content-Type" = "application/json"
                    ],
                    RelativePath = relativePath,
                    Content = Text.ToBinary(body),
                    Query = [
                        export_type = "1",
                        from = "2021-01-01",
                        to = "2021-12-30"
                    ]
                ]
            )
        )
in
    Source

I'm not so sure which type of content your API requirement, maybe you can check the API document and add the corresponding JSON strings in the 'body' step.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

i still have a problem

I am working on 

Thanks 

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.