API Script for Shopify
It is necessary to create a script (js method) that will update the number of products via API
- connecting node adminClientAPI (official package)
- updating through mutation GraphQL (or your option)
- updating by delta (+1, -2, etc.)
In fact, the function exists but gives an error that the Input has an incorrect format, other methods in the project work well
Ось весь код який має запрацювати.
const client = createAdminApiClient({
storeDomain: process.env.SF_DOMAIN,
apiVersion: process.env.SF_API_VERSION,
accessToken: process.env.SF_ADMIN_ACCESS_TOKEN,
});
const mutateInventoryQuantity = async (inventoryItemId, delta) => {
const mutation = `
mutation inventoryAdjustQuantities($input: InventoryAdjustQuantitiesInput!) {
inventoryAdjustQuantities(input: $input) {
userErrors {
field
message
}
inventoryAdjustmentGroup {
createdAt
reason
referenceDocumentUri
changes {
name
delta
}
}
}
}
`;
const input = {
reason: "correction",
changes: [
{
delta,
inventoryItemId,
locationId: process.env.SF_CONST_LOCATION_ID
}
]
};
console.log('DEBUG: payload', JSON.stringify({ input }, null, 2));
try {
return await client.request(mutation, { input });
} catch (error) {
console.error('Failed to mutate inventory:', error);
throw error;
}
}
mutateInventoryQuantity(id, delta)
RESPONSE
Variable $input of type InventoryAdjustQuantitiesInput! was provided invalid value {
value: null,
problems: [ { path: [], explanation: 'Expected value to not be null' } ]
}
-
const mutateInventoryQuantity = async (inventoryItemId, delta) => {
const mutation = `
mutation inventoryAdjustQuantities($input: InventoryAdjustQuantitiesInput!) {
inventoryAdjustQuantities(input: $input) {
userErrors {
field
message
}
inventoryAdjustmentGroup {
createdAt
reason
referenceDocumentUri
changes {
name
delta
}
}
}
}
`;
const input = {
reason: "correction",
changes: [
{
delta,
inventoryItemId,
locationId: process.env.SF_CONST_LOCATION_ID
}
]
};
console.log('DEBUG: payload', JSON.stringify({ input }, null, 2));
try {
return await client.request(mutation, { input });
} catch (error) {
console.error('Failed to mutate inventory:', error);
throw error;
}
}
RESPONSE
Variable $input of type InventoryAdjustQuantitiesInput! was provided invalid value {
value: null,
problems: [ { path: [], explanation: 'Expected value to not be null' } ]
}
ось така відповідь з сервера -
Current freelance projects in the category Javascript and Typescript
Full-stack development — Amazon PPC Dashboard (Stage 1)Need a full-stack developer with experience working with Amazon API to implement Stage 1 of the internal PPC dashboard. The project is real, the data is live, everything is ready to start. Frontend prototype (5 pages, React + TypeScript): WHAT IS ALREADY READY — Frontend… Javascript and Typescript, Web Programming ∙ 2 days 5 hours back ∙ 28 proposals |
Development of a photo book and photo frame constructor websiteProject Goal A modern website needs to be developed for ordering photo books, photo frames, and other personalized photo products. The main task of the project is to provide the client with the ability to independently create a ready-made layout of the product directly on the… Javascript and Typescript, Web Programming ∙ 3 days 21 hours back ∙ 96 proposals |
Team for a custom marketplace of funeral services.We are looking for a team to launch and develop a custom national marketplace for funeral services. Right away: we are not looking for solo freelancers, juniors, or "website builders." We need a strong product team at the middle+/senior level with real cases in… Javascript and Typescript, Web Programming ∙ 4 days 15 hours back ∙ 27 proposals |
Improvement of the existing Next.js/Supabase project: offers, CRM, analytics, AI chatThere is an active project WatchGenius — a luxury watch analytics platform with a catalog of models, price analytics, external offers, application forms, and an AI chat. The project has already been partially developed. We need not a website from scratch, but an experienced… Javascript and Typescript, Web Programming ∙ 6 days 17 hours back ∙ 55 proposals |
I am looking for a Senior Full-Stack Developer (Payload CMS) — migration of 2 websites for a hotel chain.The resort hotel network is transitioning from Webflow to its own headless stack. Two corporate websites (~140 pages in total), multi-tenant architecture — one code serves multiple hotels on different domains. The project has already started: the infrastructure is deployed,… Content Management Systems, Javascript and Typescript ∙ 10 days 15 hours back ∙ 19 proposals |