Techioz Blog

Xero API に接続して請求書を作成しようとしていますが、次のエラーが発生します。

概要

Xero API を使用して請求書を取得しようとすると、.get_invoices(’’).invoices でエラーが発生します。

以下のエラーを参照してください。

*** XeroRuby::ApiError Exception: Error message: the server returns an error

HTTP status code: 403

Response headers: {"content-length"=>"0", "server"=>"nginx", "xero-correlation-id"=>"c605f5e5-81e7-4763-ae07-093e7cb6f949", "x-appminlimit-remaining"=>"9998", "expires"=>"Thu, 02 Feb 2023 16:45:04 GMT", "cache-control"=>"max-age=0, no-cache, no-store", "pragma"=>"no-cache", "date"=>"Thu, 02 Feb 2023 16:45:04 GMT", "connection"=>"keep-alive", "x-client-tls-ver"=>"tls1.3"}

Response body:

インデックスコントローラー


require 'xero-ruby'

    creds = {
      client_id: '...',
      client_secret: '...',
      grant_type: 'client_credentials'
    }

    xero_client = XeroRuby::ApiClient.new(credentials: creds)

    @token_set = xero_client.get_client_credentials_token

    byebug

    @invoices = xero_client.accounting_api.get_invoices('').invoices

解決策

お電話の際にテナント ID をご確認いただけますか。あなたが言及した相関 ID の Xero ログを見ると、テナント ID は「page=1-100」として送信されています。