Ebay Trading API错误AddItem服务

时间:2017-07-28 18:59:53

标签: php api soap ebay

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

XML请求和CURL语法对我来说似乎很好,有人可以指导我还缺少其他内容。

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

我们将不胜感激。

$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​​资源管理器尝试相同的XML时。请求通过了。

我认为CURL存在一些问题。

1 个答案:

答案 0 :(得分:1)

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

您的XML是AddItemRequest

这些必须匹配。 AddItem&amp; AddItems是两个不同的调用。