我尝试使用以下API在导轨中使用HTTParty gem
发布数据,
curl -X POST https://app.referralsaasquatch.com/api/v1/{tenant_alias}/user \
-u API_KEY: \
-H "Content-Type: application/json" \
-d '{
"id": "219065",
"accountId": "accc9065",
"referralCode": "BOBTESTERSON",
"email": "bob@example.com",
"imageUrl": "https://www.example.com/profiled/ab5111251125",
"firstName": "Bob",
"lastName": "Testerson" }'
实现这一目标的最佳方法是什么? 提前谢谢。
答案 0 :(得分:2)
解决方案看起来有点像这样,basic_auth
参数代表curl -u
部分。由于你只传递了api_key,所以下面应该可以解决问题。它看起来很奇怪,但它是要走的路:
class MyRequest
include HTTParty
base_uri 'https://testdomain.org/api/v1'
def self.execute(query)
post('/updates/create.json', :query => query, basic_auth: {username: "YOUR_API_KEY", password: ""})
end
end