The data provided was deemed invalid with the message, "Requested quantity is unavailable," involving NextJS and Commerce JS

Hey there! I'm currently working on setting up an online store using CommerceJs and NextJS, but I've encountered an issue when processing payments. The error message I'm receiving is:

"The given data was invalid." "type: unprocessable_entity" line_items.item_7RyWOwmK5nEa2V.quantity: ["Requested quantity is not available."]

I've attempted to adjust my code based on the documentation, but so far, I haven't had any success.

const orderData = {
    line_items: {
      item_7RyWOwmK5nEa2V: {
        quantity: 1,
      }
    },
    customer: {
      firstname: 'John',
      lastname: 'Doe',
      email: '[email protected]'
    },
    shipping: {
      name: 'John Doe',
      street: '123 Fake St',
      town_city: 'San Francisco',
      county_state: 'US-CA',
      postal_zip_code: '94103',
      country: 'US'
    },
    fulfillment: {
      shipping_method: 'ship_7RyWOwmK5nEa2V'
    },
    billing: {
      name: 'John Doe',
      street: '234 Fake St',
      town_city: 'San Francisco',
      county_state: 'US-CA',
      postal_zip_code: '94103',
      country: 'US'
    },
    payment: {
      gateway: 'stripe',
      stripe: {
        payment_method_id: paymentMethod.id,
      },
    }
  }

Answer №1

To adjust the available quantity of your product, head to your commerce.js dashboard and make the necessary edits. Navigate to dashboard > products > productName > inventoryAvailable. Don't forget to also confirm that if you have variants, the selected variant has sufficient inventory available...

If you want to check the availability of your product inventory, use the following code snippet...

commerce.checkout.checkQuantity("your-checkout-token", 'item-id', {
    amount: 1,
    variant_id: 'your-variant-id-OPTIONAL'
}).then((response) => console.log(response.available));

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Fade out a component in Material UI/React by setting a timeout in the parent's useEffect hook for when it unmounts

Incorporating a fade out transition into my child component, <Welcome />, using Material UI's Fade component is my current goal. This transition should be triggered by two specific conditions: The timeout set in the useEffect function expires. ...

Switch up the image source with Javascript in a random sequence

Looking to create a script that randomly changes the image source of an element with one specified in an array. However, the variable "target" keeps returning undefined. Can you help? HTML <ul> <li><img src="http://www.placehold.it/20x ...

Executing a JavaScript Ajax request when the page has finished loading

I want the page to be completely loaded before making an ajax call to update the database. I can trigger a JavaScript function in the body's onload event to ensure the page is fully loaded, but I'm unsure how to initiate the Ajax call from there. ...

Error: Unable to assign value to '18dit075' property as it is not defined in Node.js

var id = req.query.id; var username = req.query.name; var password = req.query.password; console.log(req.query); var data = { people:{ } } data.people[id] = { username: username, password: password, ...

Struggling to create a line break within an SVG using the <tspan> element?

I have a pair of text lines that are wrapped in <tspan> tags. <tspan dy="-11.7890625">welcome</tspan> <tspan dy="16.8" x="285.75">text</tspan> I am trying to add a line break between them, but the <br> tag is not worki ...

Executing conditions in a JavaScript browser

Currently, I am utilizing a JS library known as fallback.js. This library loads all its <link> elements at the bottom of the <head> tag. However, I am facing an issue where I need to load certain stylesheets at the very end, but they require IE ...

JavaScript ES5 allows for the choice between updating a value or pushing to an array

I've been attempting to add an object to an array of objects only if that specific object is not already in the array. If it is present, the object should be updated instead. My requirement is to achieve this using es5. Below is my current approach: ...

Achieve overlapping divs using the Grid Layout

My objective is to have the div overlap the next row(s) without pushing them down when it increases in size. I attempted to use position: absolute; but this caused issues with the Grid Layout structure. Preserving the shape of the grid is crucial to me ...

An error stating 'THREE.OBJLoader is not a constructor' has occurred, along with an 'Unexpected token {' message in OBJLoader and OrbitControls

Attempting to showcase an OBJ 3D model as a wireframe that can be interactively moved using OrbitControls in Three.js. Being new to three.js, I apologize if I'm overlooking something obvious. Successfully displayed a wireframe cube with OrbitControls ...

What is the best way to properly redirect a page using a router link in Vue.js 2?

I've encountered an issue with the router-link component in Vue.js 2. I have set up my router file index.js import Vue from 'vue'; import VueRouter from 'vue-router'; import HomeView from '../views/HomeView.vue'; import ...

Retrieving xml data using ajax

Hey there, I'm working with an HTML file that looks like this: <!DOCTYPE html> <html> <style> table, th, td { border: 1px solid black; border-collapse: collapse; } th, td { padding: 5px; } </style> & ...

Struggling to send an array through Ajax to Django view?

I am just starting to work with ajax and I want to pass an array from JavaScript to my view. Here is the template. I have a form that takes the course ID number and score from students, creates a table, and adds how many courses the student wants to add. ...

Leveraging Global SCSS Variables in Next.JS with SASS

In my Next.js Application, I have a global CSS file named main.scss imported in the pages/_app.js file. _app.js import '../global-styles/main.scss' export default function MyApp({ Component, pageProps }) { return <Component {...pageProps} ...

Implementing Date.now() as a Schema Field Type in Meteor's Simple-Schema

Within my Meteor application, I have utilized Date.now() to generate a timestamp for inclusion in a new MongoDB document. Although Date.now() appears to be an appropriate choice for my app, I lack expertise in managing dates and times. As I transition to ...

Can you provide me with a step-by-step guide on how to implement Stripe's Custom Payment feature

Currently in the process of creating a customized payment module for my django application and in need of some assistance. At the moment, I am using Stripe's Checkout for handling payments, but I find it restrictive as it doesn't allow for comple ...

Explain the contrast between specifying a function name in the onclick react event versus invoking it using a callback

Can someone explain the distinction between these two React statements? <Button onClick={this.Callme}></Button> <Button onClick={()=>this.Callme()}></Button> Is it merely a syntax difference or is there an impact on functional ...

Prevent any pop-up windows from appearing when a specific link is clicked

On my website, I have implemented popup advertising where ads open when clicked inside the body. However, I am looking to disable popups when a link with the class donot is clicked. Currently, when the donot link is clicked, a popup opens and the link doe ...

React's .map is not compatible with arrays of objects

I want to retrieve all products from my API. Here is the code snippet for fetching products from the API. The following code snippet is functioning properly: const heh = () => { products.map((p) => console.log(p.id)) } The issue ari ...

Cloud Function experiences a timeout error when attempting to subscribe an FCM token to a topic within the HTTP function

Example Code: Main.ts: import * as admin from "firebase-admin" import fetch, { Headers } from "node-fetch"; interface FooPayload { topic: string, token: string, } exports.foo = functions.https.onCall(async (data, context) => { ...

What causes AngularJS to generate an error when attempting to construct a URL for the src attribute of an iframe?

Recently, I've been working with AngularJS directives and encountered an issue while trying to use an expression in the src attribute of an iframe. The error message I received referenced a URL that didn't provide much insight: http://errors.ang ...