I want to translate a curl request to a Typhoeus request. Curl request:
@response = %x{curl -i https://track.customer.io/api/v1/customers/#{@client.id} \
-X PUT \
-H "Content-Type: application/json" \
-u #{APP_CONFIG[:customerio][:api_key]}:#{APP_CONFIG[:customerio][:api_key]} \
-d '{
"email":"#{@client.email}",
"name":"#{@client.name}",
"id":"#{@client.id}",
"created_at":"#{@client.created_at.to_time.to_i}"}'}
Typhoeus request:
request = Typhoeus::Request.new(
"https://track.customer.io/api/v1/customers/4",
ssl_verifypeer: false,
method: :put,
headers: {
"Content-Type" => "application/json",
"user_agent" => "#{APP_CONFIG[:customerio][:api_key]}:#{APP_CONFIG[:customerio][:api_key]}"},
body: '{
"email":"[email protected]",
"name":"Name is here",
"id":"4",
"created_at":"#{Time.now}"}')
When I run the Typhoeus request, I get a response saying unauthorized
which I believe indicates my user info is incorrect. How can I set the -u flag equivalent in a Typhoeus request?
Use the
userpwd
key within the options hash, e.g: