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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Anonymous
Not applicable

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 @Anonymous - 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 @Anonymous - 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 @Anonymous - 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.

 

Anonymous
Not applicable

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
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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