Searching

Search Results

## Stream responses As of version 1.11.0, the search function returns a node stream in object mode if no callback is provided.
  1. Node.js
const stream = require("stream");
const writableStream = stream.Writable({ objectMode: true });
writableStream._write = (chunk, enc, next) => {
    // ...
    next();
};
const customerStream = gateway.customer.search((search) => {
    search.company().is("Acme Inc.");
});
customerStream.pipe(writableStream);
  1. Node.js
const customerStream = gateway.customer.search((search) => {
    search.company().is("Acme Inc.");
});
customerStream.on("data", (customer) => {
    // ...
});
customerStream.on("end", () => {
    // ...
});
customerStream.resume();

Iterable responsesAnchorIcon

If a callback is provided to the search function, an object with the each method defined is yielded.
  1. Node.js
gateway.customer.search((search) => {
    search.company().is("Acme Inc.");
}, (err, response) => {
    response.each((err, customer) => {
        // ...
    });
});

Race conditionsAnchorIcon

To optimize the processing of large searches, data is retrieved from the server lazily. Initially, the server returns a list of ids that matched the search criteria. While you're iterating over search results, the data for each record is fetched dynamically. This causes race conditions to exist when records are modified on the server while you are iterating over them.

Records are deletedAnchorIcon

If a record is deleted server-side while you are iterating over the results, that record is skipped.

Records are updatedAnchorIcon

If a record is updated server-side while you are iterating over the results, one of two things could happen:
  • the record still matches the search criteria and the modified record is returned
  • the record no longer matches the search criteria and is skipped

Maximum sizeAnchorIcon

Because of the race conditions described above, you can't know how many search results you have while iterating over them. You do, however, know the maximum number of results that will be given.
  1. Node.js
const customerStream = gateway.customer.search((search) => {
    search.company().is("Acme Inc.");
});
customerStream.on("ready", () => {
    customerStream.searchResponse.length();
});

Search limitAnchorIcon

Transaction searches return a maximum of 50,000 results; all other searches return a maximum of 10,000 results.

If you accept cookies, we’ll use them to improve and customize your experience and enable our partners to show you personalized PayPal ads when you visit other sites. Manage cookies and learn more