# New SDK Returning Different then the old SDK

**URL:** <https://forum.builder.io/t/new-sdk-returning-different-then-the-old-sdk/4975>\
**Category:** Technical Questions\
**Created:** [February 13, 2024, 5:10pm UTC](https://forum.builder.io/t/new-sdk-returning-different-then-the-old-sdk/4975 "2024-02-13T17:10:21Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![kacey](https://avatars.discourse-cdn.com/v4/letter/k/0ea827/32.png) [@kacey](https://forum.builder.io/u/kacey)\
**Post date:** [February 13, 2024, 5:10pm UTC](https://forum.builder.io/t/new-sdk-returning-different-then-the-old-sdk/4975/1 "2024-02-13T17:10:21Z")

</div>

_Please fill out as many of the following questions as possible so we can help you promptly! If you don’t know how to answer or it does not apply, feel free to remove it or leave it blank._

**Builder content link**  
_e.g. [Builder.io: Visual Development Platform](http://builder.io/content/4cab34394e684fe7b93d6ef5493a8a51)_  
[Builder.io: Visual Development Platform](https://builder.io/content/feff53ec3d574c12aa2cf4e7350a8768)

**Builder public api key**  
_go to [Builder.io: Visual Development Platform](https://builder.io/account/organization) and copy your PUBLIC api key_  
e2f096ba17f74dfd9c140ac050f349a4

**What are you trying to accomplish**  
_e.g. I want to integrate builder on a landing page_  
I need the new SDK to return the same as the old SDK using the `$elemMatch` operator. The URL generated between the two SDKs are different but I cannot pinpoint how to adjust it to work.l

**Code stack you are integrating Builder with**  
_e.g. NextJS, react, Shopify_  
NextJS

**Reproducible code example**  
_If you are having integration errors, please link to codesandbox or copy and paste your problematic code here. The more detail the better!_

Here is the URL generated by the old SDK that works:  
[https://cdn.builder.io/api/v3/query/e2f096ba17f74dfd9c140ac050f349a4/blog-article%3A4afaabe8?omit=data.blocks&apiKey=e2f096ba17f74dfd9c140ac050f349a4&sort.createdDate=-1&enrich=true&noTraverse=true&userAttributes.urlPath=%2Fblog&userAttributes.host=localhost%3A4000&userAttributes.device=desktop&options.blog-article%3A4afaabe8.limit=5&options.blog-article%3A4afaabe8.query={"data.categories"%3A{"%24elemMatch"%3A{"category.id"%3A{"%24in"%3A"[\"d491820ec5da422199336a73f388f354\"]"}}}}&options.blog-article%3A4afaabe8.model="blog-article"](https://cdn.builder.io/api/v3/query/e2f096ba17f74dfd9c140ac050f349a4/blog-article%3A4afaabe8?omit=data.blocks&apiKey=e2f096ba17f74dfd9c140ac050f349a4&sort.createdDate=-1&enrich=true&noTraverse=true&userAttributes.urlPath=%2Fblog&userAttributes.host=localhost%3A4000&userAttributes.device=desktop&options.blog-article%3A4afaabe8.limit=5&options.blog-article%3A4afaabe8.query=%7B%22data.categories%22%3A%7B%22%24elemMatch%22%3A%7B%22category.id%22%3A%7B%22%24in%22%3A%22%5B%5C%22d491820ec5da422199336a73f388f354%5C%22%5D%22%7D%7D%7D%7D&options.blog-article%3A4afaabe8.model=%22blog-article%22)

Here is the URL generated by the new SDK that does not work:  
[https://cdn.builder.io/api/v3/content/blog-article?apiKey=e2f096ba17f74dfd9c140ac050f349a4&limit=5&noTraverse=true&includeRefs=true&omit=data.blocks&sort.createdDate=-1&enrich=true&query.data.categories.%24elemMatch.category.id.%24in="[\"d491820ec5da422199336a73f388f354\"]"](https://cdn.builder.io/api/v3/content/blog-article?apiKey=e2f096ba17f74dfd9c140ac050f349a4&limit=5&noTraverse=true&includeRefs=true&omit=data.blocks&sort.createdDate=-1&enrich=true&query.data.categories.%24elemMatch.category.id.%24in=%22%5B%5C%22d491820ec5da422199336a73f388f354%5C%22%5D%22)

The query field is passed in differently so that is probably the cause but I just don’t know what is being expected on the API side in terms of syntax to get it to return properly.

---

<div class="post-metadata">

**Author:** ![manish-sharma](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@manish-sharma](https://forum.builder.io/u/manish-sharma)\
**Post date:** [February 15, 2024, 7:49pm UTC](https://forum.builder.io/t/new-sdk-returning-different-then-the-old-sdk/4975/2 "2024-02-15T19:49:26Z")

</div>

Hello @kacey,

There seems to be some issue with the encoding of the query. To fix the issue with your URL, you need to make sure the query parameters are properly encoded. Here’s the corrected URL:

[https://cdn.builder.io/api/v3/content/blog-article?apiKey=e2f096ba17f74dfd9c140ac050f349a4&limit=5&includeRefs=true&omit=data.blocks&enrich=true&query.data.categories.$elemMatch%3D{category.id%3D{%24in%3D['d491820ec5da422199336a73f388f354']}}](https://cdn.builder.io/api/v3/content/blog-article?apiKey=e2f096ba17f74dfd9c140ac050f349a4&limit=5&includeRefs=true&omit=data.blocks&enrich=true&query.data.categories.$elemMatch%3D%7Bcategory.id%3D%7B%24in%3D%5B%27d491820ec5da422199336a73f388f354%27%5D%7D%7D)

```auto
https://cdn.builder.io/api/v3/content/blog-article?
apiKey=e2f096ba17f74dfd9c140ac050f349a4&limit=5
&includeRefs=true&omit=data.blocks&enrich=true
&query.data.categories.$elemMatch={category.id={$in=['d491820ec5da422199336a73f388f354']}}

```

For reference, I recommend you check out our [Querying Cheatsheet](https://www.builder.io/c/docs/querying#querying-cheatsheet)

---

<div class="post-metadata">

**Author:** ![kacey](https://avatars.discourse-cdn.com/v4/letter/k/0ea827/32.png) [@kacey](https://forum.builder.io/u/kacey)\
**Post date:** [February 15, 2024, 8:07pm UTC](https://forum.builder.io/t/new-sdk-returning-different-then-the-old-sdk/4975/3 "2024-02-15T20:07:08Z")

</div>

Thanks again for taking a look at this Manish; I will have to mess around with the new SDK to try and get it to return the format you posted.

Do you have any ideas on how to do that? The old SDK accepted and worked with the syntax I used however the new SDK is not outputting the correct request that I am expecting.

---

<div class="post-metadata">

**Author:** ![manish-sharma](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@manish-sharma](https://forum.builder.io/u/manish-sharma)\
**Post date:** [February 15, 2024, 8:11pm UTC](https://forum.builder.io/t/new-sdk-returning-different-then-the-old-sdk/4975/4 "2024-02-15T20:11:21Z")

</div>

Hello @kacey,

I recommend you check out the following [Querying Cheatsheet - Builder.io](https://www.builder.io/c/docs/querying#querying-cheatsheet)

[Using graphql to query model with 'foreign keys' - #2 by aziz](https://forum.builder.io/t/using-graphql-to-query-model-with-foreign-keys/505/2)

---

<div class="post-metadata">

**Author:** ![kacey](https://avatars.discourse-cdn.com/v4/letter/k/0ea827/32.png) [@kacey](https://forum.builder.io/u/kacey)\
**Post date:** [February 15, 2024, 8:19pm UTC](https://forum.builder.io/t/new-sdk-returning-different-then-the-old-sdk/4975/5 "2024-02-15T20:19:02Z")

</div>

The cheatsheet only references the old SDK and that link I have followed before and it worked with the old SDK but not the new SDK

---

<div class="post-metadata">

**Author:** ![manish-sharma](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@manish-sharma](https://forum.builder.io/u/manish-sharma)\
**Post date:** [February 16, 2024, 1:03pm UTC](https://forum.builder.io/t/new-sdk-returning-different-then-the-old-sdk/4975/6 "2024-02-16T13:03:07Z")

</div>

Hello @kacey,

I wanted to clarify that the querying cheatsheet is specifically for the content API v3 and there have been no changes to it. If you’ve been utilizing [https://cdn.builder.io/api/v3/query/](https://cdn.builder.io/api/v3/query/), which is our query API, and assuming it’s part of our old SDK, that’s not the case. The query API is still in use alongside the content API. We’ve simply upgraded our API version to v3, which I see you’re already using.

Query API is used internally within the editor and you should be using content API for fetch or querying operations.

---

<div class="post-metadata">

**Author:** ![kacey](https://avatars.discourse-cdn.com/v4/letter/k/0ea827/32.png) [@kacey](https://forum.builder.io/u/kacey)\
**Post date:** [February 16, 2024, 4:09pm UTC](https://forum.builder.io/t/new-sdk-returning-different-then-the-old-sdk/4975/7 "2024-02-16T16:09:56Z")

</div>

The content API v3 works fine like you said but the translation to the content API v3 query params from the new React SDK makes it impossible to get the correct API call you linked. The working API call you linked includes a query parameter with no value and the `=` signs encoded into the key of the query param itself for the `query` parameter. It seems impossible to get this result when using the new React SDK without some weird work arounds.

For instance, the working API call you linked  
[https://cdn.builder.io/api/v3/content/blog-article?apiKey=e2f096ba17f74dfd9c140ac050f349a4&limit=5&includeRefs=true&omit=data.blocks&enrich=true&query.data.categories.$elemMatch%3D{category.id%3D{%24in%3D[‘d491820ec5da422199336a73f388f354’]}}](https://cdn.builder.io/api/v3/content/blog-article?apiKey=e2f096ba17f74dfd9c140ac050f349a4&limit=5&includeRefs=true&omit=data.blocks&enrich=true&query.data.categories.$elemMatch%3D%7Bcategory.id%3D%7B%24in%3D%5B%27d491820ec5da422199336a73f388f354%27%5D%7D%7D)

has these query params when parsed out:

```auto
apiKey: e2f096ba17f74dfd9c140ac050f349a4
limit: 5
includeRefs: true
omit: data.blocks
enrich: true
query.data.categories.$elemMatch={category.id={$in=['d491820ec5da422199336a73f388f354']}}: 

```

when using the React SDK like so:

```ts
await fetchEntries({
    model: 'blog-article',
    apiKey: process.env.NX_BUILDER_IO_PUBLIC_KEY!,
    options: {
      sort: {
        createdDate: -1,
      },
      enrich: true,
    },
    query: {
      'data.categories': {
        $elemMatch: {
          'category.id': {
            $in: JSON.stringify(['d491820ec5da422199336a73f388f354']).trim(),
          },
        },
      },
    },
    limit: 5,
    omit: 'data.blocks',
  });

```

This should work when compared to the previous SDK but also using some of the referenced posts you pointed to but it does not. It encodes the `=` and your working URL does not.

I was able to finally get it to work with a hacky work around but its far from ideal.

```ts
await fetchEntries({
    model: 'blog-article',
    apiKey: process.env.NX_BUILDER_IO_PUBLIC_KEY!,
    options: new URLSearchParams(
      `query.data.categories.$elemMatch%3D%7Bcategory.id%3D%7B%24in%3D%5B%27d491820ec5da422199336a73f388f354%27%5D%7D%7D`,
    ),
    sort: {
      createdDate: -1,
    },
    enrich: true,
    limit: 5,
    omit: 'data.blocks',
  });

```

I essentially have to use the “scape goat” `options` param with an encoded `URLSearchParams` to get the desired result. I think this is a fairly large issue with the new SDK if I am thinking of this right as it prevents a large portion of functionality for querying data via the SDK which is the whole point.

---

<div class="post-metadata">

**Author:** ![manish-sharma](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@manish-sharma](https://forum.builder.io/u/manish-sharma)\
**Post date:** [February 16, 2024, 5:44pm UTC](https://forum.builder.io/t/new-sdk-returning-different-then-the-old-sdk/4975/8 "2024-02-16T17:44:40Z")

</div>

Hello @kacey,

Your workaround using `URLSearchParams` is indeed clever, though I understand it’s not ideal. It seems like a specific requirement or limitation of how the new React SDK handles query parameters, therefore, I will try to reproduce this at the SDK level and provide you with further updates as soon as possible.

Thanks for your cooperation!

---

<div class="post-metadata">

**Author:** ![kacey](https://avatars.discourse-cdn.com/v4/letter/k/0ea827/32.png) [@kacey](https://forum.builder.io/u/kacey)\
**Post date:** [February 16, 2024, 5:59pm UTC](https://forum.builder.io/t/new-sdk-returning-different-then-the-old-sdk/4975/9 "2024-02-16T17:59:14Z")

</div>

Thanks Manish and no worries.

I like the new SDK and the switch from using the query API to the content API was news to me as well. Your responses helped me put together my work around so I appreciate that 🙂

---

<div class="post-metadata">

**Author:** ![kacey](https://avatars.discourse-cdn.com/v4/letter/k/0ea827/32.png) [@kacey](https://forum.builder.io/u/kacey)\
**Post date:** [February 20, 2024, 1:45am UTC](https://forum.builder.io/t/new-sdk-returning-different-then-the-old-sdk/4975/10 "2024-02-20T01:45:16Z")

</div>

@manish-sharma I realized even your provided query is not working properly. It returns incorrect results. It seems it is returning all the results without honoring the `$elemMatch`. I thought it was correct before because at least the first couple are valid but the last couple entries should not be returned in the response.

This is a really time consuming issue we are trying to hack together with a work around; we would really appreciate some support on this and/or some prioritization. I would not recommend the new SDK if this relatively simple function can’t be supported and I am surprised no one else has brought this up. I imagine most users are still using the old SDK and that is probably why?

---

<div class="post-metadata">

**Author:** ![manish-sharma](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@manish-sharma](https://forum.builder.io/u/manish-sharma)\
**Post date:** [February 20, 2024, 7:49pm UTC](https://forum.builder.io/t/new-sdk-returning-different-then-the-old-sdk/4975/11 "2024-02-20T19:49:24Z")

</div>

Hello @kacey,

It appears that there may be an issue with how the `$elemMatch` option is being set in the request for gen2. We’re currently in the process of comparing the actual API requests for both SDK versions, gen1 and gen2.

We’ll provide you with an update as soon as we have more information. Thank you for your collaboration and patience!

---

<div class="post-metadata">

**Author:** ![kacey](https://avatars.discourse-cdn.com/v4/letter/k/0ea827/32.png) [@kacey](https://forum.builder.io/u/kacey)\
**Post date:** [February 20, 2024, 8:06pm UTC](https://forum.builder.io/t/new-sdk-returning-different-then-the-old-sdk/4975/12 "2024-02-20T20:06:31Z")

</div>

Thank you Manish; let me know how if I can help in anyway. We poked quite a bit around trying to get it working.

Will check back in later this week if I have not heard back as its a blocking issue for some of our work

---

<div class="post-metadata">

**Author:** ![kacey](https://avatars.discourse-cdn.com/v4/letter/k/0ea827/32.png) [@kacey](https://forum.builder.io/u/kacey)\
**Post date:** [February 23, 2024, 4:22pm UTC](https://forum.builder.io/t/new-sdk-returning-different-then-the-old-sdk/4975/13 "2024-02-23T16:22:05Z")

</div>

@manish-sharma Any updates on this?

---

<div class="post-metadata">

**Author:** ![manish-sharma](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@manish-sharma](https://forum.builder.io/u/manish-sharma)\
**Post date:** [February 27, 2024, 4:31am UTC](https://forum.builder.io/t/new-sdk-returning-different-then-the-old-sdk/4975/14 "2024-02-27T04:31:31Z")

</div>

Hello @kacey,

We are working on this internally, I’m happy to confirm that I was able to reproduce the issue with the **elemMatch** operator and have raised a ticket for our team to further investigate and offer us a workaround. I’ll try to prioritize this and update you as soon as we have made any progress.

In the meantime, we suggest exploring alternative approaches to achieve the query’s objective without relying on **elemMatch**.

Thanks for your cooperation!

---

<div class="post-metadata">

**Author:** ![kacey](https://avatars.discourse-cdn.com/v4/letter/k/0ea827/32.png) [@kacey](https://forum.builder.io/u/kacey)\
**Post date:** [February 28, 2024, 5:13pm UTC](https://forum.builder.io/t/new-sdk-returning-different-then-the-old-sdk/4975/15 "2024-02-28T17:13:02Z")

</div>

This is tough to explore a work around but I will try.  
We do not have a solid grasp of what query options work and in what syntax they work so its hard to even explore any options. We would need updated docs and confirmation that query operators were tested to really do this in any efficient matter.

The functionality we want is based on “related posts” in a blog. We want to query for all posts that have a shared category as a given post.

---

<div class="post-metadata">

**Author:** ![kacey](https://avatars.discourse-cdn.com/v4/letter/k/0ea827/32.png) [@kacey](https://forum.builder.io/u/kacey)\
**Post date:** [March 5, 2024, 5:40pm UTC](https://forum.builder.io/t/new-sdk-returning-different-then-the-old-sdk/4975/16 "2024-03-05T17:40:02Z")

</div>

@manish-sharma Are there any updates to this?

We have a potential path forward but its far from ideal. We are building a separate service that basically syncs all our builder io entries and then we query that instead which defeats the purpose of the headless CMS functionality to an extent. Also building a separate service would not be an option for most 😅

---

<div class="post-metadata">

**Author:** ![manish-sharma](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@manish-sharma](https://forum.builder.io/u/manish-sharma)\
**Post date:** [March 5, 2024, 6:02pm UTC](https://forum.builder.io/t/new-sdk-returning-different-then-the-old-sdk/4975/17 "2024-03-05T18:02:31Z")

</div>

Hello @kacey,

We completely understand your concerns, and please rest assured that we are actively working on resolving this issue. It has already been escalated to our product team, and I’ll personally ensure to keep you updated as soon as we make any progress.

We appreciate the temporary workaround you’ve explored and your cooperation in this matter.

Best regards,

---

<div class="post-metadata">

**Author:** ![manish-sharma](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@manish-sharma](https://forum.builder.io/u/manish-sharma)\
**Post date:** [September 5, 2024, 11:39am UTC](https://forum.builder.io/t/new-sdk-returning-different-then-the-old-sdk/4975/18 "2024-09-05T11:39:40Z")

</div>

Hello,

Our development team has fixed this issue.

Thank you.
