none
Which characters use to replace in REST API query RRS feed

  • Question

  • If Special characters(like $Filter=Title eq Brother's & Son. LTD) exist in query then how can i replace special characters in REST API call.
    Wednesday, May 18, 2016 11:27 AM

Answers

  • Hi Sushantha,

    & and . characters are not encoded by default in URL. So we have to must specify the encoded values for those special characters.

    I think, this answers your question, if not please let me know your comments.


    Regards,
    Shantha Kumar .T | MCPD - SharePoint Developer 2010 | MCITP - SharePoint Administrator 2010
    (B) Shantha Kumar's Blog | (T)Follow me

    • Marked as answer by Sushanth Y Friday, May 20, 2016 5:45 AM
    Wednesday, May 18, 2016 1:38 PM
  • No there is no way to get this done without the URI encode. 

    If not encoded then it will be treated as the url tokens and it will break your ODATA query.


    ---
    Rajesh
    rjesh.com| @rjesh
    You don't need to buy me a beer, if helpful just smile, vote, and mark it as answer.

    • Marked as answer by Sushanth Y Thursday, May 19, 2016 2:07 PM
    Wednesday, May 18, 2016 8:41 PM

All replies

  • The special characters should be encode to UTF-8 format. Please find the below table to replace the special character.

    Character Encode (UTF-8)
    space %20
    ! %21
    " %22
    # %23
    $ %24
    % %25
    & %26
    ' %27
    ( %28
    ) %29
    * %2A
    + %2B
    , %2C
    - %2D
    . %2E
    / %2F

    For more Reference: http://www.w3schools.com/tags/ref_urlencode.asp


    Regards,
    Shantha Kumar .T | MCPD - SharePoint Developer 2010 | MCITP - SharePoint Administrator 2010
    (B) Shantha Kumar's Blog | (T)Follow me


    • Edited by Shantha Kumar T Wednesday, May 18, 2016 1:01 PM Replace % position
    Wednesday, May 18, 2016 12:11 PM
  • Wow..thanks.
    Wednesday, May 18, 2016 12:14 PM
  • I replaced with Encode above specified, in my string text but it is not worked for me. Rest API call was not showing any results.

    EX: I Replaced F&G with F26%G

    Query string is https://myurl/_api/web/lists/lists/getByTitle('TestList')/items?$select=ID,Title&$filter=Title eq F26%G

    Thanks.

    Wednesday, May 18, 2016 12:40 PM
  • Hi Sushanth,

    In the REST API you have tried has two lists in URL. Remove that and also use Single quote (') for title value in url.

    Remove or replace the bold ones.

    https://myurl/_api/web/lists/lists/getByTitle('TestList')/items?$select=ID,Title&$filter=Title eq F26%G

    Please try the below url,

    https://myurl/_api/web/lists/getByTitle('TestList')/items?$select=ID,Title&$filter=Title%20eq%20%27F%26G%27

    Decoded URL:

    https://myurl/_api/web/lists/getByTitle('TestList')/items?$select=ID,Title&$filter=Title eq 'F&G'


    Regards,
    Shantha Kumar .T | MCPD - SharePoint Developer 2010 | MCITP - SharePoint Administrator 2010
    (B) Shantha Kumar's Blog | (T)Follow me


    Wednesday, May 18, 2016 12:59 PM
  • To answer your initial question

    You need to escape single quote with additional single quote like $Filter=Title eq Brother''s & Son. LTD

    When you url encode, then $filter=Title%20eq%20%27Brother%27%27s%20%26%20Son.%20LTD%27


    ---
    Rajesh
    rjesh.com| @rjesh
    You don't need to buy me a beer, if helpful just smile, vote, and mark it as answer.

    Wednesday, May 18, 2016 1:15 PM
  • That is working but there is any way or procedure to get results without using encode/decode.

    Wednesday, May 18, 2016 1:26 PM
  • Hi Sushantha,

    & and . characters are not encoded by default in URL. So we have to must specify the encoded values for those special characters.

    I think, this answers your question, if not please let me know your comments.


    Regards,
    Shantha Kumar .T | MCPD - SharePoint Developer 2010 | MCITP - SharePoint Administrator 2010
    (B) Shantha Kumar's Blog | (T)Follow me

    • Marked as answer by Sushanth Y Friday, May 20, 2016 5:45 AM
    Wednesday, May 18, 2016 1:38 PM
  • No there is no way to get this done without the URI encode. 

    If not encoded then it will be treated as the url tokens and it will break your ODATA query.


    ---
    Rajesh
    rjesh.com| @rjesh
    You don't need to buy me a beer, if helpful just smile, vote, and mark it as answer.

    • Marked as answer by Sushanth Y Thursday, May 19, 2016 2:07 PM
    Wednesday, May 18, 2016 8:41 PM
  • Thanks for the double single quote tip.  Helped me get around a single quote in the List name. 
    Thursday, April 12, 2018 6:40 PM