Sample code for 30+ languages & platforms
AutoIt Requires Chilkat v11.0.0+

PayPal: Page through merchant transactions

See more PayPal Examples

Read yesterday-to-now account activity one page at a time. Enable Transaction Search for the REST app and obtain a token with reporting access. Data can lag by up to three hours; use order or capture lookup for a checkout in progress.

PayPal documentation

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

;  See Unlock Chilkat before making requests.
;  For the merchant's internal backoffice application. Load the sandbox token
;  from the merchant's credential store. Keep it out of publicly distributed apps.
;  See Get a PayPal access token.
$oHttp = ObjCreate("Chilkat.Http")
$oHttp.AuthToken = "SANDBOX_ACCESS_TOKEN"
$oResp = ObjCreate("Chilkat.HttpResponse")
;  Use the UTC window containing the transaction (at most 31 days per request).
$oDt = ObjCreate("Chilkat.CkDateTime")
$oDt.SetFromCurrentSystemTime()
$oQuery = ObjCreate("Chilkat.JsonObject")
$oQuery.UpdateString("end_date",$oDt.GetAsTimestamp(False))
$oDt.AddDays(-1)
$oQuery.UpdateString("start_date",$oDt.GetAsTimestamp(False))
$oQuery.UpdateString("fields","transaction_info")
$oQuery.UpdateInt("page_size",100)
Local $iPage = 1
Local $iLastPage = 1
While ($iPage <= $iLastPage)
    $oQuery.UpdateInt("page",$iPage)
    $bSuccess = $oHttp.HttpParams("GET","https://api-m.sandbox.paypal.com/v1/reporting/transactions",$oQuery,$oResp)
    If ($bSuccess <> True) Then
        ConsoleWrite("No HTTP response: " & $oHttp.LastErrorText & @CRLF)
        Exit
    EndIf

    If (($oResp.StatusCode < 200) Or ($oResp.StatusCode >= 300)) Then
        $oErrorInfo = ObjCreate("Chilkat.JsonObject")
        $oErrorInfo.Load($oResp.BodyStr)
        ConsoleWrite("HTTP " & $oResp.StatusCode & " " & $oErrorInfo.StringOf("name") & " " & $oErrorInfo.StringOf("details[0].issue") & @CRLF)
        ConsoleWrite("PayPal debug ID: " & $oErrorInfo.StringOf("debug_id") & @CRLF)
        Exit
    EndIf

    $oResult = ObjCreate("Chilkat.JsonObject")
Local $bParsed = $oResult.Load($oResp.BodyStr)
    If ($bParsed <> True) Then
        ConsoleWrite("Expected a JSON response; HTTP " & $oResp.StatusCode & @CRLF)
        Exit
    EndIf

Local $i = 0
Local $iCount = $oResult.SizeOfArray("transaction_details")
    While ($i < $iCount)
        $oResult.I = $i
        ConsoleWrite($oResult.StringOf("transaction_details[i].transaction_info.transaction_id") & "  " & $oResult.StringOf("transaction_details[i].transaction_info.transaction_event_code") _
             & "  " & $oResult.StringOf("transaction_details[i].transaction_info.transaction_status") & @CRLF)
        ConsoleWrite("  " & $oResult.StringOf("transaction_details[i].transaction_info.transaction_amount.value") & " " & $oResult.StringOf("transaction_details[i].transaction_info.transaction_amount.currency_code") & @CRLF)
        $i = $i + 1
    Wend
    $iLastPage = $oResult.IntOf("total_pages")
    $iPage = $iPage + 1
Wend