Results 1 to 9 of 9

 

Thread: API problem

  1. #1
    Registered User

    Status
    Offline
    Join Date
    Sep 2003
    Posts
    315
    Thanks
    28
    Thanked 19 Times in 16 Posts


    Morning all,

    I'm used to working with feeds but have been given the job of working with an XML / API web service. After reading many tutorials and guides I'm still not able to make a simple request and print something on screen from it.

    This is the code I'm trying.

    <?php

    $password = 'passwordhere';
    $productCode = 'ITEMCODEHERE';
    $userName = 'USERNAMEHERE';

    $xmlParameters = "password=$password&productCode=productCode";

    $client = new SoapClient('https://api.domain.com/');

    $res = $client->GetImagesforProduct($userName,$xmlParameters);

    $contentString = $res->contentString;

    print($contentString);

    ?>

    I'm trying to pass the variables to the API and get a response. Any help more than appreciated as I think I'm about to bank my head into a wall!

    Thanks

    Tom

  2. #2
    buy.at tech

    Status
    Offline
    Join Date
    Jul 2008
    Posts
    64
    Thanks
    1
    Thanked 11 Times in 11 Posts
    In the first instance you might want to check that you can see any errors this might be producing. If this script outputs nothing at all then that might be the case. Put this at the top of the script:

    PHP Code:
    error_reporting(E_ALL);
    ini_set('display_errors'1); 
    This should hopefully make any error messages show up in the output. Remember to remove this in production.

    Most APIs aren't set up to be called the way you're calling it with the various parameters passed as a query string. Usually, the parameters should be passed directly in the method call, e.g.:

    PHP Code:
    $res $client->GetImagesforProduct($userName$password$productCode); 
    But you should check the API documentation to see if you're calling it correctly.

    The following only applies if the API has a WSDL (which it should!) but might shed some light on whether you're calling the API in the right way:

    PHP Code:
    $client = new SoapClient('https://api.domain.com/');
    print_r($client->__getFunctions()); 
    SoapClient::__getFunctions is supposed to give you a spec of the actual functions you can call on the client, as a bunch of strings. It's useful to see this as it basically tells you how you should be calling the various functions from php.
    Ian Sproates, Head of Development (Newcastle), buy.at
    tel: +44 (0)191 222 9728 | email: ian.sproates@buy.at | icq: 490-111-853 | msn: sproates@hotmail.com

  3. The Following User Says Thank You to Sproates For This Useful Post:

    Tobman (20-10-10)

  4. #3
    Registered User

    Status
    Offline
    Join Date
    Sep 2003
    Posts
    315
    Thanks
    28
    Thanked 19 Times in 16 Posts
    Hmm that's weird. I've been trying to get this to work for days now and even another team of programmers I passed it to couldnt get their code to work. I've got to somehow pass the XML as a full chunk of XML:

    The merchant's tech team have been completely unhelpful too. If anyone can help - thank you!

    <?php
    $body = „
    <FeaturesForProductType
    xmlns="https://api.domain.co.uk/API.asmx">
    <userName>Your API Username</userName>
    <xmlParameters>
    <![CDATA[
    <FeaturesLookup xmlns="http://tempuri.org/DummySchema.xsd">
    <authorisation>
    <password>Your Password</password>
    </authorisation>
    <request>
    <ProductTypeCode>311</ProductTypeCode>
    </request>
    </FeaturesLookup>
    ]]>
    </xmlParameters>
    </FeaturesForProductType>
    ‟;
    // Call NuSOAP class
    require_once('nusoap.php');
    $s = new soapclientnusoap('https://api.domain.co.uk/API.asmx');
    $msg = $s->serializeEnvelope($body);
    $s ->
    send($msg,'https://api.domain.co.uk/API.asmx/FeaturesForProductTy
    pe');
    $response = $s->response;
    ?>


    Quote Originally Posted by Sproates View Post
    In the first instance you might want to check that you can see any errors this might be producing. If this script outputs nothing at all then that might be the case. Put this at the top of the script:

    PHP Code:
    error_reporting(E_ALL);
    ini_set('display_errors'1); 
    This should hopefully make any error messages show up in the output. Remember to remove this in production.

    Most APIs aren't set up to be called the way you're calling it with the various parameters passed as a query string. Usually, the parameters should be passed directly in the method call, e.g.:

    PHP Code:
    $res $client->GetImagesforProduct($userName$password$productCode); 
    But you should check the API documentation to see if you're calling it correctly.

    The following only applies if the API has a WSDL (which it should!) but might shed some light on whether you're calling the API in the right way:

    PHP Code:
    $client = new SoapClient('https://api.domain.com/');
    print_r($client->__getFunctions()); 
    SoapClient::__getFunctions is supposed to give you a spec of the actual functions you can call on the client, as a bunch of strings. It's useful to see this as it basically tells you how you should be calling the various functions from php.

  5. #4
    buy.at tech

    Status
    Offline
    Join Date
    Jul 2008
    Posts
    64
    Thanks
    1
    Thanked 11 Times in 11 Posts
    Sounds like their API is a bit weird if you've got to create the payload yourself like that. It will be difficult for anyone to spot what the matter is just given this code snippet and no access to the API for testing. If you don't want to give out the actual web service URL in public, PM or email me and I'll have a dabble with it.
    Ian Sproates, Head of Development (Newcastle), buy.at
    tel: +44 (0)191 222 9728 | email: ian.sproates@buy.at | icq: 490-111-853 | msn: sproates@hotmail.com

  6. #5
    Registered User

    Status
    Offline
    Join Date
    Oct 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Sproates View Post
    Sounds like their API is a bit weird if you've got to create the payload yourself like that. It will be difficult for anyone to spot what the matter is just given this code snippet and no access to the API for testing. If you don't want to give out the actual web service URL in public, PM or email me and I'll have a dabble with it.
    This code looks familiar did you have any success?

  7. #6
    buy.at tech

    Status
    Offline
    Join Date
    Jul 2008
    Posts
    64
    Thanks
    1
    Thanked 11 Times in 11 Posts
    Quote Originally Posted by Wells View Post
    This code looks familiar did you have any success?
    Not yet. I created a test client that sends a request exactly as the provider specified, but there was no response. So possibly the API is broken or doesn't work as advertised.

  8. #7
    Registered User

    Status
    Offline
    Join Date
    Oct 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Sproates View Post
    Not yet. I created a test client that sends a request exactly as the provider specified, but there was no response. So possibly the API is broken or doesn't work as advertised.
    Do you have the api technical documentation?

  9. #8
    buy.at tech

    Status
    Offline
    Join Date
    Jul 2008
    Posts
    64
    Thanks
    1
    Thanked 11 Times in 11 Posts
    Quote Originally Posted by Wells View Post
    Do you have the api technical documentation?
    There is online documentation plus a snippet that was sent to the OP; I think it would be better to contact him about it though as I don't know how public he'd like to be with it.

  10. #9
    Registered User

    Status
    Offline
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This error can be caused by an incorrect API username, an incorrect API password, or an invalid API signature. Make sure that all three of these values are correct. For your security, PayPal does not report exactly which of these three values might be in error.



Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Picture Loans Problem - OMG Problem
    By Black Cat in forum OMGPM.com, OMG Network
    Replies: 9
    Last Post: 25-01-07, 09:12 PM
  2. EPI value problem
    By bluesapphire in forum TradeDoubler
    Replies: 0
    Last Post: 24-04-06, 02:21 AM
  3. log in problem
    By tg88 in forum Affiliate Future
    Replies: 5
    Last Post: 25-08-05, 10:52 AM
  4. My problem
    By frazer987 in forum Affiliate Marketing Lounge
    Replies: 5
    Last Post: 25-06-05, 11:02 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
To Top

Content Relevant URLs by vBSEO 3.5.0 RC2