shippo

How do you get the tracking number for each shipment in a Shippo batch process?


I have successfully created and purchased a batch shipment using the shippo endpoints const batch = shippo.batch.create({...}) and shippo.batch.purchase(batch.object_id). Now I need to know if I can retrieve the tracking number for each shipment in the batch? I have checked the batch_shipments.results and don't see anything there. I have also tried retrieving each transaction separately using the batch_shipments.results.object_id and it tells me that the item is not found. Is this possible? I can log in to the dashboard and I see the tracking# listed there. So I would think this would be available via the API as well.


Solution

  • Once you purchase shipments using Batch Purchase API, you need to Retrieve Batch Status

    GET /batches/{batchObjectId} HTTP/1.1
    Host: api.goshippo.com
    Content-Type: application/json
    Authorization: ShippoToken token
    Shippo-API-Version: 2018-02-08
    

    the response returns transactionObjectId

       {
            "object_id": "batchObjectId",
            "object_owner": "your.email@gmail.com",
            "status": "PURCHASED",
            "object_created": "2022-05-10T04:43:28.594Z",
            "object_updated": "2022-05-10T04:44:28.469Z",
            "metadata": "BATCH #170",
            "default_carrier_account": "carrierObjectId",
            "default_servicelevel_token": "usps_priority",
            "label_filetype": "PDF_4x6",
            "batch_shipments": {
                "count": 1,
                "next": null,
                "previous": null,
                "results": [
                    {
                        "metadata": "",
                        "carrier_account": "carrier
    AccountObjectId",
                        "servicelevel_token": "usps_priority",
                        "shipment": "shipmentObjectId",
                        "transaction": "transactionObjectId",
                        "object_id": "resultObjectId",
                        "status": "VALID",
                        "messages": []
                    }
                ]
            },
            "object_results": {
                "purchase_succeeded": 1,
                "purchase_failed": 0,
                "creation_failed": 0,
                "creation_succeeded": 1
            },
            "label_url": [
                "LABEL URL"
            ],
            "test": false
        }
    

    You can receive the tracking number by either calling 'transactions' API via shippo.transactions.list(..) or shippo.transactions.retrive(transactionObjectId)

    GET /transactions/ HTTP/1.1
    Host: api.goshippo.com
    Authorization: ShippoToken token
    Content-Type: application/json
    Shippo-API-Version: 2018-02-08
    

    or

    GET /transactions/{transactionObjectId} HTTP/1.1
    Host: api.goshippo.com
    Authorization: ShippoToken token
    Content-Type: application/json
    Shippo-API-Version: 2018-02-08
    

    which will return your tracking number

    {
        "object_state": "VALID",
        "status": "SUCCESS",
        "object_created": "2022-05-10T04:44:22.562Z",
        "object_updated": "2022-05-10T04:44:24.313Z",
        "object_id": "objectId",
        "object_owner": "your.email@gmail.com",
        "test": false,
        "rate": "rateObjectId",
        "tracking_number": "9205590175547700060",
        "tracking_status": "UNKNOWN",
        "eta": null,
        "tracking_url_provider": "https://tools.usps.com/go/TrackConfirmAction_input?origTrackNum=9205590175547700060",
        "label_url": "https://deliver.goshippo.com/1a67e21f40fb947.pdf?Expires=1683863&Signature=CFUGbQN5O7eo0lQ__&Key-Pair-Id=APKAJR",
        "commercial_invoice_url": null,
        "messages": [],
        "order": null,
        "metadata": "",
        "parcel": "parcelObjectId",
        "billing": {
            "payments": []
        },
        "qr_code_url": null
    }