question

chri184158 avatar image
0 Likes"
chri184158 asked

Laravel Cronjob using API

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: &quot;; nested exception is:
org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 254; Open quote is expected for attribute &quot;xmlns&quot; associated with an element type &quot;GetOrdersRequest&quot;.&quot;.</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 &quot;xmlns&quot; associated with an element type &quot;GetOrdersRequest&quot;.</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.

PHPorderorderapilaravel
· 5
10 |600

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

michab2003 avatar image michab2003 commented ·
first, if your app does not need the user to authenticate, it's much easier to use the long living Auth'n'auth token instead of this whole oauth overhead. here's an sdk, but I wasn't able to test everything with php 8, you can try: https://github.com/michabbb/php-ebay-sdk (see different branches) - this sdk doesn't work with oauth, because if you are not developing a public app, there is no need for oauth. if you are working for some customers, they should trust you creating an Auth'n'auth token.
0 Likes 0 ·
chri184158 avatar image chri184158 michab2003 commented ·

Thanks. I wasn't sure if Auth'n'auth will be dropped in the future and wanted to go with the modern solution.

I tried to follow this https://developer.ebay.com/api-docs/static/oauth-trad-apis.html
But not sure if my oauth app token expires in this case.

0 Likes 0 ·
michab2003 avatar image michab2003 chri184158 commented ·

that's more than unlogical lol. using an old api doesn't get modern by using oauth :)) you're still using a "not modern api" :) and if oauth is not needed, it's simply said "stupid" dealing with all that overhead. but hey, good luck ;)

0 Likes 0 ·
Show more comments
sing-harv avatar image
0 Likes"
sing-harv answered

Maybe if you try to remove all new lines/tabs and send the body as a single string as below + dump out the $response to check what is actually being sent to the eBay endpoint.

$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>';

I do use User/Seller Auth token in these calls as part of the XML request but not the header

$xmlRequest = '<RequesterCredentials><eBayAuthToken>'.$this->authToken.'</eBayAuthToken></RequesterCredentials>'.$body
10 |600

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

erjac_121 avatar image
0 Likes"
erjac_121 answered

This works really well for us, thank you!


10 |600

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.