Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Algolia::AlgoliaHttpError (Unknown parameter: headers) #435

Open
breiko83 opened this issue Aug 31, 2023 · 6 comments
Open

Algolia::AlgoliaHttpError (Unknown parameter: headers) #435

breiko83 opened this issue Aug 31, 2023 · 6 comments

Comments

@breiko83
Copy link

Trying to add a custom header to search request as documented in Algolia docs doesn't seem to work:

res = index.search('', {
  headers: {
    # Replace `XX.XXX.XXX.XXXX` with your user's IP address
    'X-Forwarded-For': 'XX.XXX.XXX.XXX'
  }
})

Algolia::AlgoliaHttpError (Unknown parameter: headers)

Any suggestions?

@DevinCodes
Copy link
Contributor

Hi @breiko83 ,

are you on the latest version of the algoliasearch-rails gem? If not, which versions do you have in your lockfile for algoliasearch-rails and the algolia gem?

Thanks!

@breiko83
Copy link
Author

breiko83 commented Aug 31, 2023

algoliasearch-rails (2.2.2)
algolia (2.3.2)

@DevinCodes
Copy link
Contributor

I believe your code should work in that case, could you provide some more context please that could help reproduce the issue?

@breiko83
Copy link
Author

Sure here is what my code looks like:

include AlgoliaSearch
search("jordan",{clickAnalytics: true})
# works

search("jordan",{clickAnalytics: true, headers: {foo:"bar"}})
# return *** Algolia::AlgoliaHttpError Exception: Unknown parameter: headers

@DevinCodes
Copy link
Contributor

Instead of calling search directly, could you try with calling index.search please? The search method indeed seems to not accept search options for now as it will pass everything as a search option instead of moving the headers key towards the request headers.

@breiko83
Copy link
Author

The problem with this is the class response.

search('jordan').class -> AlgoliaSearch::Pagination::Kaminari
# this is what I need

index.search('jordan',headers: {foo:"bar"}).class -> Hash
# headers works but response is a Hash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants