New Member
August 26, 2022
Hello, I'm followed this artickle as much I could but no success Connecting to an OAuth API Like PayPal With Power Query .
Could someone tell me where is my error please?
Is this corect please?
let
api_url = "https://api.paypal.com/",
token_path = "v1/oauth2/token",
ClientID = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
Secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
EncodedCredentials = "Basic " & Binary.ToText(Text.ToBinary(ClientID & ":" & Secret), BinaryEncoding.Base64),
Token_Response = Json.Document(Web.Contents(api_url,
[
RelativePath = token_path,
Headers = [#"Content-Path"="aplication/x-www-form-urlencoded",#"Authorization"=EncodedCredentials],
Content=Text.ToBinary("grant_type=client_credetials")
]
)
),
transaction_details = data[transaction_details]
October 5, 2010
Hi Jaroslav,
That code isn't making any query for data. The code you have pasted gets the authorization token from Paypal. You then need to use that token to make an authorized query to get the data you want.
In the example workbook form my post, the code looks like this
let
// Get the API Token
api_url = "https://api.paypal.com/",
token_path = "v1/oauth2/token",
ClientID = "xxxxxxxx",
Secret = "xxxxxxxx",
EncodedCredentials = "Basic " & Binary.ToText(Text.ToBinary(ClientID & ":" & Secret), BinaryEncoding.Base64),
Token_Response = Json.Document(Web.Contents(api_url,
[
RelativePath = token_path,
Headers = [#"Content-Type"="application/x-www-form-urlencoded",#"Authorization"=EncodedCredentials],
Content=Text.ToBinary("grant_type=client_credentials")
]
)
),
// Get the token from the API response
token = Token_Response[access_token],
// Query the API for Transactions between startDate and endDate and return all fields
path = "v1/reporting/transactions",
endDate = "2020-05-30T00:00:00-0700",
startDate= "2020-05-01T23:59:59-0700",
fields = "all",
data= Json.Document(Web.Contents(api_url,
[
RelativePath = path,
Query = [end_date=endDate, start_date=startDate, fields=fields],
Headers = [#"Authorization"="Bearer "&token,#"Content-Type"="application/json"]
]
)
),
transaction_details = data[transaction_details]
So once the token is returned from Paypal, you need to get it
// Get the token from the API response
token = Token_Response[access_token],
then query Paypal for the data
// Query the API for Transactions between startDate and endDate and return all fields
path = "v1/reporting/transactions",
endDate = "2020-05-30T00:00:00-0700",
startDate= "2020-05-01T23:59:59-0700",
fields = "all",
data= Json.Document(Web.Contents(api_url,
[
RelativePath = path,
Query = [end_date=endDate, start_date=startDate, fields=fields],
Headers = [#"Authorization"="Bearer "&token,#"Content-Type"="application/json"]
]
)
),
Regards
Phil
Answers Post
1 Guest(s)