Expand my Community achievements bar.

How to create persist url graphql with variable array of object

Avatar

Level 2

Hello i have query variable like this

VinceLu_0-1722571364637.png

 

 {
"tagFilter": [
{
"value": "ctf:ring"
}
]
}

 

and i want to copy url /graphql/execute.json/testingtemplate/collections;tagFilter=[{value: ctf:ring}]

and this encode
graphql/execute.json/testingtemplate/collections%3BtagFilter=[%7Bvalue:%20ctf:ring%7D]

and i get error this. how to create url if variable array of object?

VinceLu_1-1722571539578.png

 





10 Replies

Avatar

Community Advisor

Hi,

 

You need to encode entire query parameters ensuring special characters are encoded correctly, like below

 

const query = {
  tagFilter: [
    {
      value: "ctf:ring"
    }
  ]
};

const encodedQuery = encodeURIComponent(JSON.stringify(query));
const url = `/graphql/execute.json/testingtemplate/collections;tagFilter=${encodedQuery}`;

console.log(url);
// Output: /graphql/execute.json/testingtemplate/collections;tagFilter=%5B%7B%22value%22%3A%22ctf%3Aring%22%7D%5D

Avatar

Level 2

yes but it's still error.

i have try url like this but cannot /graphql/execute.json/testingtemplate/collections;tagFilter=%5B%7B%22value%22%3A%22ctf%3Aring%22%7D%5D

VinceLu_0-1722847596840.png

 

Avatar

Level 8

Please check this https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/headless/graphql... 
Something like this might work.

/graphql/execute.json/testingtemplate/collections%3BtagFilter%3D[%7B"value":"ctf:ring"%7D]

 

Avatar

Level 2

This is not work too. i'm confused

const query = {
tagname: [
{
"value": "collection:ring/bracelet"
},
{
"value": "collection:ring/earing"
}
]
};
 
const encodedQuery = encodeURIComponent(JSON.stringify(query));
 

Avatar

Level 8

Hi @VinceLu 
I checked the implementation of StringArrayFilterExpression and tried some samples.

Could you please try this :

/graphql/execute.json/testingtemplate/collections%3BtagFilter=%7B"values":["collection:ring/bracelet","collection:ring/earing"]%7D


For passing a single value, it will have to be passed as value instead of values

/graphql/execute.json/testingtemplate/collections%3BtagFilter=%7B"value":"collection:ring/earing"%7D

I believe this should work and hope this helps. 

Avatar

Level 2

Hii thanks for help me.

/graphql/execute.json/CTF-MOBILE/ProductList%tagname=%7B"values":["collection:ring/ring"]%7D



this is work for single value , but for multiple i'm still confused. i have no item if have 2 value

/graphql/execute.json/CTF-MOBILE/ProductList%tagname=%7B"values":["collection:ring/ring", "collection:ring/earing"]%7D


i don't know why if i put 2 items i can't get the item. just return empty

VinceLu_0-1723519576850.png

in the playground i can get item

VinceLu_1-1723519661289.png

can you help me for multiple value?

Avatar

Level 2

not work.

and i have encode too but not working for array

const query = {
tagname: [
{
"value": "collection:ring/bracelet"
},
{
"value": "collection:ring/earing"
}
]
};
 
const encodedQuery = encodeURIComponent(JSON.stringify(query));
 
console.log(url);

Avatar

Administrator

@VinceLu 

Did you find the suggestions helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!



Kautuk Sahni