builder icon indicating copy to clipboard operation
builder copied to clipboard

Admin SDK not connecting–"Private Key is required"

Open davidrhoderick opened this issue 2 years ago • 1 comments

Describe the bug When I try to initialize the Admin SDK and run a basic query that works in the GraphQL explorer, with the same private key used there, I get an error that "Private Key is required". I've tried using an env var as well as hard-coding the private key and neither work. I've also tried initializing the Admin SDK inside a Next.js getStaticProps function and outside (like how the Builder instance is instantiated).

To Reproduce Steps to reproduce the behavior (follow the tutorial but here's what I did):

  1. Install the admin SDK with npm install --save @builder.io/admin-sdk
  2. Import it with import { createAdminApiClient } from '@builder.io/admin-sdk';.
  3. Instantiate it with const adminSdk = createAdminApiClient(process.env.BUILDERIO_PRIVATE_API_KEY);, either in getStaticPaths or outside of it. confirm that the BUILDERIO_PRIVATE_API_KEY env var is defined (or hard code your private API key from your space that works with the GraphQL explorer).
  4. Try a simple query that works in the GraphQL explorer such as the following:
const res = await adminSdk.query({
    models: {
      name: true
    }
  });

Expected behavior It should work just like the example code and reflect what's to be expected from the GraphQL explorer. I had an easier time connecting to the Admin SDK GraphQL using fetch than I did with the SDK.

Error log

{
  errors: [
    {
      message: 'Private Key is required',
      locations: [Array],
      path: [Array],
      extensions: [Object]
    }
  ],
  data: { models: null },
  extensions: {
    tracing: {
      version: 1,
      startTime: '2022-12-06T23:11:23.282Z',
      endTime: '2022-12-06T23:11:23.363Z',
      duration: 80553819,
      execution: [Object]
    }
  }
}

davidrhoderick avatar Dec 06 '22 23:12 davidrhoderick

Hi @davidrhoderick, this error happens when you are not passing a valid private key value, please double-check the value you have in your environment for process.env.BUILDERIO_PRIVATE_API_KEY

teleaziz avatar Dec 27 '22 19:12 teleaziz

@davidrhoderick Are you still experiencing this issue? I am closing this issue due to staleness, but please feel free to reopen if you still need help.

samijaber avatar Oct 02 '24 14:10 samijaber

Hey @samijaber , yea I don't work with Builder anymore so you can close this

toptal-dave avatar Oct 03 '24 07:10 toptal-dave