URL Encoding Special Characters in API requests

This issue of url encoding special characters is something you want to keep in mind with any form input you send to an API. An example of this with WorldCat Search API is if someone puts in a title search like "Kate & Leopold". The ampersand in this will cause the API to throw an error message if you don't URL encode it. The wisest way to handle this is to URL encode any form input that might have any special characters in it. Things like title, keyword are likely suspects.

However, OCLC Symbol also falls into this category as well because as you may or may not be aware that OCLC Symbols can have some non-alphanumeric characters in them. For example the OCLC Symbol for the library system nearest me is HT# . This creates an interesting issue when one is trying to make a request via WorldCat Search API or the WorldCat Registry which uses this OCLC Symbol. You see if you send the raw OCLC Symbol the query will fail. This is because the special character has to be be url encoded before it is sent to either of these APIs.

So in PHP you'd do this

urlencode('HT#')

Once you URL encode the character the APIs behave as expected and you can retrieve the data you need easily.

.

  • Karen Coombs

    Karen Coombs

    Senior Product Analyst