eBay Developers Program
  • Forums Sign in
  • My Account
    • My Developer Account
    • Solutions Directory
    • Applications Settings
  • Forums
    • Orders, Returns and Feedback
    • Java SDK for Trading API
    • Search
    • Selling
    • Talk to Your Fellow Devs
    • .Net SDK for Trading API
    • Tokens, Notifications, Messages
    • Feedback & Suggestions
  • Documentation
    • Release Notes
    • Finding API
    • Shopping API
    • Trading API
    • Large Merchant Services
    • Marketing Handbook
    • All Features Comparison
    • All API Documentation
  • Support
    • eBay SDKs
    • API Site Status
    • Program & News Blog
    • Compatible Application Check
    • Support Ticket
    • Knowledge Base
    • Developer Help Center
    • Search Details
  • Home
  • eBay Forums
  • eBay APIs: Search /
avatar image

Question by faustofausto94 · May 12, 2017 at 04:17 AM · corssearch-apicategoriesdomain

Is there a CORS support?

Hello, I'm trying to make a ws call in angularJS to the following url that from now on I will call mySearchUrl: http://open.api.ebay.com/Shopping?callname=GetCategoryInfo≈pid=myAppID&CategoryID=-1&IncludeSelector=ChildCategories&version=967&siteid=101

But when I try to make the from another domain it gives me a CORS error:

XMLHttpRequest cannot load mySearchUrl. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.mydomain.com' is therefore not allowed access.

So I fixed the problem using the:

$http.defaults.headers.common= {

'Access-Control-Allow-Origin': '*',

'Access-Control-Allow-Headers': 'X-Requested-With, Origin, Content-Type, X-Auth-Token',

'Access-Control-Allow-Methods': 'GET, PUT, POST, DELETE'

}

to modify the requests header and now the problem is:

XMLHttpRequest cannot load mySearchUrl. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://mydomain.com' is therefore not allowed access.

So I'm testing everything but I can't solve this problem. I also tested the URL from a CORS-test site and it doesn't work, so:

Can Anybody tell me if these ws calls are CORS enabled? how can I solve, please? Thank you very much for your help

People who like this

0
Comment
10 |600 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

6 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by clickimusprime · May 15, 2017 at 10:00 AM

There is no call to retrieve all categories. You have to walk the tree. There are other threads that discuss this. You should consider retrieving and caching category data as needed rather than preloading it all.

CORS doesn't apply to jsonp, so you don't need headers. eBay's system supports jsonp with the callbackname as I mentioned previously. You're probably handling the response directly instead of using the callback function.

Here's a simple example to fetch a category name via jsonp:

 <script>
 var appid = "YOURAPPID";
 
 $.ajax({
   dataType: "jsonp",
   method: "GET",
   url: "http://open.api.ebay.com/Shopping?callname=GetCategoryInfo&appid=" + appid + "&siteid=1&CategoryID=293&version=981&responseencoding=JSON&callbackname=jsonpcallback", 
 });
 
 function jsonpcallback(jsdata) { 
   console.log(jsdata);
   $("#output").html(jsdata.CategoryArray.Category[0].CategoryName);
 }
 
 </script>
 
 <div id="output">pending...</div>
 

Again, you shouldn't be doing it this way unless it's a private app. Instead, create a PHP (or whatever) page that does an API request and outputs the data you need to the screen in JSON/HTML/delimited. Then call the PHP page with AJAX to make the API request and get the data. Try to keep as much of the code as possible on the server side.

Comment

People who like this

0 · 1 show · Share
10 |600 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image faustofausto94 · May 16, 2017 at 01:52 AM 0
Share

You've been precious! Seriously, thank you very much for your tips. Have a nice day

avatar image

Answer by clickimusprime · May 12, 2017 at 06:19 AM

Use the jsonp callback option, see Making a Call at the top of the docs. Note that you are exposing your appid to clients this way.

The preferred way is to setup a script on your server that makes the request and then returns the results, then call that script with ajax. This keeps your appid private.

Comment

People who like this

0 · Share
10 |600 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by faustofausto94 · May 13, 2017 at 08:00 AM

@clickimusprime

You mean this page? https://developer.ebay.com/Devzone/finding/Concepts/MakingACall.html

maybe some code clarifies; this doesn't work:

 $scope.getSuperCategories = function(){
     var getSuperCategories = $http({
     url: mySearchUrl,
     dataType: 'jsonp',
     headers: {'Access-Control-Allow-Origin': '*',
             'Access-Control-Allow-Headers': 'X-Requested-With, Origin, Content-Type, X-Auth-Token',
             'Access-Control-Allow-Methods': 'GET, PUT, POST, DELETE'}
     }).then(function(result){
             $scope.superCategories = result.data;
     });
 };

