How to set API key in curl


I am trying to do a GET request via curl_fetch_memory and I've set my credential in handle.
It is working on a normal url BUT now i am having issue doing GET to a url that requires API key.

Tried handle_setheaders BUT seems like it missed the user and password piece.

h <- new_handle()
handle_setopt(h, userpwd = [xxxx])
handle_setheaders(h, "API_Key" = [xxxx])
req <- curl_fetch_memory(url, handle = h)

Please advise.

I'm not familiar with curl, but the documentation mentions that:

Note that handle_setopt appends or overrides options in the handle, whereas handle_setheaders replaces the entire set of headers with the new ones.

Could that be an explanation? Also, I'm not sure the quotes around API_Key are necessary.

Thanks for the reply!
Yes, handle_setheaders does set the API and I think my issue here is more on the authenticate part where it is throwing not autorized.
I got this sorted out by adding httpauth = 1L into the handle_setopt which sets the authentication method to try initially.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.