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

PayPal: Find disputes awaiting a seller response

See more PayPal Examples

Scan cases updated in the past 30 days and page through the results. Show each case waiting on the seller and its response deadline when PayPal includes one in the summary.

PayPal documentation

Chilkat B4X Downloads

B4X
Dim success As Boolean = 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.
Dim http As ChilkatHttp
http.Initialize("http")
http.AuthToken = "SANDBOX_ACCESS_TOKEN"
Dim resp As ChilkatHttpResponse
resp.Initialize
Dim since As ChilkatDateTime
since.Initialize
since.SetFromCurrentSystemTime
since.AddDays(-30)
Dim query As ChilkatJsonObject
query.Initialize
query.UpdateString("update_time_after", since.GetAsTimestamp(False))
query.UpdateInt("page_size", 50)
Dim page As Int = 1
Dim more As Boolean = True
Do While (more = True)
    query.UpdateInt("page", page)
    success = http.HttpParams("GET", "https://api-m.sandbox.paypal.com/v1/customer/disputes", query, resp)
    If success <> True Then
        Log("No HTTP response: " & http.LastErrorText)
        Return
    End If

    If (resp.StatusCode < 200) Or (resp.StatusCode >= 300) Then
        Dim errorInfo As ChilkatJsonObject
        errorInfo.Initialize
        errorInfo.Load(resp.BodyStr)
        Log("HTTP " & resp.StatusCode & " " & errorInfo.StringOf("name") & " " & errorInfo.StringOf("details[0].issue"))
        Log("PayPal debug ID: " & errorInfo.StringOf("debug_id"))
        Return
    End If

    Dim result As ChilkatJsonObject
    result.Initialize
    Dim parsedResult As Boolean = result.Load(resp.BodyStr)
    If parsedResult <> True Then
        Log("Expected a JSON response; HTTP " & resp.StatusCode)
        Return
    End If

    Dim i As Int = 0
    Do While (i < result.SizeOfArray("items"))
        result.I = i
        If result.StringOfEquals("items[i].status", "WAITING_FOR_SELLER_RESPONSE", True) = True Then
            Log(result.StringOf("items[i].dispute_id") & "  " & result.StringOf("items[i].reason"))
            If result.HasMember("items[i].seller_response_due_date") = True Then
                Log("Respond by " & result.StringOf("items[i].seller_response_due_date"))
            End If

        End If

        i = i + 1
    Loop
    Dim hasNext As Boolean = False
    Dim linkIndex As Int = 0
    Do While (linkIndex < result.SizeOfArray("links"))
        result.I = linkIndex
        If result.StringOfEquals("links[i].rel", "next", True) = True Then
            hasNext = True
        End If

        linkIndex = linkIndex + 1
    Loop
    more = hasNext
    page = page + 1
Loop