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
mariewo
Regular Visitor

API connection to App Store

Hi, I'm trying to connect to our appstore account to retreive stats on app downloads.  

The power query M code I've been trying is based on the API specification file downloadable from here and also I used took some guidance from the end of this article about JSON code here 

...The M code I'm using at the moment is below, I'm getting an error message in Power Query saying 'Please specify how to connect [Edit credentials]'. Do I need to specify the connection this in the M code, if so I'm not sure how to do this?!... I'm new to using private key type APIs like this so hoping someone can advise where I'm going wrong please 🙏

 

let
Source =
Web.Contents(
"https://api.appstoreconnect.apple.com/",
[
RelativePath = "v1/salesReports",
Query=
[
key_id ="###ourkeyid###"
,issuer_id ="###ourissuerid###"
,key="-----BEGIN PRIVATE KEY-----\n###ourkey###\n-----END PRIVATE KEY-----"
//,duration= 1200, // optional (maximum 1200)
//,in_house= false // optional but may be required if using match/sigh,
]
]
)
in
Source

 

 

1 ACCEPTED SOLUTION
v-junyant-msft
Community Support
Community Support

Hi @mariewo ,

Given the nature of the error message you're receiving in Power Query, it appears that Power Query is prompting you to specify how to connect because it doesn't automatically recognize the authentication method required by the API you're trying to access. In cases involving APIs that require private key authentication, you typically need to handle the authentication process programmatically within your M code, which involves generating a token based on your private key and other credentials, and then passing this token as part of your API request headers.
However, the M code snippet you've shared seems to attempt to include the private key directly in the query parameters, which is not the standard method for APIs requiring private key authentication. Instead, you would generally need to:
1. Generate a JWT (JSON Web Token) using your private key and other necessary credentials.
2. Use this JWT to request an access token from the API's authentication endpoint.
3. Include the access token in the header of your API requests.

For a general understanding of handling API connections in Power Query M, you can refer to the documentation on Web.Contents function:
Web.Contents - PowerQuery M | Microsoft Learn
Web.Headers - PowerQuery M | Microsoft Learn
www.dalesandro.net

vjunyantmsft_0-1709799105491.png

Here I have helped you find some of the correct ways to write it:
Solved: Connecting API - Microsoft Fabric Community
Solved: Connecting to API - Page 2 - Microsoft Fabric Community

Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-junyant-msft
Community Support
Community Support

Hi @mariewo ,

Given the nature of the error message you're receiving in Power Query, it appears that Power Query is prompting you to specify how to connect because it doesn't automatically recognize the authentication method required by the API you're trying to access. In cases involving APIs that require private key authentication, you typically need to handle the authentication process programmatically within your M code, which involves generating a token based on your private key and other credentials, and then passing this token as part of your API request headers.
However, the M code snippet you've shared seems to attempt to include the private key directly in the query parameters, which is not the standard method for APIs requiring private key authentication. Instead, you would generally need to:
1. Generate a JWT (JSON Web Token) using your private key and other necessary credentials.
2. Use this JWT to request an access token from the API's authentication endpoint.
3. Include the access token in the header of your API requests.

For a general understanding of handling API connections in Power Query M, you can refer to the documentation on Web.Contents function:
Web.Contents - PowerQuery M | Microsoft Learn
Web.Headers - PowerQuery M | Microsoft Learn
www.dalesandro.net

vjunyantmsft_0-1709799105491.png

Here I have helped you find some of the correct ways to write it:
Solved: Connecting API - Microsoft Fabric Community
Solved: Connecting to API - Page 2 - Microsoft Fabric Community

Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.