# Call API using curl in seed.rb

**URL:** <https://discuss.rubyonrails.org/t/call-api-using-curl-in-seed-rb/71345>\
**Category:** rubyonrails-talk\
**Created:** [November 17, 2015, 3:14pm UTC](https://discuss.rubyonrails.org/t/call-api-using-curl-in-seed-rb/71345 "2015-11-17T15:14:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daynthan\_Kabilan](https://avatars.discourse-cdn.com/v4/letter/d/a88e57/32.png) [@Daynthan\_Kabilan](https://discuss.rubyonrails.org/u/Daynthan_Kabilan)\
**Post date:** [November 17, 2015, 3:14pm UTC](https://discuss.rubyonrails.org/t/call-api-using-curl-in-seed-rb/71345/1 "2015-11-17T15:14:00Z")

</div>

Hi,

I need to call API using curl in seed.rb

Before i have used API like

response = HTTParty.get(“[https://pipeline.locallabs.com/api/v1/organizations?access\_key=XXXXXX](https://pipeline.locallabs.com/api/v1/organizations?access_key=XXXXXX)”)

i don’t know how to call API using curl in ssed.rb

now my client assign one new domain and mentioned this was working for him.

curl -H’Authorization: KEY’ [https://pipeline-api.locallabs.com/api/v1/organizations?min\_updated\_at='2015-11-13&limit=10](https://pipeline-api.locallabs.com/api/v1/organizations?min_updated_at=%272015-11-13&limit=10)’

Any one know how to call API using curl in seed.rb please let me know.

Thanks!

Daya.

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [November 18, 2015, 10:02am UTC](https://discuss.rubyonrails.org/t/call-api-using-curl-in-seed-rb/71345/2 "2015-11-18T10:02:03Z")

</div>

Why use curl instead of a ruby method (e.g. HTTPary since you are already used to that) ? You can shell out with system, popen etc but that seems like an inferior solution unless there is some other constraint you haven’t mentioned. You can pass headers by doing something like HTTPParty.get(“http://…”, headers: {foo: ‘bar’})

Fred

---

<div class="post-metadata">

**Author:** ![Daynthan\_Kabilan](https://avatars.discourse-cdn.com/v4/letter/d/a88e57/32.png) [@Daynthan\_Kabilan](https://discuss.rubyonrails.org/u/Daynthan_Kabilan)\
**Post date:** [November 23, 2015, 4:09pm UTC](https://discuss.rubyonrails.org/t/call-api-using-curl-in-seed-rb/71345/3 "2015-11-23T16:09:17Z")

</div>

Hi Fred,

Thanks for your reply.

Actually i got the API result form chrome postman.([https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en](https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en))

Here i gave the URL like [https://pipeline-api.locallabs.com/api/v1/organizations?min\_updated\_at='2015-11-13&limit=10](https://pipeline-api.locallabs.com/api/v1/organizations?min_updated_at=%272015-11-13&limit=10)’ and i set the authorization key in header an got the Exact result.

But i don’t know how to access this url in Rails. If i give this URL in browser then return unauthorized result.

Please suggest me.

Thanks!
