User Tools

Site Tools


developers:api:client:requests

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
developers:api:client:requests [2014/11/16 06:47]
Jaco van Wyk [Examples]
developers:api:client:requests [2014/11/16 06:52]
Jaco van Wyk [Examples]
Line 29: Line 29:
 All standard requests to the API will be POST requests. These are used to add new clients (POST /​v1/​client/​add),​ to list existing invoices (POST /​v1/​invoice/​list) and to update (POST /​v1/​service/​{id}/​update) or delete (POST /​v1/​charge/​{id}/​delete). All standard requests to the API will be POST requests. These are used to add new clients (POST /​v1/​client/​add),​ to list existing invoices (POST /​v1/​invoice/​list) and to update (POST /​v1/​service/​{id}/​update) or delete (POST /​v1/​charge/​{id}/​delete).
  
-==== PHP (Example) ​====+==== Examples ​==== 
 + 
 +**PHP**
  
 In the example, we set the URL we'd like to call and initialise the curl object to point to that. Then we create an array of post data, and configure curl to use POST to make the request and to use our data array. In the example, we set the URL we'd like to call and initialise the curl object to point to that. Then we create an array of post data, and configure curl to use POST to make the request and to use our data array.
  
 <code php> <code php>
-       $service_url = '​http://​api.snapbill.com/​v1/​example';​ +<?php 
-       ​$curl = curl_init($service_url);​ + 
-       ​$curl_post_data = array( +$service_url = '​http://​api.snapbill.com/​v1/​example';​ 
-            "​client_xid"​ => '​T:​SA',​ +$curl = curl_init($service_url);​ 
-            "email_address" => '​email@example.com',​ +$curl_post_data = array( 
-            ); +     ​"​client_xid"​ => '​T:​SA',​ 
-       ​curl_setopt($curl,​ CURLOPT_RETURNTRANSFER,​ true); +     ​"email" => '​email@example.com',​ 
-       ​curl_setopt($curl,​ CURLOPT_POST,​ true); +     ​); 
-       ​curl_setopt($curl,​ CURLOPT_POSTFIELDS,​ $curl_post_data);​ +curl_setopt($curl,​ CURLOPT_RETURNTRANSFER,​ true); 
-       ​$curl_response = curl_exec($curl);​ +curl_setopt($curl,​ CURLOPT_POST,​ true); 
-       ​curl_close($curl);​ +curl_setopt($curl,​ CURLOPT_POSTFIELDS,​ $curl_post_data);​ 
-  +$curl_response = curl_exec($curl);​ 
-       ​$xml = new SimpleXMLElement($curl_response);</​code>​+curl_close($curl);​ 
 + 
 +$xml = new SimpleXMLElement($curl_response);</​code>​
                
 We execute the request and capture the response. **Health warning:** by default curl will echo the response, if you want to parse it then you will need to use the CURLOPT_RETURNTRANSFER flag to have curl return the response rather than a boolean indication of success. We execute the request and capture the response. **Health warning:** by default curl will echo the response, if you want to parse it then you will need to use the CURLOPT_RETURNTRANSFER flag to have curl return the response rather than a boolean indication of success.
developers/api/client/requests.txt · Last modified: 2014/11/16 06:52 by Jaco van Wyk