-1

I am trying to get the global_ip_id using the SoftLayer::API::SOAP. But when I try

$global_ip_id = $client->getGlobalIpRecords()->result->[0]->{id};

I get the error:

Can't use an undefined value as an ARRAY reference at /usr/bin/reroute_global line 19

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
N. Re
  • 1
  • Welcome to [so]! At this site you are expected to try to **write the code yourself**. After **[doing more research](//meta.stackoverflow.com/questions/261592)** if you have a problem you can **post what you've tried** with a **clear explanation of what isn't working** and providing a [**Minimal, Complete, and Verifiable example**](//stackoverflow.com/help/mcve). I suggest reading [ask] a good question and [the perfect question](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/). Also, be sure to take the [tour] and read **[this](//meta.stackoverflow.com/questions/347937/)**. – Badacadabra Apr 26 '17 at 17:30

1 Answers1

0

I have no idea what framework or language you are using, but I am prettry sure this is an issue with the wrong use of that.

The SOAP response that you get from that call should be somethign like this

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://api.service.softlayer.com/soap/v3.1/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Header>
    <ns1:totalItems>
      <amount>7</amount>
    </ns1:totalItems>
  </SOAP-ENV:Header>
  <SOAP-ENV:Body>
    <ns1:getGlobalIpRecordsResponse>
      <getGlobalIpRecordsReturn SOAP-ENC:arrayType="ns1:SoftLayer_Network_Subnet_IpAddress_Global[7]" xsi:type="ns1:SoftLayer_Network_Subnet_IpAddress_GlobalArray">
        <item xsi:type="ns1:SoftLayer_Network_Subnet_IpAddress_Global">
          <description xsi:nil="true"/>
          <destinationIpAddressId xsi:nil="true"/>
          <id xsi:type="xsd:int">11111</id>
          <ipAddressId xsi:type="xsd:int">22222</ipAddressId>
          <typeId xsi:type="xsd:int">1</typeId>
        </item>
      </getGlobalIpRecordsReturn>
    </ns1:getGlobalIpRecordsResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Now how you get the data from that response depends on the language or framework that you are using, as the response is a XML in some languages you need to navigate through the tags of the XML e.g.

result->{Body}->{getGlobalIpRecordsResponse}->{getGlobalIpRecordsReturn }->[0]->{id}

So I recomend you to make sure how your language or framework allows you to navigate through the SOAP response, because currently the issue that you are getting is due to the wrong way that you are trying to access to the data.

Now if you are using the Softlayer's Perl client you should use something like this:

my $client = SoftLayer::API::SOAP->new('SoftLayer_Account', undef, $api_username, $api_key);
my $output = $client->getGlobalIpRecords();
print $output->result->[0]->{'id'};

As you can see all depends on what lenguage and framework you are using

Also in case you are using Perl that error could be due to the result is empty in such case you need to verify that this is not empty see Error: Can't use an undefined value as an ARRAY reference for more information.

Regards

Community
  • 1
  • 1
  • hi Nelson, thanks for your Answer. I am using the Softlayer's perl, i tried your example but i still have the same error: – N. Re Apr 27 '17 at 08:02
  • i followed this implementation https://serverfault.com/questions/666850/softlayer-haproxy-with-failover – N. Re Apr 27 '17 at 08:26
  • maybe you do not have any global IP try to dump the result and see if it has data "print Dumper($output->result);" – Nelson Raul Cabero Mendoza Apr 27 '17 at 12:35
  • Hey, thanks a lot f your help. The issue hat something to do with the user permissions, since the user had no access to the Global IPs – N. Re Apr 27 '17 at 14:42