0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Tailor PlatformにNode.js+connectrpcでAPIアクセスする備忘

Last updated at Posted at 2025-11-12

BSRに公開されているSDKをpnpmでインストール

$ pnpm config set @buf:registry https://buf.build/gen/npm/v1/
$ pnpm add @buf/tailor-inc_tailor.bufbuild_es@2.10.0-20251015043835-ab63191facd7.1

まずはpingにリクエストしてみる

import { createClient } from "@connectrpc/connect";
import { createConnectTransport } from "@connectrpc/connect-node";
import * as Tailor from "@buf/tailor-inc_tailor.bufbuild_es/tailor/v1/service_pb";

const transport = createConnectTransport({
  baseUrl: "https://api.tailor.tech",
  httpVersion: "2",
});

const client = createClient(Tailor.OperatorService, transport);

const r = await client.ping({});

console.log(r);

動いた

{ '$typeName': 'tailor.v1.PingResponse' }

認証

ワークスペースの取得やアプリケーションの作成などでは認証が必要になる

事前に tailorctl auth pat でPATを作っておき、それをトランスポートの作成部分でBearer Tokenとしてセットする

const transport = createConnectTransport({
  baseUrl: "https://api.tailor.tech",
  httpVersion: "2",
  interceptors: [
    (next) => async (req) => {
      req.header.set(
        "Authorization",
        "Bearer tpp_hogehogepiyopiyo" // <- ここでトークンをセット
      );
      return await next(req);
    },
  ],
});
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?