const axios = require('axios');

const SHOP = 'veloxautomotive.myshopify.com';
const ACCESS_TOKEN = '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';

//gid://shopify/Location/84790051032

const client = axios.create({
  baseURL: `https://${SHOP}/admin/api/2024-01/graphql.json`,
  headers: {
    'X-Shopify-Access-Token': ACCESS_TOKEN,
    'Content-Type': 'application/json',
  },
});

async function createFulfillmentService() {
  var mutation = `
    mutation {
      fulfillmentServiceCreate(
        name: "Data4Autos Distribution1",
        callbackUrl: "https://your-app.com/fulfillment-callback"
      ) {
        fulfillmentService {
          id
          serviceName
          callbackUrl
          handle
          location {
            id
          }
        }
        userErrors {
          field
          message
        }
      }
    }
  `;


  //   mutation = `
  //   mutation {
  //     fulfillmentServiceDelete(id: "gid://shopify/FulfillmentService/64502038744") {
  //       deletedId
  //       userErrors {
  //         field
  //         message
  //       }
  //     }
  //   }
  // `;



  try {
    const response = await client.post('', { query: mutation });
    console.log(`Response received:`, response.data);
    const data = response.data.data.fulfillmentServiceCreate;
    if (data.userErrors && data.userErrors.length > 0) {
      console.error('User errors:', data.userErrors);
    } else {
      console.log('Fulfillment Service created:', data.fulfillmentService);
    }
  } catch (error) {
    console.error('Request failed:', error.response ? error.response.data : error.message);
  }
}

createFulfillmentService();