Search code examples
shopifyshopify-api-node

Shopify Admin API create customer has odd response


I'm able to successfully pull orders via the Admin API. I now am creating a custom create account widget and am using the same fetch methodology I used for getting the orders but posting to create the customer. Here is the fetch call:

const shopifyUserQuery = `
  query {
    customer {
      first_name: ${values.firstName},
      last_name: ${values.lastName},
      email: ${values.email},
      verified_email: true,
      password: ${values.password}
      password_confirmation: ${values.password},
      send_email_welcome = false;
    }
  }
  `
  const shopifyUser = await fetch(process.env.SHOPIFY_ADMIN_API_URL, {
    'body': shopifyUserQuery,
    'method': 'post',
    'headers': {
      'X-Shopify-Access-Token': shopifyAdminAccessToken,
      'Content-Type': 'application/graphql',
    },
  }).then((res) => console.log(res))

Now, the response is really odd - no errors, nothing just an odd blend of content in a zipped file:

<ref *1> Gunzip {
  _writeState: Uint32Array(2) [ 0, 0 ],
  _readableState: ReadableState {
    objectMode: false,
    highWaterMark: 16384,
    buffer: BufferList { head: null, tail: null, length: 0 },
    length: 0,
    pipes: [],
    flowing: null,
    ended: false,
    endEmitted: false,
    reading: false,
    constructed: true,
    sync: false,
    needReadable: false,
    emittedReadable: false,
    readableListening: false,
    resumeScheduled: false,
    errorEmitted: false,
    emitClose: true,
    autoDestroy: true,
    destroyed: false,
    errored: null,
    closed: false,
    closeEmitted: false,
    defaultEncoding: 'utf8',
    awaitDrainWriters: null,
    multiAwaitDrain: false,
    readingMore: false,
    dataEmitted: false,
    decoder: null,
    encoding: null,
    [Symbol(kPaused)]: null
  },
  _events: [Object: null prototype] {
    prefinish: [Function: prefinish],
    unpipe: [Function: onunpipe],
    error: [ [Function: onerror], [Function (anonymous)] ],
    close: [Function: bound onceWrapper] { listener: [Function: onclose] },
    finish: [Function: bound onceWrapper] { listener: [Function: onfinish] }
  },
  _eventsCount: 5,
  _maxListeners: undefined,
  _writableState: WritableState {
    objectMode: false,
    highWaterMark: 16384,
    finalCalled: false,
    needDrain: false,
    ending: false,
    ended: false,
    finished: false,
    destroyed: false,
    decodeStrings: true,
    defaultEncoding: 'utf8',
    length: 109,
    writing: true,
    corked: 0,
    sync: false,
    bufferProcessing: false,
    onwrite: [Function: bound onwrite],
    writecb: [Function: nop],
    writelen: 109,
    afterWriteTickInfo: null,
    buffered: [],
    bufferedIndex: 0,
    allBuffers: true,
    allNoop: true,
    pendingcb: 1,
    constructed: true,
    prefinished: false,
    errorEmitted: false,
    emitClose: true,
    autoDestroy: true,
    errored: null,
    closed: false,
    closeEmitted: false,
    [Symbol(kOnFinished)]: []
  },
  allowHalfOpen: true,
  bytesWritten: 0,
  _handle: Zlib {
    onerror: [Function: zlibOnError],
    buffer: <Buffer 1f 8b 08 00 00 00 00 00 04 03 25 8c 31 0a 80 30 10 04 bf 72 6c a5 10 6c 42 52 e4 15 f6 9a e2 90 20 42 bc 83 44 ab e0 df 0d ca 56 c3 30 db 90 4a d1 52 ... 59 more bytes>,
    cb: [Function (anonymous)],
    availOutBefore: 16384,
    availInBefore: 109,
    inOff: 0,
    flushFlag: 2,
    [Symbol(owner_symbol)]: [Circular *1]
  },
  _outBuffer: <Buffer 7b 22 65 72 72 6f 72 73 22 3a 5b 7b 22 6d 65 73 73 61 67 65 22 3a 22 50 61 72 73 65 20 65 72 72 6f 72 20 6f 6e 20 5c 22 2e 5c 22 20 28 65 72 72 6f 72 ... 16334 more bytes>,
  _outOffset: 0,
  _chunkSize: 16384,
  _defaultFlushFlag: 2,
  _finishFlushFlag: 2,
  _defaultFullFlushFlag: 3,
  _info: undefined,
  _maxOutputLength: 4294967296,
  _level: -1,
  _strategy: 0,
  [Symbol(kCapture)]: false,
  [Symbol(kCallback)]: null,
  [Symbol(kError)]: null
}

Again, this admin token key does work but even if there were scope or perm issues (I did double check that my app has customer read and write scope) I'd expect a better error. Any help is appreciated.


Solution

  • Query Operation in Shopify GraphQL are type of get request where you can only get the demanded query list.

    To edit or update anything on store you need to use Mutation operations (admin api required)

    mutation test {
      customerCreate(input: {firstName: "", lastName: "", phone: "", email: ""})
    }
    

    for more clarity please visit - Shopify GraphQL

    In the image you can see how to add a mutation operation.

    enter image description here