I try to do my first ebay API request and the tons of endless doc pages are abit overwhelming. And it's always a mix or SOAP and xml, interactive oauth when I search for some issue.
I want to do scheduled API requests with Laravel 9 to fetch new orders, import them in our system them and send fulfillment update to ebay when shipped.
First issue is the oAuth. I generated an Application Token which seems to be the way to go for cli cronjobs. Will this token expire? It's so difficult since almost every doc is about interactive oauth for browser apps.
2nd problem is my first try to use the GetOrders call.
$body = '<?xml version="1.0" encoding="utf-8"?> <GetOrdersRequest xmlns="urn:ebay:apis:eBLBaseComponents"> <CreateTimeFrom>2018-10-01T20:34:44.000Z</CreateTimeFrom> <CreateTimeTo>2022-05-30T20:34:44.000Z</CreateTimeTo> <OrderRole>Seller</OrderRole> </GetOrdersRequest>'; $response = Http::withHeaders([ 'Content-type' => 'text/xml;charset="utf-8"', 'Accept' => 'text/xml', 'Content-length' => strlen($body), 'X-EBAY-API-COMPATIBILITY-LEVEL' => 1225, 'X-EBAY-API-IAF-TOKEN' => config('services.ebay.application_token'), 'X-EBAY-API-APP-ID' => config('services.ebay.app_id'), 'X-EBAY-API-SITEID' => '0', 'X-EBAY-API-DETAIL-LEVEL' => 0, 'X-EBAY-API-CALL-NAME' => 'GetOrders', 'X-EBAY-API-REQUEST-ENCODING' => 'xml', ])->post(self::API_SANDBOX_URL, $body );
This returns an error:
<?xml version="1.0" encoding="UTF-8"?> <GetOrdersResponse xmlns="urn:ebay:apis:eBLBaseComponents"><Timestamp>2022-06-01T09:39:03.242Z</Timestamp><Ack>Failure</Ack><Errors><ShortMessage>XML Parse error.</ShortMessage><LongMessage>XML Error Text: "; nested exception is: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 254; Open quote is expected for attribute "xmlns" associated with an element type "GetOrdersRequest".".</LongMessage><ErrorCode>5</ErrorCode><SeverityCode>Error</SeverityCode><ErrorParameters ParamID="0"><Value>; nested exception is: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 254; Open quote is expected for attribute "xmlns" associated with an element type "GetOrdersRequest".</Value></ErrorParameters><ErrorClassification>RequestError</ErrorClassification></Errors><Version>1247</Version><Build>E1247_CORE_APIXO_19220561_R1</Build></GetOrdersResponse>
If I use rawurlencode on the body content I just a different error:
<?xml version="1.0" encoding="ISO-8859-1" ?><eBay> <EBayTime>2022-06-01 09:40:39</EBayTime><Errors> <Error> <Code>5</Code><SeverityCode>1</SeverityCode><Severity>SeriousError</Severity><Line>0</Line><Column>0</Column><ErrorClass>RequestError</ErrorClass><ShortMessage><![CDATA[XML Parse error.]]></ShortMessage> </Error> </Errors> </eBay>
I have no clue If I have to include the "RequesterCredentials eBayAuthToken" to the request xml sinceI'm not sure if I will get this token when I'm using an Application Token. All api example seems to be done for an interactive oauth and not for cronjobs.
If anybody has some ideas would be nice.