Import-API

Updating the MdB via API is a simple way to automate this otherwise laborious task. Please work with people experienced in communicating with API's online. Each API session needs to be authenticated using documentation AXA: Atlas XML API, and all data sent with this API must be encoded as UTF8.
Please mind that all API requests are sent to one web server, meaning that if you have child sites, you need to use the URL for each child site. A communication operator with four sites will this need to run this API on four different URL's

Here is some example PHP code for using insert_posts():

$api_user = 12345; $api_key = "xxx"; $api_hash = ""; require_once 'Zend/Rest/Client.php'; $client = new Zend_Rest_Client("http://www.example.com/admin/edit/mdb_buildings/plain/api.php"); $client->api_login($api_user, $api_key); $login = $client->get(); $api_hash = $login->hash_key->__toString(); $keys = array("coId", "accessId", "...", "residentName", "activeServices"); $apifile = "addresses.csv"; if (($handle = fopen($apifile, "r")) !== false){         $nr = 0;         while (($csv = fgetcsv($handle, 1000, $delimiter)) !== false){                 $nr++;                 $data = array_combine($keys, $csv);                 $inserts["line$nr"] = $data;                 if ($nr % 100 == 0){                         $status = insert_posts($inserts);                         if (!$status->status == "success") unset($inserts);                         print "$nr: " . $status->message . "n";                         if ($status->log){                                 foreach ($status->log as $line => $errors){                                         if (strstr($errors, "successfully")) continue;                                         print "   $line: $errorsn";                                 }                         }                 }         }         if ($inserts){                 $status = insert_posts($inserts);                 print "$nr: " . $status->message . "n";                 if ($status->log){                         foreach ($status->log as $line => $errors){                                 if (strstr($errors, "successfully")) continue;                                 print "   $line: $errorsn";                         }                 }         } } function insert_posts($inserts){         global $client, $api_hash;         $client->insert_posts($api_hash, $inserts);         try{                 $inserted = $client->post();                 return $inserted;         } catch (Zend_Rest_Client_Result_Exception $e){                 print $e->getMessage() . ": " . $e->getCode() . "nn";         } }

Timing

It is our explicit recommendation that you run your import script during the timeframe between midnight to 3 am in the morning. The reson for this is that we run an aggregation script for XSP export at 3 am, and if you have run your import, the daily data will include that for the service providers in the following day.
Another reason is that if you were to run this during daytime, and you empty the database and insert every row, then you'd have a empty or incomplete database during a time where end customer could be searching for their address. Also, during nighttime the resource pressure on the server is much lower.

API Endpoint: Import
Import till Marknadsdatabasen 2
Endpoint URL http://www.example.com/admin/edit/mdb_buildings/plain/api
Note that this API requires authenticated user id and IP address and a hashed api credential Note that this API requires authenticated user id and IP address and a hashed api credential
  • Method: empty_database

  • Will empty the database connected to the site you execute the command on.
  • Parameters
    1 hash string green abcd Your login hash from api_login()
    Endpoint example:
    https://www.example.com/admin/edit/mdb_buildings/plain/api?method=empty_database&hash=abcd
  • success response


       <empty_database>
          <response>
             <message>Deleted all posts from MDb2 where citynet is 'ABC'</message>
          </response>
          <status>success</status>
       </empty_database>
  • Method: insert_post

  • ARRAY should be an array with PHP notation, as such: data[citynet]=MNCMSN&data[city]=Hallstahammar...

    The array sent must follow the MdB2 specification
    All values is validated and an error will be returned if it doesn't validate and the post isn't accepted.
    All data is inserted into the DB as a new post or updates an already existing post depending on the data.

    Note that this method should NOT be used to update your entire database. It can be used for pushing up small changes to the database or to test the API, but never to update your entire database, it is a far too costly method to use, when uploading large amounts of data, always use insert_posts
  • Parameters
    1 hash string green abcd Your login hash from api_login()
    2 data array green ARRAY An array of fields to be inserted to the database
    Endpoint example:
    https://www.example.com/admin/edit/mdb_buildings/plain/api?method=insert_post&hash=abcd&data=ARRAY
  • success response


       <insert_post>
          <response>
             <message>Inserted 1 post successfully</message>
          </response>
          <status>success</status>
       </insert_post>
  • Method: insert_posts

  • ARRAY should be an array of arrays with PHP notation, as such: posts[post1][coID]=MNCMSN&posts[post1][city]=Hallstahammar&posts[post1][streetName]=... where "post1" is the index of the post in the array.

    The array accepted can only contain a maximum of 100 arrays (posts) for each request. If you have 1000 posts to insert, you need to run this function 10 times. The API will return how many posts that validated and was thus entered to the database.

    Using "post###" (no spaces!) as the key for each array (post) in the request helps you understand possible error messages easier, if you have an internal ID for the data, it might be wise to use that (i.e. posts[293749][coID]=MNCMSN)

    Each post is then handled the same way as via the insert_post() method, see further information in that method
  • Parameters
    1 hash string green abcd Your login hash from api_login()
    2 posts array green ARRAY An array of posts to be inserted to the database, each post in the array the same as a single to insert_post()
    Endpoint example:
    https://www.example.com/admin/edit/mdb_buildings/plain/api?method=insert_posts&hash=abcd&posts=ARRAY
  • failed response


       <insert_posts>
          <response>
             <message>2 errors</message>
             <log>
                <line2>
                   <building>building can not be NULL</building>
                </line2>
                <line3>
                   <building>building can not be NULL</building>
                </line3>
             </log>
          </response>
          <status>failed</status>
       </insert_posts>
  • success response


       <insert_posts>
          <response>
             <message>100 successes, 0 errors, 100 processed</message>
          </response>
          <status>success</status>
       </insert_posts>