3 Replies Latest reply on Aug 27, 2012 1:35 AM by poligon

    how to use

    poligon

      Hi!

      I have some problem with use Search API. English is not their native language for me, my be I not understand some in docs.

      I complite registration, and take 2 api key, use interactive documentation, construct URI. for example:

      https://api.element14.com/catalog/products?term=any%3Afuse&storeInfo.id=uk.farnell.com&resultsSettings.offset=0&resultsSettings.numberOfResults=1&resultsSettings.refinements.filters=rohsCompliant%2CinStock&resultsSettings.responseGroup=large&callInfo.omitXmlSchema=false&callInfo.responseDataFormat=xml&callinfo.apiKey=XXXXXXXXXXXXXX
      

      (I skip key. )

      1. Can I use curl for request? If yes, how headers I must send? From PHP I request this URI. If I don't send some headers, response is

      HTTP/1.0 403 Forbidden
      X-Mashery-Responder: mashery-web1.HKG 
      X-Mashery-Error-Code: ERR_403_NOT_AUTHORIZED
      Content-Type: text/xml
      Date: Wed, 27 Jun 2012 08:59:19 GMT
      Server: Mashery Proxy
      Content-Length: 23
      <h1>Not Authorized</h1>
      

      2. If I send some headers (any X-Originating-IP and any User-Agent), response is

      HTTP/1.0 403 Forbidden
      X-Mashery-Error-Code: ERR_403_SERVICE_REQUIRES_SSL
      Content-Type: text/xml
      Date: Wed, 27 Jun 2012 09:02:48 GMT
      Server: Mashery Proxy
      Content-Length: 29
      
      <h1>Service Requires SSL</h1>
      
      

      How it work?

        • Re: how to use
          efficientelectronics

          It seems like you are not using SSL or have a PHP installation where this is not properly configured. You may want to try the hints provided in http://stackoverflow.com/questions/316099/cant-connect-to-https-site-using-curl-returns-0-length-content-instead-what-c

           

          For your reference, the simplest PHP cURL implementation works for me just fine:

           

          $ch = curl_init();
          
          curl_setopt($ch, CURLOPT_URL, $url);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
          $result = curl_exec($ch);
          curl_close($ch);
          
          

           

          (obviously with some input and output validation left out for clarity)

            • Re: how to use
              poligon

              My configuration: http://vip-26.spaceweb.ru/phpinfo.php

              I must ask my hosting-provider about some?

              The code that I use:

              <?
              // url I'm get for example in IO doc, and remove double slash before "catalog"
              $url = "https://api.element14.com/catalog/products?term=any%3Afuse&storeInfo.id=uk.farnell.com&resultsSettings.offset=0&resultsSettings.numberOfResults=1&resultsSettings.refinements.filters=rohsCompliant%2CinStock&resultsSettings.responseGroup=large&callInfo.omitXmlSchema=false&callInfo.responseDataFormat=xml&callinfo.apiKey=xxx_my_application_key_xxx";
              
              
              // I'm not sure it's right headers... if I send any ip and any agent response one. farnell-store - it's application name
              $headers = array(
                  "X-Originating-IP: 77.222.56.18\n",
                  "User-Agent: farnell-store\n",
              );
              
              
              $ch = curl_init();
              curl_setopt($ch, CURLOPT_URL, $url);
              curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
              // I tried whitout SSL options and cert, different value for it, but response forever one: 403 error
              curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__)."/cacert.pem"); // from http://curl.haxx.se/ca/cacert.pem
              curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);     
              curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
              curl_setopt($ch, CURLOPT_HEADER, 1);
              curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
              $result = curl_exec($ch);
              
              print curl_error($ch);
              print($result);
              curl_close($ch);
              
              
                • Re: how to use
                  poligon

                  I must up this theme.

                  I'm install SSL-certificate (from Comodo), but have previous response again!


                  HTTP/1.0 403 Forbidden

                  X-Mashery-Error-Code: ERR_403_SERVICE_REQUIRES_SSL

                  Content-Type: text/xml

                  Date: Mon, 27 Aug 2012 06:26:42 GMT

                  Server: Mashery Proxy

                  Content-Length: 29



                  <h1>Service Requires SSL</h1>

                  somebody can give me code that is work?