在 Shippo 批处理流程中,您如何获取每批货物的跟踪号?

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

我已使用 shippo 端点 const batch = shippo.batch.create({...})shippo.batch.purchase(batch.object_id) 成功创建并购买了批量货件。现在我需要知道是否可以检索该批次中每批货件的运单号?我检查了 batch_shipments.results 并没有看到任何东西。我还尝试使用 batch_shipments.results.object_id 分别检索每笔交易,它告诉我找不到该项目。这可能吗?我可以登录到仪表板,然后看到那里列出了 tracking#。所以我认为这也可以通过 API 获得。

使用 Batch Purchase API 购买货件后,您需要 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

响应 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
    }

您可以通过 shippo.transactions.list(..)shippo.transactions.retrive(transactionObjectId)

致电 'transactions' API 来接收跟踪号码
GET /transactions/ HTTP/1.1
Host: api.goshippo.com
Authorization: ShippoToken token
Content-Type: application/json
Shippo-API-Version: 2018-02-08

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

这将 return 您的追踪号码

{
    "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
}