【问题标题】:eBay Trading API AddItem call returns 'Invalid job context type' erroreBay 交易 API AddItem 调用返回“无效的工作上下文类型”错误
【发布时间】:2017-07-28 18:59:53
【问题描述】:

我正在尝试使用 php 和 CURL 使用 Ebay Tradding API 在 ebay 上列出一个项目。

XML 请求和 CURL 语法对我来说似乎很好,但 API 返回 Invalid job context type 错误。

我想我在标题中遗漏了一些东西。

我的请求代码如下:

$xml_string = '<?xml version="1.0" encoding="utf-8"?>
                        <AddItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">
                          <RequesterCredentials>
                            <eBayAuthToken>*Token*</eBayAuthToken>
                          </RequesterCredentials>
                          <ErrorLanguage>en_US</ErrorLanguage>
                          <WarningLevel>High</WarningLevel>
                          <Item>
                            <Title>'.$postdata['item_name'].'</Title>
                            <Description>'.$postdata['external_comments'].'</Description>
                            <PrimaryCategory>
                              <CategoryID>377</CategoryID>
                            </PrimaryCategory>
                            <StartPrice>'.$postdata['ebay_price'].'</StartPrice>
                            <CategoryMappingAllowed>true</CategoryMappingAllowed>
                            <Country>US</Country>
                            <Currency>USD</Currency>
                            <ConditionID>1000</ConditionID>
                            <DispatchTimeMax>3</DispatchTimeMax>
                            <ListingDuration>Days_7</ListingDuration>
                            <ListingType>Chinese</ListingType>
                            <PaymentMethods>PayPal</PaymentMethods>
                            <!--Enter your Paypal email address-->
                            <PayPalEmailAddress>jash389@gmail.com</PayPalEmailAddress>
                            <PictureDetails>
                              <PictureURL>http://pics.ebay.com/aw/pics/dot_clear.gif</PictureURL>
                            </PictureDetails>
                            <PostalCode>95125</PostalCode>
                            <Quantity>1</Quantity>
                            <ReturnPolicy>
                              <ReturnsAcceptedOption>ReturnsAccepted</ReturnsAcceptedOption>
                              <RefundOption>MoneyBack</RefundOption>
                              <ReturnsWithinOption>Days_30</ReturnsWithinOption>
                              <Description>If you are not satisfied, return the book for refund.</Description>
                              <ShippingCostPaidByOption>Buyer</ShippingCostPaidByOption>
                            </ReturnPolicy>
                            <ShippingDetails>
                              <ShippingType>Flat</ShippingType>
                              <ShippingServiceOptions>
                                <ShippingServicePriority>1</ShippingServicePriority>
                                <ShippingService>USPSMedia</ShippingService>
                                <ShippingServiceCost>2.50</ShippingServiceCost>
                              </ShippingServiceOptions>
                            </ShippingDetails>
                            <Site>US</Site>
                         </Item>
                        </AddItemRequest>';

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.ebay.com/ws/api.dll");
        $headers = array(
            'Content-Type: text/xml',
            'X-EBAY-API-COMPATIBILITY-LEVEL: 967',
            'X-EBAY-API-DEV-NAME: ',
            'X-EBAY-API-APP-NAME: ',
            'X-EBAY-API-CERT-NAME: ',
            'X-EBAY-API-SITEID: 2',
            'X-EBAY-API-CALL-NAME: AddItems'
        );

        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_POSTFIELDS, "xmlRequest=" . $xml_string);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        curl_setopt($ch, CURLOPT_POST, TRUE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);

响应是:

<?xml version="1.0" encoding="UTF-8"?>
  <AddItemsResponse xmlns="urn:ebay:apis:eBLBaseComponents">
  <Timestamp>2017-07-28T18:48:59.487Z</Timestamp>
  <Ack>Failure</Ack>
  <Errors>
      <ShortMessage>Invalid job context type</ShortMessage>
      <LongMessage>The job context object is not supported by Action Service Framework.</LongMessage>
     <ErrorCode>21843</ErrorCode>
     <SeverityCode>Error</SeverityCode>
     <ErrorParameters ParamID="0"><Value>AddItems</Value></ErrorParameters>
     <ErrorParameters ParamID="1"><Value>AddItemRequestType</Value></ErrorParameters>
     <ErrorClassification>RequestError</ErrorClassification>
 </Errors><Version>1021</Version><Build>E1021_UNI_API5_18478667_R1</Build></AddItemsResponse>

当我使用 API Explorer 尝试相同的 XML 时。请求已通过。

我认为 CURL 存在一些问题。

【问题讨论】:

    标签: php soap ebay-api


    【解决方案1】:

    您将 X-EBAY-API-CALL-NAME 指定为 AddItems

    您的 XML 是一个 AddItemRequest

    这些必须匹配。 AddItem 和 AddItems 是 2 个不同的调用。

    【讨论】:

    • 您好,感谢您的回复。今天想通了。我现在卡住的地方是运输详细信息部分。知道那里有什么。无论如何,谢谢!
    猜你喜欢
    • 1970-01-01
    • 2011-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 2016-05-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多