快速开始

快速开始

五个请求,从空账户一路走到带有公开链接的已发布护照。

  1. 1.创建 API 密钥

    密钥在设置中创建。密钥只在创建的那一刻完整显示一次,之后仅保留其标识符可见。

    只授予集成真正需要的作用域。一把能读取护照却不能发布的密钥,绝不会意外把整份目录推上线。

    在设置中打开 API 密钥
    shell
    export PASSPORTCRAFT_API_KEY=pc_sk_test_…
  2. 2.检查凭据

    最值得先发出的一个调用。它确认密钥可用,说明这是正式凭据还是测试凭据,并列出它可代为操作的组织,其中就包含后续每个请求都需要的组织 ID。

    请求
    curl "https://passportcraft.com/api/v1/whoami" \
      -H "Authorization: Bearer $PASSPORTCRAFT_API_KEY"
    响应
    {
      "object": "credential",
      "key_id": "K3n9Qw2P",
      "livemode": true,
      "owner_organization_id": "8f14e45f-ceea-467a-9a5f-8dc7d9c6a1b2",
      "expires_at": null,
      "last_used_at": "2026-08-02T07:41:03.220Z",
      "organizations": [
        {
          "organization_id": "8f14e45f-ceea-467a-9a5f-8dc7d9c6a1b2",
          "scopes": [
            "passports:read",
            "passports:write",
            "units:read",
            "units:write"
          ],
          "granted_at": "2026-07-14T11:02:19.004Z"
        }
      ]
    }
    查看该端点的完整参考
  3. 3.创建护照

    护照创建后即为草稿。只有类别是必填项;其余字段可以随后逐项填写,与在编辑器中完全一致。

    请求
    curl "https://passportcraft.com/api/v1/organizations/8f14e45f-ceea-467a-9a5f-8dc7d9c6a1b2/passports" \
      -X POST \
      -H "Authorization: Bearer $PASSPORTCRAFT_API_KEY" \
      -H "Idempotency-Key: $(uuidgen)" \
      -H "Content-Type: application/json" \
      -d '{
      "category": "textile",
      "external_id": "SKU-4471-BLK",
      "data": {
        "product_name": "Merino Crew Neck",
        "product_description": "Mid-weight knitted crew neck in 100% merino wool.",
        "manufacturer_name": "Atelier Kestrel SAS",
        "manufacturer_address": "14 rue des Tanneurs, 59100 Roubaix",
        "manufacturer_country": "FR"
      }
    }'
    响应
    {
      "object": "passport",
      "id": "2c1f9e07-3b4d-4a18-9f6c-5e0a7b8d3c41",
      "name": "organizations/8f14e45f-ceea-467a-9a5f-8dc7d9c6a1b2/passports/2c1f9e07-3b4d-4a18-9f6c-5e0a7b8d3c41",
      "organization_id": "8f14e45f-ceea-467a-9a5f-8dc7d9c6a1b2",
      "category": "textile",
      "status": "draft",
      "gtin": null,
      "serial_number": null,
      "external_id": "SKU-4471-BLK",
      "version": 1,
      "livemode": true,
      "registry_id": null,
      "created_at": "2026-08-01T09:12:44.918Z",
      "updated_at": "2026-08-01T09:12:44.918Z",
      "published_at": null,
      "trashed_at": null,
      "data": {
        "product_name": "Merino Crew Neck",
        "product_description": "Mid-weight knitted crew neck in 100% merino wool.",
        "manufacturer_name": "Atelier Kestrel SAS",
        "manufacturer_address": "14 rue des Tanneurs, 59100 Roubaix",
        "manufacturer_country": "FR",
        "material_composition": [
          {
            "fiber": "Merino wool",
            "percentage": 100
          }
        ],
        "substances_of_concern": [
          {
            "name": "None declared",
            "present": false
          }
        ]
      }
    }
    查看该端点的完整参考
  4. 4.发布前先校验

    校验不写入任何数据。它会指出哪些问题会阻止发布、哪些只是提示,让集成在真正关键的那次调用之前就知道结果。

    请求
    curl "https://passportcraft.com/api/v1/organizations/8f14e45f-ceea-467a-9a5f-8dc7d9c6a1b2/passports/2c1f9e07-3b4d-4a18-9f6c-5e0a7b8d3c41/validate" \
      -X POST \
      -H "Authorization: Bearer $PASSPORTCRAFT_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
      "data": {
        "material_composition": null
      }
    }'
    响应
    {
      "object": "validation",
      "id": "2c1f9e07-3b4d-4a18-9f6c-5e0a7b8d3c41",
      "name": "organizations/8f14e45f-ceea-467a-9a5f-8dc7d9c6a1b2/passports/2c1f9e07-3b4d-4a18-9f6c-5e0a7b8d3c41/validation",
      "organization_id": "8f14e45f-ceea-467a-9a5f-8dc7d9c6a1b2",
      "passport_id": "2c1f9e07-3b4d-4a18-9f6c-5e0a7b8d3c41",
      "category": "textile",
      "schema_version": "1.0.0-draft",
      "dry_run": true,
      "valid": false,
      "publishable": false,
      "error_count": 2,
      "warning_count": 0,
      "checked_at": "2026-08-02T08:26:11.409Z",
      "issues": [
        {
          "object": "validation_issue",
          "field": "material_composition",
          "source": {
            "pointer": "/data/material_composition"
          },
          "rule": "required",
          "severity": "error",
          "message": "Material Composition is required",
          "message_key": "required",
          "message_params": {
            "field": "Material Composition"
          },
          "writable_via_api": true
        },
        {
          "object": "validation_issue",
          "field": "gtin",
          "source": {
            "pointer": "/data/gtin"
          },
          "rule": "required",
          "severity": "error",
          "message": "A GTIN is required before this passport can be published.",
          "writable_via_api": true
        }
      ]
    }
    查看该端点的完整参考
  5. 5.发布护照

    发布后,任何扫码的人都能读到这份护照。若缺少必填字段、缺少 GTIN,或套餐已无可用的发布名额,调用将被拒绝。

    请求
    curl "https://passportcraft.com/api/v1/organizations/8f14e45f-ceea-467a-9a5f-8dc7d9c6a1b2/passports/2c1f9e07-3b4d-4a18-9f6c-5e0a7b8d3c41/publish" \
      -X POST \
      -H "Authorization: Bearer $PASSPORTCRAFT_API_KEY" \
      -H "Idempotency-Key: $(uuidgen)"
    响应
    {
      "object": "passport",
      "id": "2c1f9e07-3b4d-4a18-9f6c-5e0a7b8d3c41",
      "name": "organizations/8f14e45f-ceea-467a-9a5f-8dc7d9c6a1b2/passports/2c1f9e07-3b4d-4a18-9f6c-5e0a7b8d3c41",
      "organization_id": "8f14e45f-ceea-467a-9a5f-8dc7d9c6a1b2",
      "category": "textile",
      "status": "published",
      "gtin": "03453120000011",
      "serial_number": null,
      "external_id": "SKU-4471-BLK",
      "version": 4,
      "livemode": true,
      "registry_id": null,
      "created_at": "2026-08-01T09:12:44.918Z",
      "updated_at": "2026-08-01T14:03:22.501Z",
      "published_at": "2026-08-01T14:03:22.501Z",
      "trashed_at": null,
      "data": {
        "product_name": "Merino Crew Neck",
        "product_description": "Mid-weight knitted crew neck in 100% merino wool.",
        "manufacturer_name": "Atelier Kestrel SAS",
        "manufacturer_address": "14 rue des Tanneurs, 59100 Roubaix",
        "manufacturer_country": "FR",
        "material_composition": [
          {
            "fiber": "Merino wool",
            "percentage": 100
          }
        ],
        "substances_of_concern": [
          {
            "name": "None declared",
            "present": false
          }
        ],
        "gtin": "03453120000011"
      },
      "warnings": [
        {
          "code": "environmental_claim_detected",
          "message": "This passport contains environmental claim language (carbon neutral). From 27 September 2026, Directive (EU) 2024/825 requires the trader placing the product on the market to hold substantiation for such claims. Publishing succeeded; confirm the substantiation exists.",
          "doc_url": "https://passportcraft.com/docs/api/errors#environmental_claim_detected"
        }
      ]
    }
    查看该端点的完整参考
  6. 6.取回公开链接

    返回公开页面、GS1 Digital Link,以及印刷二维码所编码的确切目标地址,也就是交给标签印制方的那个值。

    请求
    curl "https://passportcraft.com/api/v1/organizations/8f14e45f-ceea-467a-9a5f-8dc7d9c6a1b2/passports/2c1f9e07-3b4d-4a18-9f6c-5e0a7b8d3c41/links" \
      -H "Authorization: Bearer $PASSPORTCRAFT_API_KEY"
    响应
    {
      "object": "passport_links",
      "id": "2c1f9e07-3b4d-4a18-9f6c-5e0a7b8d3c41",
      "name": "organizations/8f14e45f-ceea-467a-9a5f-8dc7d9c6a1b2/passports/2c1f9e07-3b4d-4a18-9f6c-5e0a7b8d3c41/links",
      "organization_id": "8f14e45f-ceea-467a-9a5f-8dc7d9c6a1b2",
      "passport": "organizations/8f14e45f-ceea-467a-9a5f-8dc7d9c6a1b2/passports/2c1f9e07-3b4d-4a18-9f6c-5e0a7b8d3c41",
      "status": "published",
      "livemode": true,
      "gtin": "03453120000011",
      "serial_number": null,
      "public_url": "https://passportcraft.com/passport/2c1f9e07-3b4d-4a18-9f6c-5e0a7b8d3c41",
      "qr_target": "https://passportcraft.com/01/03453120000011",
      "gs1_digital_link": {
        "uri": "https://passportcraft.com/01/03453120000011",
        "gtin14": "03453120000011",
        "serial": null,
        "linkset_url": "https://passportcraft.com/01/03453120000011?linkType=linkset",
        "unavailable_reason": null
      },
      "resolves_publicly": true,
      "not_resolvable_reason": null
    }
    查看该端点的完整参考

接下来读什么

  • 通用约定重试、分页与条件写入。
  • 错误调用被拒绝时应当据以分支的错误码。
  • 兼容性哪些内容可以不经通知就变更,哪些不可以。
PassportCraft API 快速开始 | PassportCraft