Sending queries for multiple values of the same criteria

Hello!

I was wondering how to structure a query to be able to request results on multiple values of the same criteria. For example, I would like to send a products query to get information on multiple SKUs, but I would like to do it 1) without having to pull all 7300+ products and filtering through the result after the fact, and 2) without having the send the same “single” queries multiple times. Is something like this possible?

Using the products query as an example, I would like to be able to do something like this:

query {
  products (sku: "sku1,sku2,sku3") {
    request_id
    complexity
    data (first: 5) {
        ...

I’ve tried using the sku: identifier multiple times, but that isn’t allowed. I also tried a number of variations for splitting up the SKUs in the query string, such as separating with commas (as above), spaces, pipes, “or”, “OR”, “and”, “AND”, and semicolons. None of them worked. Is there a way to get this to work? I looked through the documentation website and didn’t see anything related to this.

Thanks,
Jeremy

Hi @jeremyw!
We don’t have the ability to do this at the moment. We do have on our scope to be able to use GraphQL Aliases, which will allow you to get a bunch of them at once.

Example:

query {
  aliasOne: product(sku: "1122334464") {
    request_id
    complexity
    data {
      sku
      name
      barcode
    }
  }
  aliasTwo: product(sku: "1122334466") {
    request_id
    complexity
    data {
      sku
      name
      barcode
    }
  }
}

But we don’t have an ETA on when this might be worked on.
Would this work for you?
Thanks in advance!
Tom

1 Like

Thanks, @tomasw !

It’s not ideal because there could be times where I need to pull a hundred or more SKUs, but it’s definitely workable and still way better than sending them one at a time. :slight_smile:

Sounds good @jeremyw
We have that workaround pending, but we will make a Feature Request for the OR query
We will keep you posted!
Thanks again!
Tom

Hi Tomasw,

I used this way to query two different order, but I still receive the same id for both order.

Hello @oneye!
I hope you are doing ok.
Unfortunately, this hasn’t been implemented yet. However, you can fetch multiple orders using the orders query and its filters.
Please let me know if this doesn’t help.
Best,
Tomas

Hi @tomasfd ,
Currently I am running multiple query to fetch the result I want at 5 second interval.
It is a bit slow but if I ran it faster, I would get Credit error message.
Is there a optimal time limit I should be running?

Hi @oneye ,

For me, what I do is I have the code that’s sending the queries and checking the results run as fast as it can. When it encounters the credit error message, there should be a field that says how long it should be until you can run that query and get the results you requested. (I forget what that field is called off the top of my head) I have the code extract that and wait for that number of seconds before trying the same query again. That way your code is self regulating and only waiting for the minimum amount of time required to in order to try again, even if that time fluctuates for any reason.

I hope that helps!

1 Like

Hello @oneye!
I hope you are having a great day!

The time limit will depend mainly on the complexity of the query/mutation. You are given 2002 credits, to begin with, and recover 30 every second. If you are expending more than 30 per second, you will eventually end up getting the error.

As @jeremyw stated, you could work around this by polling the error and checking the time_remaining field or rounding up (required_credits - remaining_credits) / 30.

Here’s an example of what the error returns so you can check the fields:

{
  "errors": [
    {
      "code": 30,
      "message": "There are not enough credits to perform the requested operation, which requires 1001 credits, but the are only 90 left. In 31 seconds you will have enough credits to perform the operation",
      "operation": "order",
      "request_id": "9843ynt3489ty34",
      "required_credits": 1001,
      "remaining_credits": 90,
      "time_remaining": "31 seconds"
    }
  ],
  "data": {
    "order": null
  }
}

Please let me know if this doesn’t help.
Have a nice day!
Tomas

1 Like

Is there a solution yet to query multiple SKU’s? Alias doesn’t work.