Forum

Paypal transaction ...
 
Notifications
Clear all

Paypal transaction list via PQ API call

3 Posts
2 Users
0 Reactions
187 Views
(@jareksv)
Posts: 2
New Member
Topic starter
 

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]

 
Posted : 22/02/2024 11:54 am
Philip Treacy
(@philipt)
Posts: 1632
Member Admin
 

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

 
Posted : 23/02/2024 2:11 am
(@jareksv)
Posts: 2
New Member
Topic starter
 

Many thanks, works:-)

 
Posted : 08/03/2024 11:20 am
Share: