Search query encoding ampersand

thisconnectthisconnect Member Posts: 30 ✭
hi,

if i want to look up a product by name, i use this PHP to generate the API url string:

"Item.json?limit=10&description=~,".rawurlencode("%".$search."%");

(i tried plain 'urlencode()' and double encoding 'urlencode(urlencode())' too)

when $search includes an ampersand &, no products are found.

i.e. search for 'B&W Speaker' does not give me a result, but 'W Speaker' does.

any ideas in how to encode a string with & in it properly?

thx!
maarten

2 comments

  • gregaricangregarican Member Posts: 926 
    Can you try HTML escaping it as %26 to see if that works?
  • thisconnectthisconnect Member Posts: 30 ✭

    i'm still not finding the correct way if searching a product through the API...

    example:

    i want to find this: "Coco & Pine - badcape Colette Tetra" (exact copy of "description" field in Lightspeed Retail)

    so my search string looks like this:

    Item.json?limit=30&load_relations=["Images"]&or=description%3D~,%25Coco%20%26%20Pine%20-%20badcape%20Colette%20Tetra%25|systemSku%3DCoco%20%26%20Pine%20-%20badcape%20Colette%20Tetra

    is is rawurlencoded and the description is pre- and appended by % (%25)

    nothing is found...

    even if i try searching for "badcape Colette Tetra" (part of description, without any special characters), i do not get results?

    but when i search for "Colette Tetra" (smaller part) i do get the product in the results!

    that looks very random to me...

    also have problems with single quotes in search:

    example: Baby's Only

    encoded to: Baby%27S%20Only -> no results (backslashing does not work either)

    anyone has more info?

Sign In or Register to comment.