smartystreets / smartystreets-python-sdk

The official client libraries for accessing SmartyStreets APIs from Python 2.7 and 3.5
https://smartystreets.com/docs/sdk/python
Apache License 2.0
28 stars 30 forks source link

Returned 'input_id' for invalid address during batch? #14

Closed dweissinger closed 4 years ago

dweissinger commented 4 years ago

https://github.com/smartystreets/smartystreets-python-sdk/blob/e666821faee1af9fdba6683f2309edbf6d1925e9/examples/us_street_multiple_addresses_example.py#L58

I greatly appreciate the us_street_multiple_addresses_example.py example you supplied, but have a question: Is it possible to return the input_id regardless of valid or invalid status? I'd like to flag the source data that an attempt was made, but manual intervention is needed. I'm essentially wanting to do this:

I guess I could store a list of the input_ids submitted during a batch, then remove the validated input_ids and flag the remainder as invalid. It would just be so nice if the invalid address still returned the input_id.

Y'all are making it hard for me to be lazy...unless I just missed something...thus this ticket.

mdwhatcott commented 4 years ago

The input_id is already a field on the lookup, so you should already have access to it when there are no candidates (zero-length results) on a lookup. Here are a few slightly modified snippets of that sample for illustration purposes:

    # when adding to the batch, make sure you specify the input_id:
    batch.add(StreetLookup("123 Bogus Street, Pretend Lake, Oklahoma"))
    batch[2].input_id = "hello, world!"

...

        # later, when inspecting the lookup for candidates in lookup.result:
        if len(lookup.result) == 0:
            print("Address {0} is invalid (input_id: [{1}]).\n".format(i, lookup.input_id))
            # output: Address 2 is invalid (input_id: [hello, world!]).
            continue

Does knowing that enable sufficient laziness? ;)

dweissinger commented 4 years ago

Laziness now resuming. Thank you! This is exactly what I needed.