0

I'm having an issue where the NDC API returns errors when special characters are submitted in the search parameter.

I working on a product that contains a search box that allows the user to lookup medication information. The end users are not restricted right now in what they are allowed to enter into the search box. The information that they enter is surrounded in quotes because I want the users to search for the exact information. All spaces are turned into "+". Finally, any outstanding special characters are converted into their percent codes.

This is the code that we use to form the string

SearchText = Uri.EscapeDataString(SearchText);

if (!(this.SearchText.StartsWith("\"") && (this.SearchText.EndsWith("\""))))
{
    this.SearchText = "\"" + this.SearchText;
    this.SearchText = this.SearchText + "\"";
}

SearchText = "generic_name:" + SearchText + "+" + "brand_name:" + SearchText;

return string.Format("?search=({0})+AND+listing_expiration_date:[{1}+TO+9999-12-31]&limit={2}&sort=listing_expiration_date:desc&skip={3}", SearchText, DateTime.Today.ToString("yyyy-MM-dd"), this.PageSize > 0 ? this.PageSize : 100, RecordStart);

When I test with random special characters thrown in, I get error 400 Bad Request responses from the API.

The OpenFDA website doesn't have any information about what characters are allowed in their parameters and I haven't been able to find any standard online. Does anyone know what characters are allowed in the parameters?

  • Hi Matthew, I'm Jack with the openFDA team. I'm looking into compiling a list of allowed characters, but while I'm doing that research, can you post an example query returning a 400 error for you? Thanks! – Jack Finch yesterday

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.