with the following code, instead, CORS errors disappear:

 $.ajax({
     url: url,
     dataType: "jsonp",
     beforeSend: function(request) {
         request.setRequestHeader("Access-Control-Allow-Origin", '*');
     },
     success: function(root){
       main.superCategories = root;
     }
     });

but it gives me

 Uncaught SyntaxError: Unexpected token <

on the first line of the correct document containing ebay's data:

 <?xml version="1.0" encoding="UTF-8"?>

what's wrong with this? Thank you, I really appreciate this.

Comment

People who like this

0 · Share
10 |600 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by clickimusprime · May 14, 2017 at 08:06 AM

Can't tell what's wrong with your URL because you didn't post it. But since the response is XML, you probably didn't follow the instruction about how to request a JSON response.

Comment

People who like this

0 · Share
10 |600 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by xiang.developersupport · May 14, 2017 at 09:57 PM

Hi faustofausto94, Please note CORS and JSONP are general concepts in web development, instead of eBay specific feature.

Please note it does not make sense to set HTTP request headers, such as Access-Control-Allow-Origin and send it to the server. You should set such headers in the response from your own server side when your own server serves your request. Access-Control-Allow-Origin specifies which sites are allowed. Then after this request, you can send requests to the sites which are included in Access-Control-Allow-Origin.

From some point of view, JSONP can be also an option for CORS, but it's another topic. Maybe you would like to do some learning about CORS and JSONP by yourself.

Best Regards,

Comment

People who like this

0 · Share
10 |600 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by faustofausto94 · May 15, 2017 at 03:53 AM

@xiang.developersupport I know they're general concept, but you clarified me an important thing, thank you. @clickimusprime I dind't post the URL because I was testing a similiar URL. the definitive search I have to do is to get all categories(with child included). But I don't know the correct URL, maybe you can help me. I was testing with the GetCategoryInfo, but it returns only one child level:

http://open.api.ebay.com/Shopping?callname=GetCategoryInfo≈pid=MY-APP-ID&CategoryID=-1&IncludeSelector=ChildCategories&version=967&siteid=101&responseencoding=JSON

now I'm trying to get all categories, but I was wrong because I didn't know about the "reponseencoding=JSON" part. After adding it the CORS error didn't disappear but at least I don't have to parse xml. Now my target is to retrieve all categories using an URL: I read about the GetCategories but I dind't find a real solution using the URL to get ALL the existing categories. Do you know which URL to use, please? Thank you for your assistance.

Comment

People who like this

0 · Share
10 |600 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

33 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Cannot Get Search API to work with ShippingType query 5 Answers

Why isn't this API search call working? 1 Answer

FindingService API returns false info 10 Answers

Different results between searchAPI and search directly online 4 Answers

search using tracking number 0 Answers


Support

Developer Help Center
eBay Developers Program Blog
API Site Status
Request Support
Knowledge Base
Developer Forums
eBay Software Development Kits

API Information

API License Agreement
API Documentation
API Call Limits
Marketing Handbook
API Features Comparison

Apps Center

Applications Directory
Solutions Directory

Social Media

     

Programs

About Us
Success Stories
Affiliate Developers
eBay Market Data Program
Developer Directory
Developer Jobs
Copyright 1999 - 2018 eBay Inc. All rights reserved. User Agreement | Privacy Policy.    Site Feedback
  • Anonymous
  • Login with eBay
  • Create
  • Ask a question
  • Forums
  • Associating your listings with the eBay Catalog using eBay APIs
  • Buy APIs (BETA) - Browse
  • Buy APIs (BETA) - Order
  • Feedback, Comments, Suggestions
  • New Sell APIs - Account, Inventory, Catalog and Compliance
  • New Sell APIs - Fulfillment
  • New Sell APIs - Marketing, Analytics, Metadata
  • Post Order APIs - Cancellation
  • Post Order APIs - Inquiry, Case Management
  • Post Order APIs - Return
  • Token, Messaging, Sandbox related issues
  • eBay APIs: .NET SDK for Trading API
  • eBay APIs: Java SDK for Trading API
  • eBay APIs: Orders, resolutions and feedback
  • eBay APIs: Search
  • eBay APIs: Selling
  • eBay APIs: Talk to your fellow developers
  • Explore
  • Tags
  • Questions
  • Users
  • Badges