locked
How to use the adCenter API from a JAVA application? RRS feed

  • Question

  • Hi,

    Does someone use the adcenter API from a JAVA application? I am stuck at the first step - connection to the API - since I have no class named Administration after generating the JAVA classes from the WSDL files (using the Axis2 WSDL2Java plugin for eclipse)! I only have a AdmimistrationStub class which does not contain a method to set a ApiUserAuthHeader for instance...

    Any help is welcome!

    Thanks.

    Friday, October 13, 2006 8:05 AM

Answers

  • Hello Ludo-R,

    Here is how it works on my side:

        AdministrationSoap _administrationService = new AdministrationLocator().getAdministrationSoap();

            ((Stub) _administrationService).setHeader(NAMESPACE, "ApiUserAuthHeader", new ApiUserAuthHeader(USERNAME, PASSWORD, USERACCESSKEY));


        CampaignManagementSoap _campaignManagementService = new CampaignManagementLocator().getCampaignManagementSoap();

            ((Stub) _campaignManagementService).setHeader(NAMESPACE, "ApiUserAuthHeader", new ApiUserAuthHeader(USERNAME, PASSWORD, USERACCESSKEY));

        CustomerManagementSoap _customerManagementService = new CustomerManagementLocator().getCustomerManagementSoap();

            ((Stub) _customerManagementService).setHeader(NAMESPACE, "ApiUserAuthHeader", new ApiUserAuthHeader(USERNAME, PASSWORD, USERACCESSKEY));

        ReportingSoap _reportingService = new ReportingLocator().getReportingSoap();

            ((Stub) _reportingService).setHeader(NAMESPACE, "ApiUserAuthHeader", new ApiUserAuthHeader(USERNAME, PASSWORD, USERACCESSKEY));

    For example, to get the quota balance (the remaining quota units for the current month), you use:

    long quotaBalance = _administrationService.getQuotaBalance(APIFlags);

    I hope this will help you.

    All the best,
    Orest
    Friday, October 13, 2006 5:08 PM

All replies

  • Hello Ludo-R,

    Here is how it works on my side:

        AdministrationSoap _administrationService = new AdministrationLocator().getAdministrationSoap();

            ((Stub) _administrationService).setHeader(NAMESPACE, "ApiUserAuthHeader", new ApiUserAuthHeader(USERNAME, PASSWORD, USERACCESSKEY));


        CampaignManagementSoap _campaignManagementService = new CampaignManagementLocator().getCampaignManagementSoap();

            ((Stub) _campaignManagementService).setHeader(NAMESPACE, "ApiUserAuthHeader", new ApiUserAuthHeader(USERNAME, PASSWORD, USERACCESSKEY));

        CustomerManagementSoap _customerManagementService = new CustomerManagementLocator().getCustomerManagementSoap();

            ((Stub) _customerManagementService).setHeader(NAMESPACE, "ApiUserAuthHeader", new ApiUserAuthHeader(USERNAME, PASSWORD, USERACCESSKEY));

        ReportingSoap _reportingService = new ReportingLocator().getReportingSoap();

            ((Stub) _reportingService).setHeader(NAMESPACE, "ApiUserAuthHeader", new ApiUserAuthHeader(USERNAME, PASSWORD, USERACCESSKEY));

    For example, to get the quota balance (the remaining quota units for the current month), you use:

    long quotaBalance = _administrationService.getQuotaBalance(APIFlags);

    I hope this will help you.

    All the best,
    Orest
    Friday, October 13, 2006 5:08 PM
  • Thank you very much for your help.

    I now have problem to connect to the API (authentification failure but my credentials are ok according to the support).

    ((Stub) administrationService).setHeader("http://adcenter.microsoft.com/syncapis", "ApiUserAuthHeader", new ApiUserAuthHeader("myLogin", "myPassword", "myAccessKey"));

    I generated the java files using Axis 1.2RC2 as it is specified in the API documentation.

    Then I had a look at the Axis logs and it seems that the SOAP request sent to the webservice is not the same as expected by the server.

    Expected.
    <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Header>
    <ApiUserAuthHeader xmlns="http://adcenter.microsoft.com/syncapis">
    <UserName>string</UserName>
    <Password>string</Password>
    <UserAccessKey>string</UserAccessKey>
    </ApiUserAuthHeader> </soap:Header>
    <soap:Body>
    <GetQuotaBalance xmlns="http://adcenter.microsoft.com/syncapis"> <APIFlags>int</APIFlags>
    </GetQuotaBalance>
    </soap:Body>
    </soap:Envelope>

    Sent.
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Header>
    <ns1:ApiUserAuthHeader soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next" soapenv:mustUnderstand="0" xmlns:ns1="http://adcenter.microsoft.com/syncapis">
    <ns1:UserName>myUserName</ns1:UserName>
    <ns1:Password>myPassword</ns1:Password>
    <ns1:UserAccessKey>myAccessKey</ns1:UserAccessKey>
    </ns1:ApiUserAuthHeader></soapenv:Header>
    <soapenv:Body>
    <GetQuotaBalance xmlns="http://adcenter.microsoft.com/syncapis">
    <APIFlags>0</APIFlags>
    </GetQuotaBalance>
    </soapenv:Body>
    </soapenv:Envelope>

    Could that be the problem? What di I do wrong?

    Thanks.


    Monday, October 16, 2006 7:35 AM
  • Hello Ludo-R,

    Here are the XML messages exchanged by my application:

    Request message:

    <?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Header>
    <ns1:ApiUserAuthHeader
    soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next"
    soapenv:mustUnderstand="0" xmlns:ns1="http://adcenter.microsoft.com/syncapis">
    <ns1:UserName>username</ns1:UserName>
    <ns1:Password>password</ns1:Password>
    <ns1:UserAccessKey>useraccesskey</ns1:UserAccessKey>
    </ns1:ApiUserAuthHeader>
    </soapenv:Header>
    <soapenv:Body>
    <GetQuotaBalance xmlns="http://adcenter.microsoft.com/syncapis">
    <APIFlags>0</APIFlags>
    </GetQuotaBalance>
    </soapenv:Body>
    </soapenv:Envelope>

    Response message:

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
    <GetQuotaBalanceResponse xmlns="http://adcenter.microsoft.com/syncapis">
    <GetQuotaBalanceResult>123456</GetQuotaBalanceResult>
    </GetQuotaBalanceResponse>
    </soap:Body>
    </soap:Envelope>
    It seems to be exactly as yours.
    I really don't know what goes wrong.
    I would recommend you to try accessing your adCenter account using Perl or some other language, just to make sure that your credentials are indeed accepted by Microsoft.

    Good luck,
    Orest
    Monday, October 16, 2006 5:33 PM
  • Well, at the beginning, Microsoft sent me credentials for the sandbox environment but yesterday they had a look (not immediatly but after several emails) and it seems that I finally have a login/pass/key for the production environement!

    Let's try to setup the SSL certificate to download the production wsdl! How to waste one day...
    Tuesday, October 17, 2006 6:58 AM