OSDial API

Development discussions by and for developers

OSDial API

Postby sentm » Thu May 27, 2010 12:25 am

An OSDial API is forthcoming.

The first function add_lead currently allows for remote insertion from CRMs or other webspace via XML into the leads table and/or directly into the hopper for immediate dialing.

Here is a preview of the XML post for the add_lead function:
Code: Select all
<?xml version='1.0' standalone='yes'?>
<api user="admin" pass="XXXXX" function="add_lead" mode="admin" test="0" debug="0" vdcompat="0">
  <params>
    <dnc_check>YES</dnc_check>
    <duplicate_check>LIST</duplicate_check>
    <gmt_lookup_method>POSTAL</gmt_lookup_method>

    <add_to_hopper>YES</add_to_hopper>
    <hopper_priority>0</hopper_priority>
    <hopper_local_call_time_check></hopper_local_call_time_check>
    <hopper_campaign_call_time_check></hopper_campaign_call_time_check>

    <vendor_lead_code></vendor_lead_code>
    <source_id></source_id>
    <list_id>1000</list_id>
    <phone_code>1</phone_code>
    <phone_number>9992031212</phone_number>
    <title></title>
    <first_name>John</first_name>
    <middle_initial></middle_initial>
    <last_name>Doe</last_name>
    <address1>1234 Test Ave</address1>
    <address2>Apt. 31-B</address2>
    <address3></address3>
    <city>Orlando</city>
    <state>FL</state>
    <province></province>
    <postal_code>32801</postal_code>
    <country_code>USA</country_code>
    <gender>m</gender>
    <date_of_birth>1970-01-01</date_of_birth>
    <alt_phone></alt_phone>
    <email>john@doe.com</email>
    <custom1></custom1>
    <custom2></custom2>
    <comments>This is a test of the lead loading.</comments>
    <external_key>88975347</external_key>
    <cost>1.23</cost>
    <post_date>2010-03-20T14:30:00</post_date>
    <agent>1000</agent>

    <additional_fields>
      <additional_field form="CREDITCARD" field="NAME">John Doe</additional_field>
      <additional_field form="CREDITCARD" field="ADDRESS">9928 CC Lane</additional_field>
    </additional_fields>

  </params>
</api>


So the question for you developers our there is...what functions do you think you can benefit from?
sentm
 
Posts: 87
Joined: Wed May 26, 2010 10:53 pm
Location: Orlando, FL

Re: OSDial API

Postby fsanchez » Tue Apr 19, 2011 5:58 pm

Hi, I can see you have a few interesting posts!

I have a question in reference to this one in particular if you have a chance, i saw in the Features List in the website http://www.osdial.org/features.php that OSDial is "Ready to import XML formatted leads from web site"

Do you know how can that option be implemented?? I appreciate your time. Thank you.
fsanchez
 
Posts: 26
Joined: Tue Feb 22, 2011 8:48 pm

Re: OSDial API

Postby sentm » Tue Apr 19, 2011 10:24 pm

The above example is a good starting point...

There is a draft version of the API Documentation also available. It goes into a bit more depth on the add_lead call.

http://www.osdial.org/docs/OSDial-API_Documentation-v0.2.pdf

Disclaimer: Being that it is a draft version, there may be mistakes in the document and/or API itself.
sentm
 
Posts: 87
Joined: Wed May 26, 2010 10:53 pm
Location: Orlando, FL

Re: OSDial API

Postby fsanchez » Mon Apr 25, 2011 10:02 am

Thank you very much that was very helpful
fsanchez
 
Posts: 26
Joined: Tue Feb 22, 2011 8:48 pm

Re: OSDial API

Postby fsanchez » Wed May 11, 2011 3:59 pm

But how my clients, can send me a xml via api.php. This is that i dont understand.
fsanchez
 
Posts: 26
Joined: Tue Feb 22, 2011 8:48 pm

Re: OSDial API

Postby sentm » Wed May 11, 2011 4:53 pm

Via HTTP POST, using the xml variable.
sentm
 
Posts: 87
Joined: Wed May 26, 2010 10:53 pm
Location: Orlando, FL

Re: OSDial API

Postby fsanchez » Sat May 14, 2011 3:53 pm

This is the code, would you please correct me

<form action="http://192.168.1.230/admin/api.php" method="post" enctype="multipart/form-data">
<input type="file" name="ufile" />
<input type="submit" value="Upload" />
</form>

because the help explain: http://yourserver/admin/api.php?xml=<api function="version"/>
but what is =<api function="version"/> this is that my clients, dont undertand
fsanchez
 
Posts: 26
Joined: Tue Feb 22, 2011 8:48 pm

Re: OSDial API

Postby sentm » Sat May 14, 2011 7:01 pm

Almost. You can't pass it an html file input, but you could post a textarea into the API. You would have to copy and paste you XML into the textarea, but it should work just fine.

Code: Select all
<form action="http://192.168.1.230/admin/api.php" method="post" enctype="multipart/form-data">
<textarea name="xml" rows="15" cols="80">Paste you XML file here and click submit.</textarea>
<input type="submit" value="Upload" />
</form>


I would recommend using JavaScript or Curl as a transport for getting information into the API.
Here is an example of a script that uses Curl to post back to the API.

http://osdial.svn.sourceforge.net/viewvc/osdial/trunk/extras/misc/import-findmyleads.php?revision=1372
sentm
 
Posts: 87
Joined: Wed May 26, 2010 10:53 pm
Location: Orlando, FL

Re: OSDial API

Postby fsanchez » Wed May 18, 2011 12:22 pm

Thank You, for the help. We apreciate your guidelines.
We Finally have a solution:
This is the code:

