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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Spartan
Frequent Visitor

Trying to connect to an API

Hello!

I have been going through the various documentations and links already provided i nthe various other posts about this topic, mainly this one: Chris Webb's BI Blog: Working with Web Services in Power Query Chris Webb's BI Blog (crossjoin.co.uk...

I keep getting an error message to which I do not have the knowledge to solve myself. I still new to Power BI.

 

When I make a custom query in the PQE with this format:
= Web.Contents("https://www.devstack.vwgroup.com/jira/secure/BOARDNAMEHERE",
[Query=[ #"filter"="", #"orderBy"=""],
ApiKeyName=[#"APIToken" ="APIKEYHERE"] ])

I get the following error:

Spartan_0-1673947144350.png

The token is made of numbers and text.

How can I solve this?

1 ACCEPTED SOLUTION
Daryl-Lynch-Bzy
Resident Rockstar
Resident Rockstar

Hi @Spartan - I start by creating an API token following these instuctions:  Manage API tokens for your Atlassian account | Atlassian Support.  When it comes to using the Token, there are two options for extracting JIRA data:

  • Download the CSV for Filters by using the Link.

DarylLynchBzy_0-1674030972146.png

 

 

DarylLynchBzy_1-1674030984891.png

 

let
    Source = 
        Csv.Document(
            Web.Contents("https://######.atlassian.net/sr/jira.issueviews:searchrequest-csv-all-fields/{id####}/SearchRequest-{id####}.csv"),
            [Delimiter=",", Encoding=65001, QuoteStyle=QuoteStyle.Csv]
        ),
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true])
in
    #"Promoted Headers" 

Note this example would store a data source connection for the fully specified csv file url.  You can make this relative path.

DarylLynchBzy_3-1674031927631.png

This provide a big flat csv table with single row for each issue.  While this is good, it is not great for columns with multiple values.  If you have 3 watchers for example, there will be 3 columns (watcher, watcher2, watcher3).

 

This is an example for the API call.

 

let
    #"JIRA Rest API URL Path" = "https://######.atlassian.net/rest/api/3/",
    #"Relative Path" = "/project/search",
    #"Max Results Per API Call" = 50,
    #"Initial API Call" = Web.Contents(
            #"JIRA Rest API URL Path",
            [
                RelativePath=#"Relative Path", 
                Headers=[Accept="application/json"], 
                Query=[startAt="0"]
            ]
        ),
    #"Open Initial API Call" = Json.Document(#"Initial API Call"),
    #"Get Total Items" = #"Open Initial API Call"[total],
    #"Number of API Calls" = Number.IntegerDivide(#"Get Total Items", #"Max Results Per API Call") + 1,
    #"Run API Calls" = 
    let
        #"Start At List" = List.Generate(() => 0, each _ < #"Number of API Calls" * 50 , each _ + 50 ),
        #"Call API" = List.Transform( #"Start At List" , each 
            Web.Contents(
                #"JIRA Rest API URL Path", 
                [
                    RelativePath=#"Relative Path", 
                    Headers=[Accept="application/json"], 
                    Query=[startAt=Text.From(_)]
                ])
            ),
        #"Open Json" = List.Transform( #"Call API" , each Json.Document(_) ),
        #"Get values" = List.Transform( #"Open Json" , each _[values] ),
        #"Get Lists" = List.Combine(#"Get values"),
        #"Converted to Table" = Table.FromList(#"Get Lists", Splitter.SplitByNothing(), type table[Records to Expand=Record.Type], null, ExtraValues.Error)
    in
        #"Converted to Table",

 

To use this call the following data source credentials are required for "https://######.atlassian.net/rest/api/3/"

DarylLynchBzy_2-1674031496068.png

 

View solution in original post

3 REPLIES 3
Daryl-Lynch-Bzy
Resident Rockstar
Resident Rockstar

Hi @Spartan - I start by creating an API token following these instuctions:  Manage API tokens for your Atlassian account | Atlassian Support.  When it comes to using the Token, there are two options for extracting JIRA data:

  • Download the CSV for Filters by using the Link.

DarylLynchBzy_0-1674030972146.png

 

 

DarylLynchBzy_1-1674030984891.png

 

let
    Source = 
        Csv.Document(
            Web.Contents("https://######.atlassian.net/sr/jira.issueviews:searchrequest-csv-all-fields/{id####}/SearchRequest-{id####}.csv"),
            [Delimiter=",", Encoding=65001, QuoteStyle=QuoteStyle.Csv]
        ),
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true])
in
    #"Promoted Headers" 

Note this example would store a data source connection for the fully specified csv file url.  You can make this relative path.

DarylLynchBzy_3-1674031927631.png

This provide a big flat csv table with single row for each issue.  While this is good, it is not great for columns with multiple values.  If you have 3 watchers for example, there will be 3 columns (watcher, watcher2, watcher3).

 

This is an example for the API call.

 

let
    #"JIRA Rest API URL Path" = "https://######.atlassian.net/rest/api/3/",
    #"Relative Path" = "/project/search",
    #"Max Results Per API Call" = 50,
    #"Initial API Call" = Web.Contents(
            #"JIRA Rest API URL Path",
            [
                RelativePath=#"Relative Path", 
                Headers=[Accept="application/json"], 
                Query=[startAt="0"]
            ]
        ),
    #"Open Initial API Call" = Json.Document(#"Initial API Call"),
    #"Get Total Items" = #"Open Initial API Call"[total],
    #"Number of API Calls" = Number.IntegerDivide(#"Get Total Items", #"Max Results Per API Call") + 1,
    #"Run API Calls" = 
    let
        #"Start At List" = List.Generate(() => 0, each _ < #"Number of API Calls" * 50 , each _ + 50 ),
        #"Call API" = List.Transform( #"Start At List" , each 
            Web.Contents(
                #"JIRA Rest API URL Path", 
                [
                    RelativePath=#"Relative Path", 
                    Headers=[Accept="application/json"], 
                    Query=[startAt=Text.From(_)]
                ])
            ),
        #"Open Json" = List.Transform( #"Call API" , each Json.Document(_) ),
        #"Get values" = List.Transform( #"Open Json" , each _[values] ),
        #"Get Lists" = List.Combine(#"Get values"),
        #"Converted to Table" = Table.FromList(#"Get Lists", Splitter.SplitByNothing(), type table[Records to Expand=Record.Type], null, ExtraValues.Error)
    in
        #"Converted to Table",

 

To use this call the following data source credentials are required for "https://######.atlassian.net/rest/api/3/"

DarylLynchBzy_2-1674031496068.png

 

Daryl-Lynch-Bzy
Resident Rockstar
Resident Rockstar

Hi @Spartan - could you please try the following options:

1. use this code:

= Web.Contents(
    "https://www.devstack.vwgroup.com/jira/secure/BOARDNAMEHERE",
    [ 
      Query=[ #"filter"="", #"orderBy"=""],
      Headers=[#"APIToken" = "APIKEYHERE"] 
    ]
)

 

2. Remove the API token from the Web.Contents altogether, so that it is included in the Data Source Connection as Web Api.

 

Out of interest, are you connecting to JIRA?  Your url includes JIRA but it does follow the normal convention.  I have used something like (https://xxxx.atlassian.com/).  When I use "Basic" authentication provide the Username and APIToken provide by JIRA.

 

Hi @Daryl-Lynch-Bzy,

thanks for the reply. 

 

Unfortunately when I try the above method I still get an Error: 

Spartan_0-1674029013178.png


But if you say that you have already achieved to connect to JIRA boards (without the connector from the marketplace) then I am very interested in how you did that!

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

Top Solution Authors
Top Kudoed Authors