使用Quickbooks Online V2过滤返回401 ErrorCode = 003200,空体帖子完美运行

时间:2013-09-24 19:42:41

标签: ruby api oauth intuit-partner-platform quickbooks-online

我们正尝试使用Ruby 1.9.3 (不是RoR)与QuickBooks Online V2 api集成。 使用API ExplorerEmployee endpoint文档,我们可以使用Google Signet OAuth Gem获得一个简单的测试员工列表。

require 'signet'
require 'signet/oauth_1/client'

#intialize oauth1 client
@client = Signet::OAuth1::Client.new(
    :temporary_credential_uri => "https://oauth.intuit.com/oauth/v1/get_request_token",
    :authorization_uri => "https://appcenter.intuit.com/Connect/Begin",
    :token_credential_uri => "https://oauth.intuit.com/oauth/v1/get_access_token",
    :client_credential_key => 'qyprdPEfJqU7eOze0Fby9iYhrUS5DQ',
    :client_credential_secret => 'fuXsasJo4TrTEd3Yhv4TeMUizmtguh0JioIB5r2I',
    :callback => "http://localhost:3000/callback/general"
)

@client.token_credential_key = 'qyprdJUtDSk7owxVfZlq7JeWO1mtpHBkSMD5GhB02PwIC6N0'
@client.token_credential_secret = 'Rq2ekgQWWL9frZAKpcgWef291mR0J5HBE354u5F3'

#setup request
original_request = [
    'POST',
    'https://qbo.sbfinance.intuit.com/resource/employees/v2/791630875',
    # we also tried this url 'https://qbo.intuit.com/qbo28/resource/employees/v2/791630875',
    [
        ['Content-Type', 'application/x-www-form-urlencoded'],
    ],
    []
]
#execute request
response = @client.fetch_protected_resource(:request => original_request)
puts response.body

正如您所看到的,请求非常简单。 但是,一旦我们在正文中创建了一个带过滤器的请求,我们就会收到一个HTML页面,其中包含以下错误:HTTP Status 401 - message=Exception authenticating OAuth; errorCode=003200; statusCode=401

#setup request
original_request = [
    'POST',
    'https://qbo.intuit.com/qbo28/resource/employees/v2/791630875',
    #'https://qbo.sbfinance.intuit.com/resource/employees/v2/791630875',
    [
        ['Content-Type', 'application/x-www-form-urlencoded'],
    ],
    ["Filter=Name :EQUALS: Doe"]
]

我们正在使用Google OAuth gem,并且使用这些工具验证了签名生成是否正确:LinkedIn Oauth Test ConsoleBeginners guide to OAuth signing requests。他们都验证了Signet生成的签名对于我提供的身体是否正确。

我看了几个SO问题:

但没有任何效果。任何帮助将不胜感激,我们愿意使用第三方宝石,如quickeebooks,但我们不愿意。我想我在这里只是缺少一些简单的东西。

请向我提供以下项目,以便我确认工作答案:

  • 您的请求参数,包括uri,标题,正文和确切的客户端以及访问令牌(仅限开发者应用令牌,我需要验证我是否可以生成完全相同的请求,包括签名)
  • 您用于生成HMAC-SHA1签名的basetring。它看起来像

POST&https%3A%2F%2Fqbo.intuit.com%2Fqbo28%2Fresource%2Femployees%2Fv2%2F7916308‌​75&Filter%3DName%2520%253AEQUALS%253A%2520David%2520Test%26oauth_consumer_key%3Dq‌​yprdPEfJqU7eOze0Fby9iYhrUS5DQ%26oauth_nonce%3D-1787433535548338293%26oauth_signat‌​ure_method%3DHMAC-SHA1%26oauth_timestamp%3D1380089100%26oauth_token%3DqyprdJUtDSk‌​7owxVfZlq7JeWO1mtpHBkSMD5GhB02PwIC6N0%26oauth_version%3D1.0

  • 您的回复,包括标题和正文数据

2 个答案:

答案 0 :(得分:0)

我曾尝试对员工端点使用过滤器查询。它工作正常。

编辑 - 与Employee API端点相关的共享端点,过滤器和结果集

https://qbo.intuit.com/qbo28/resource/employees/v2/791926875

Filter= Name :EQUALS: Manas Mukherjee

标题 - "Authorization: OAuth oauth_token="2eRrd7LhEtHrM1CrqWvy1kmSgeukEgFxW99E1xwhSsLCp1JB", oauth_consumer_key="qyprdXsaKh0a132eNs7NTJLufjfrzm", oauth_version="1.0", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1380084612", oauth_nonce="1556081845430558974", oauth_signature="IMjh%2FTx%2F7GMFDE6WQqZK8b6apjI%3D"[\r][\n]"

Content-Type: application/x-www-form-urlencoded

数据集

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<qbo:SearchResults xmlns="http://www.intuit.com/sb/cdm/v2" xmlns:qbp="http://www.intuit.com/sb/cdm/qbopayroll/v1" xmlns:qbo="http://www.intuit.com/sb/cdm/qbo">
    <qbo:CdmCollections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Employees">
        <Employee>
            <Id idDomain="QBO">20</Id>
            <SyncToken>0</SyncToken>
            <MetaData>
                <CreateTime>2013-09-24T21:37:22-07:00</CreateTime>
                <LastUpdatedTime>2013-09-24T21:37:22-07:00</LastUpdatedTime>
            </MetaData>
            <Name>Manas Mukherjee</Name>
            <Address>
                <Line1>ABC Str</Line1>
                <City>London</City>
                <PostalCode>4353543</PostalCode>
                <GeoCode>LAT=51.5148382,LNG=-0.1264144</GeoCode>
            </Address>
            <GivenName>Manas</GivenName>
            <MiddleName>Kr</MiddleName>
            <FamilyName>Mukherjee</FamilyName>
            <ShowAs>Manas Kr Mukherjee</ShowAs>
            <BillableTime>false</BillableTime>
        </Employee>
    </qbo:CdmCollections>
    <qbo:Count>1</qbo:Count>
    <qbo:CurrentPage>1</qbo:CurrentPage>
</qbo:SearchResults>

使用您的令牌

的OAuth标头
"Authorization: OAuth oauth_token="qyprdJUtDSk7owxVfZlq7JeWO1mtpHBkSMD5GhB02PwIC6N0", oauth_consumer_key="qyprdPEfJqU7eOze0Fby9iYhrUS5DQ", oauth_version="1.0", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1380089100", oauth_nonce="-1787433535548338293", oauth_signature="Vj67xMVhSKGjVSmGyOxt7SVv0i8%3D"[\r][\n]"

端点 - https://qbo.intuit.com/qbo28/resource/employees/v2/791630875

将数据发布到终点:Filter= Name :EQUALS: David Test

内容类型:application/x-www-form-urlencoded

工作正常 感谢

答案 1 :(得分:0)

请参阅此示例fiddler请求,其中包含用于QBO中的项目的过滤器。我不能在这里粘贴提琴手日志。您可以为员工进行类似的操作。过滤器应该进入正文并对标题进行编码:

请求 - 发布https://qbo.intuit.com/qbo1/resource/items/v2/723488155

HTTP / 1.1 内容类型:application / x-www-form-urlencoded 授权:OAuth的组oauth_token = “lvprdgF9q4mSQx5A6lKNm3NISXvwIpF16z”,oauth_nonce = “3740352e-20a4-4d45-af4f-2b783ee20e60”,oauth_consumer_key = “qyprd7I5WvVnPoiBh1ejZn”,oauth_signature_method = “HMAC-SHA1”,oauth_timestamp = “1377106651”,oauth_version = “1.0”,oauth_signature = “1OAJXk5uH0sEpYpdhh%2BDMzjQFEs%3D” 主持人:qbo.intuit.com 内容长度:28 期待:100-continue

页次= 1&安培; ResultsPerPage = 100

响应标题 - HTTP / 1.1 200好的 日期:2013年8月21日星期三17:37:31 GMT 服务器:Apache Set-Cookie:qboeuid = 10.129.32.5.1377106651774076;路径= /;到期=星期四,21日 - 8月14日17:37:31 GMT;域= .intuit.com Set-Cookie:JSESSIONID = 82DE11473B5246497B9FDCD8A6DA4C45.c1-pprdqboas30j;路径= /;安全;仅Http 变化:接受编码 Content-Type:application / xml; charset = UTF-8 内容长度:32525