<?php
$filename = "sample_xml1.xml";
$handle = fopen($filename, "rb");
$data = '';
while (!feof($handle)) {
$data .= fread($handle, 8192);
}
fclose($handle);
?>
<form action="http://192.168.1.230/admin/api.php" method="post" enctype="multipart/form-data">
<textarea name="xml" rows="30" cols="80"><?php echo $data; ?></textarea>
<input type="submit" value="Upload" />
</form>


Now we have another question for you.
What if we need to send by xml, multiples rows of information. Because this xml example is only of one row.
Thank for your answer.
fsanchez
 
Posts: 26
Joined: Tue Feb 22, 2011 8:48 pm

Re: OSDial API

Postby sentm » Wed May 18, 2011 11:27 pm

Well, first I would prearrange a format in which to receive the data, lets say CSV. It would then require you to write code to receive the file and parse/loop through it, creating the needed xml structures, posting the xml structure to the API via Curl or Javascript XMLHttpRequest(), and then report on the result.

Code: Select all
<?php

$PHP_SELF = $_SERVER['PHP_SELF'];

if ( !isset($_POST['submit']) or !isset($_FILES['leadfile']) ) {
  # If they havent submitted or the file was not set redisplay form.
  echo "<form action=\"$PHP_SELF\" method=\"post\" enctype=\"multipart/form-data\">\n";
  echo "<input type=\"file\" name=\"leadfile\">\n";
  echo "<input type=\"submit\" value=\"Upload\">\n";
  echo "</form>\n";

} else {
  # Good, they submitted and a file was attached.  Lets get it.
  $leadfile = $_FILES['leadfile'];
  $leadfiletmp = $_FILES['leadfile']['tmp_name'];
  $leadfilename = $_FILES['leadfile']['name'];

  # We are going to assume hear that the format is alway csv and the uploader is consistent.
  while ($row=fgetcsv($leadfiletmp, 1000, ',')) {
    # The uploaded only sends us the following fields in this order: custid, phone, fname, lname

    # Lets make an xml sturcture!
    $xmlReq = new SimpleXMLElement('<api><params></params></api>');
    # Now we need to add all the required components from the API docs...

    # Auth - CHANGE user AND pass values for a user that is allowed API access!
    $xmlReq['user']     = '1000';
    $xmlReq['pass']     = '1000';
    $xmlReq['function'] = 'add_lead';
    $xmlReq['mode']     = 'admin';
    $xmlReq['vdcompat'] = '0';
    $xmlReq['test']     = '0';
    $xmlReq['debug']    = '0';

    # Parameters / DataControl - These flags change how the lead is validated and how to act on it.
    $xmlReq->params->dnc_check         = 'Y';
    $xmlReq->params->duplicate_check   = 'LIST';
    $xmlReq->params->gmt_lookup_method = 'AREACODE';
    $xmlReq->params->add_to_hopper     = 'Y';
    $xmlReq->params->hopper_priority   = '50';
    $xmlReq->params->hopper_local_call_time_check    = 'N';
    $xmlReq->params->hopper_campaign_call_time_check = 'N';

    # Parameters / ListData - Variables that apply to every lead loaded in this list.
    $xmlReq->params->list_id          = '20110518211054'; # The list_id should exist and be assigned to a campaign.
    $xmlReq->params->vendor_lead_code = 'FSAN'; # Use this so you can later identify what vendor the leads came from.
    $xmlReq->params->source_id        = 'WEB'; # The lead source ?  Web/ Email/ Mail/ Phone...
    $xmlReq->params->phone_code       = '1';
    $xmlReq->params->status           = 'NEW';

    # Parameters / LeadData - The Actual lead data.
    $xmlReq->params->external_key     = $row[0];
    $xmlReq->params->phone_number  = $row[1];
    $xmlReq->params->first_name        = $row[2];
    $xmlReq->params->last_name         = $row[3];

    # Done with xml structure...now lets attempt to send it to the API!
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'http://192.168.1.230/admin/api.php');
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, array('xml' => $xmlReq->asXML()));
    $result = curl_exec($ch);
    curl_close($ch);

    # Print out the result of the last attempt.
    $xmlRes = new SimpleXMLElement($result);
    echo $xmlRes->status ."<br/>";

    # Continue on to next entry in file.
  }

  echo $leadfilename . " has been processed.<br/>";
}

?>



I haven't tested the above code...its just what I could come up with in 10 min. It could use counters and styles. Hopefully you have a basic concept of what it is doing.
sentm
 
Posts: 87
Joined: Wed May 26, 2010 10:53 pm
Location: Orlando, FL

Re: OSDial API

Postby fsanchez » Tue May 24, 2011 3:55 pm

That was very helpful thank you!
fsanchez
 
Posts: 26
Joined: Tue Feb 22, 2011 8:48 pm

Re: OSDial API

Postby wayneski » Wed Feb 17, 2016 4:39 pm

Hi, I appreciate the last post in in this topic was 2011, Thank you to sentm for the contribution, it has been a great basis to get some code running.

I have had some success in importing leads into OSDials standard out of the box fields however when I try to import into any of the custom fields there is no data posted in those specific fields. Again the standard fields are populated.

$xmlReq->params->additional_fields = "<additional_fields>";
$xmlReq->params->additional_field = "<additional_field form=\"CREDITCARD\" field=\"NAME\">Smith</additional_field>";
$xmlReq->params->additional_fields = "</additional_fields>";

Can anyone assist me with this as I've been banging my head on the wall.

I have purchased the OSDIAL Manual which shows it possible, so I guess it could be my PHP skills that are letting me down.

Thank you in advance and I hope this helps someone else in the future.

regards
Wayne
wayneski
 
Posts: 1
Joined: Wed Feb 17, 2016 4:30 pm


Return to Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron