Im trying to list an item on ebay with the Ebay Tradding API using php and CURL.
XML Request and CURL syntax seems fine to me, but API returns Invalid job context type
error.
I suppose I'm missing something in the Header.
My request code is following:
$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);
And the response is:
<?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>
When I tried the same XML with API explorer. The request went through.
Some issue with the CURL I suppose.
Your specify X-EBAY-API-CALL-NAME as AddItems
Your XML is an AddItemRequest
These must match. AddItem & AddItems are 2 different calls.