Skip to main content

PHP XML writing data to ABRA Flexi

How to write data to ABRA Flexi in XML format

Written by Lenka Haringerová

This article follows up on PHP loading data from ABRA Flexi, which described how to retrieve data from the ABRA Flexi system and display it as a table. This article describes how to write data to ABRA Flexi in XML format.

The initial setup was already covered in the previous article.

As a first step, prepare an XML file that will contain a simple address book record.

<?xml version="1.0"?><winstrom version="1.0">  <adresar>    <nazev>CharlieB</nazev>    <ulice>Lochot&#xED;nsk&#xE1; 18</ulice>    <mesto>Plze&#x148;</mesto>    <psc>301 00</psc>    <tel>+420 371 124 321</tel>    <email>podporaflexi@abra.eu</email>  </adresar></winstrom>

This XML file will create a record in the address book with the name CharlieB, an address, phone number, and email. These are the basic details that an e-shop operator needs to know about their customers. The abbreviation will be generated automatically based on the name, so you do not need to worry about it.

Modify the code that was already used in the previous article:

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");

Change the HTTP method to PUT.

curl_setopt($ch, CURLOPT_POSTFIELDS, ' 
<winstrom version="1.0">
<adresar>
<nazev>CharlieB</nazev>
<ulice>Lochotínská 18</ulice>
<mesto>Plzeň</mesto>
<psc>301 00</psc>
<tel>+420 371 124 321</tel>
<email>podpora@flexibee.eu</email>
</adresar>
</winstrom> ');

Set which information you need to send to ABRA Flexi and update the result handling.

The complete program will look like this, for example:

<?php 
// URL with xml data
$url = "https://demo.flexibee.eu/c/demo/adresar.xml";

// create curl resource
$ch = curl_init();

// return content as a string from curl_exec
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

// follow redirects (compatibility for changes in FlexiBee) //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);

// HTTP authentication curl_setopt($ch, CURLOPT_HTTPAUTH, TRUE);
// FlexiBee by default uses Self-Signed certificates //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

// for debugging
// curl_setopt($ch, CURLOPT_VERBOSE, TRUE);

// set username and password
curl_setopt($ch, CURLOPT_USERPWD, "winstrom:winstrom");

// set URL
curl_setopt($ch, CURLOPT_URL, $url);

// set HTTP method
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");

// set data
curl_setopt($ch, CURLOPT_POSTFIELDS,
' <winstrom version="1.0">
<adresar>
<nazev>CharlieB</nazev>
<ulice>Lochotínská 18</ulice>
<mesto>Plzeň</mesto>
<psc>301 00</psc>
<tel>+420 371 124 321</tel>
<email>podpora@flexibee.eu</email>
</adresar>
</winstrom> ');

// execute
$output = curl_exec($ch);

// FlexiBee return value
header("Content-Type: application/xml");
print ($output);

// close curl resource to free up system resources
curl_close($ch);

?>

The program will again connect to the server demo.flexibee.eu. It will authenticate via HTTP authentication as user winstrom, with the password winstrom, into the company with the identifier demo. It will create a new record in the address book with the name CharlieB.
A demo that creates an address book entry on demo.flexibee.eu

This guide describes a simple way to write data to ABRA Flexi. This can apply not only to the address book, but also to received orders or issued invoices.

Did this answer your question?