You are not currently logged in
Log In | Register

XML API Sample Code (PHP)

Tagged with
by Jonny Carter
in Code Samples

05-Jun-2015 12:13

Here is an example function for calling the XML API with PHP

PHP
Calling XML API
-------------------------------------------------------------------------------------------------------------------------------

<?php

    // Account credentials
    $userid=”userid”;
    $password=”password”;

    // message parameters
    $message=”message text body”;
    $msisdn=”07123456789”;

    // XML to be posted
    $inputdata = '
        <campaign>
            <header uid="'.$userid.'" pwd="'.$password.'" action="SEND_MSISDN"/>
            <body>
                <msg>'.$message.'</msg>
                <msisdn>'.$msisdn.'</msisdn>
            </body>
        </campaign>
    ';

    // curl post request 
    $x = curl_init("https://textgoto.com/api/xmlapi.aspx");
    curl_setopt($x, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
    curl_setopt($x, CURLOPT_HEADER, 0);
    curl_setopt($x, CURLOPT_POST, 1);
    curl_setopt($x, CURLOPT_POSTFIELDS, $inputdata);
    curl_setopt($x, CURLOPT_FOLLOWLOCATION, 0);
    curl_setopt($x, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($x, CURLOPT_SSL_VERIFYPEER, FALSE);     
    curl_setopt($x, CURLOPT_SSL_VERIFYHOST, 0); 
    $data = curl_exec($x);
    curl_close($x);

    // print response
    print_r($data);
?>