Go Requires Chilkat v11.0.0+
Go
PayPal: Find invoices for a recipient
See more PayPal Examples
Filter by a sandbox recipient email address in the JSON body. Pagination belongs in the URL. Read every matching invoice ID; several invoices can share the same recipient.
Chilkat Go Downloads
success := 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.
http := chilkat.NewHttp()
http.SetAuthToken("SANDBOX_ACCESS_TOKEN")
resp := chilkat.NewHttpResponse()
// Use a JSON search body on every page; the recipient email does not belong in the
// URL.
body := chilkat.NewJsonObject()
body.UpdateString("recipient_email","buyer@example.com")
page := 1
lastPage := 1
for (page <= lastPage) {
url := chilkat.NewStringBuilder()
url.Append("https://api-m.sandbox.paypal.com/v2/invoicing/search-invoices?total_required=true&page_size=20&page=")
url.AppendInt(page)
success = http.HttpJson("POST",*url.GetAsString(),body,"application/json",resp)
if success != true {
fmt.Println("No HTTP response: ", http.LastErrorText())
http.DisposeHttp()
resp.DisposeHttpResponse()
body.DisposeJsonObject()
url.DisposeStringBuilder()
return
}
if (resp.StatusCode() < 200) || (resp.StatusCode() >= 300) {
errorInfo := chilkat.NewJsonObject()
errorInfo.Load(resp.BodyStr())
fmt.Println("HTTP ", resp.StatusCode(), " ", *errorInfo.StringOf("name"), " ", *errorInfo.StringOf("details[0].issue"))
fmt.Println("PayPal debug ID: ", *errorInfo.StringOf("debug_id"))
http.DisposeHttp()
resp.DisposeHttpResponse()
body.DisposeJsonObject()
url.DisposeStringBuilder()
errorInfo.DisposeJsonObject()
return
}
result := chilkat.NewJsonObject()
parsed := result.Load(resp.BodyStr())
if parsed != true {
fmt.Println("Expected a JSON response; HTTP ", resp.StatusCode())
http.DisposeHttp()
resp.DisposeHttpResponse()
body.DisposeJsonObject()
url.DisposeStringBuilder()
errorInfo.DisposeJsonObject()
result.DisposeJsonObject()
return
}
i := 0
count := result.SizeOfArray("items")
for (i < count) {
result.SetI(i)
fmt.Println(*result.StringOf("items[i].id"), " ", *result.StringOf("items[i].detail.invoice_number"), " ", *result.StringOf("items[i].status"))
i = i + 1
}
lastPage = result.IntOf("total_pages")
page = page + 1
}
http.DisposeHttp()
resp.DisposeHttpResponse()
body.DisposeJsonObject()
url.DisposeStringBuilder()
errorInfo.DisposeJsonObject()
result.DisposeJsonObject()