Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the @shopify/admin-api-client with GraphQL, we able to make query requests but not mutation requests, If it's available in the README, an example would be greatly appreciated. #1652

Closed
vhr333 opened this issue Oct 18, 2024 · 5 comments

Comments

@vhr333
Copy link

vhr333 commented Oct 18, 2024

Using the @shopify/admin-api-client with GraphQL, we able to make query requests but not mutation requests, If it's available in the README, an example would be greatly appreciated.

Package: https://www.npmjs.com/package/@shopify/admin-api-client
GitHub: https://github.com/Shopify/shopify-app-js/tree/main/packages/api-clients/admin-api-client#readme

Query works fine, mutation throws an error with message: "Field 'fulfillmentCreate' doesn't exist on type 'Mutation'"

Example query and Mutations

## Client: 

import {createAdminApiClient} from '@shopify/admin-api-client';
const client = createAdminApiClient({
  storeDomain: 'changeme.myshopify.com',
  apiVersion: 'changeme',
  accessToken: 'changeme'
});

## Query:
const operation = `
  query ProductQuery($id: ID!) {
    product(id: $id) {
      id
      title
    }
  }
`;

const productResp = await client.request(operation, {
  variables: {
    id: 'gid://shopify/Product/7608002183224',
  },
});

## Mutation:
  const operation = `mutation fulfillmentCreate {
    fulfillmentCreate(
      fulfillment: {
        lineItemsByFulfillmentOrder: {
          fulfillmentOrderId: "gid://shopify/FulfillmentOrder/123456"
          fulfillmentOrderLineItems: {
            id: "gid://shopify/FulfillmentOrderLineItem/900000"
            quantity: 1
          }
        }
        notifyCustomer: "${notifyCustomer}"
        trackingInfo: {
          company: "Other"
          number: "123456"
        }
      }
    ) {
      fulfillment {
        id
      }
    }
  }`;
  const fulfillmentResp = await client.request(operation);
@lizkenyon
Copy link
Contributor

Hi there 👋

What API version are you using? That mutation is not available in all API versions. (E.g. Not available in 2024-07, is available in 2024-10)

@vhr333
Copy link
Author

vhr333 commented Oct 18, 2024

@lizkenyon
Currently we are using 2024-10, which version will support mutation for admin-client?
Tried with 2024-04 same issue.

Image

@lizkenyon
Copy link
Contributor

Hi there this worked for me!

import {createAdminApiClient} from '@shopify/admin-api-client';
const client = createAdminApiClient({
  storeDomain: 'liz-dev-pre-pop-september.myshopify.com',
  apiVersion: '2024-10',
  accessToken: 'shpat_cff'
});

const operation = `mutation fulfillmentCreate {
    fulfillmentCreate(
      fulfillment: {
        lineItemsByFulfillmentOrder: {
          fulfillmentOrderId: "gid://shopify/FulfillmentOrder/123456"
          fulfillmentOrderLineItems: {
            id: "gid://shopify/FulfillmentOrderLineItem/900000"
            quantity: 1
          }
        }
        notifyCustomer: true
        trackingInfo: {
          company: "Other"
          number: "123456"
        }
      }
    ) {
      fulfillment {
        id
      }
    }
  }`;
  const fulfillmentResp = await client.request(operation);
  console.log(fulfillmentResp);

You may want to review what you are setting the API version when you create the client.

import {createAdminApiClient} from '@shopify/admin-api-client';
const client = createAdminApiClient({
  storeDomain: 'liz-dev-pre-pop-september.myshopify.com',
  apiVersion: '2024-10',
  accessToken: 'shpat_cff'
});

If you use an API version that is no longer available you will be defaulted to the oldest valid API version.

@vhr333
Copy link
Author

vhr333 commented Oct 18, 2024

Hi there this worked for me!

import {createAdminApiClient} from '@shopify/admin-api-client';
const client = createAdminApiClient({
  storeDomain: 'liz-dev-pre-pop-september.myshopify.com',
  apiVersion: '2024-10',
  accessToken: 'shpat_cff'
});

const operation = `mutation fulfillmentCreate {
    fulfillmentCreate(
      fulfillment: {
        lineItemsByFulfillmentOrder: {
          fulfillmentOrderId: "gid://shopify/FulfillmentOrder/123456"
          fulfillmentOrderLineItems: {
            id: "gid://shopify/FulfillmentOrderLineItem/900000"
            quantity: 1
          }
        }
        notifyCustomer: true
        trackingInfo: {
          company: "Other"
          number: "123456"
        }
      }
    ) {
      fulfillment {
        id
      }
    }
  }`;
  const fulfillmentResp = await client.request(operation);
  console.log(fulfillmentResp);

You may want to review what you are setting the API version when you create the client.

import {createAdminApiClient} from '@shopify/admin-api-client';
const client = createAdminApiClient({
  storeDomain: 'liz-dev-pre-pop-september.myshopify.com',
  apiVersion: '2024-10',
  accessToken: 'shpat_cff'
});

If you use an API version that is no longer available you will be defaulted to the oldest valid API version.

@vhr333 vhr333 closed this as completed Oct 18, 2024
@vhr333
Copy link
Author

vhr333 commented Oct 18, 2024

Thank you @lizkenyon it's working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants