[Mifos-developer] How to connect using mifosx api when running community app

95 views
Skip to first unread message

Geoffrey Kimani

unread,
Aug 15, 2016, 6:13:52 AM8/15/16
to mifos-d...@lists.sourceforge.net
Hello,

I have installed my mifox in my server and the link is of this nature

https://xxx.234.237.xxx:8443/community-app/#/


This is the link to my php script

https://bitbucket.org/qubitsmith/mifosx-api-php-examples/raw/3f0784f954bd61a52e4173e2657812aaf37aec6e/index.php


When i run the php script,i am not able to post a repayment. Does
anyone know why its not working?.

------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports. http://sdm.link/zohodev2dev
Mifos-developer mailing list
mifos-d...@lists.sourceforge.net
Unsubscribe or change settings at:
https://lists.sourceforge.net/lists/listinfo/mifos-developer

Nayan Ambali

unread,
Aug 15, 2016, 2:22:30 PM8/15/16
to Mifos software development
Hello Geoffrey,
You need to add custom header called Fineract-Platform-TenantId and set the value same as tenant identifier you want to access, in your case it may be 'default'.

the best way to learn about API is, refer API documentation https://demo.openmf.org/api-docs/apiLive.htm#top

Suggestions:
-
Nayan Ambali

Geoffrey Kimani

unread,
Aug 18, 2016, 8:40:24 PM8/18/16
to Mifos software development
I would like a sample script to connect to the api. The current   api is hard to connect to,things keep changing and no one documents  apiusage.
Nayan Ambali <nayan....@gmail.com> wrote:

Nazeer Shaik

unread,
Aug 19, 2016, 12:27:23 AM8/19/16
to Mifos software development
Can you check the URL you are constructing in your script. The URL should be like
'mifosng-provider/api/v1/loans/{{loanId}}/transactions?command=repayment'.
But your API target is clients.If you are using latest Mifosx releases, you need to replace 'mifosng' with 'fineract'


Thanks,
Nazeer

Nayan Ambali <nayan....@gmail.com> wrote:

------------------------------------------------------------------------------

Geoffrey Cimani

unread,
Aug 19, 2016, 9:13:49 AM8/19/16
to Mifos Developer, mifos-d...@lists.sourceforge.net

Hello,

This is my community app url



and this is my script which does not seem to work


<?php

error_reporting(E_ALL);
ini_set("display_errors", 1);

$data_string = '
{
 "dateFormat": "dd MMMM yyyy",
  "locale": "en",
  "transactionDate": "16 August 2016",
  "transactionAmount": "500.00",
  "paymentTypeId": "12",
  "note": "check payment",
  "accountNumber": "Pasay000000010",
  "checkNumber": "che123",
  "routingCode": "rou123",
  "receiptNumber": "rec123",
  "bankNumber": "ban123"
}
';

$username= "benk";
$password= "12345";
$tenant = "default";

$method = "POST";
$api_target = "clients";
$extra_parameters = '';
//$extra_parameters = "&command=close";
$URL= $endpoint.$api_target."?tenantIdentifier=".$tenant.$extra_parameters;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen($data_string))
);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);   //get status code
$result=curl_exec ($ch);
curl_close ($ch);

$result = json_decode(json_encode(json_decode($result,true)), true);
echo "<pre>".print_r($result,true)."</pre>";


?>


Does your company offer commercial support for mifosx?.
Nayan Ambali <nayan....@gmail.com> wrote:

------------------------------------------------------------------------------

Nayan Ambali

unread,
Aug 19, 2016, 10:18:17 AM8/19/16
to Mifos software development, Mifos Developer
possible corrections (php syntax may be broken), I assume you want to create a client using this script


<?php

error_reporting(E_ALL);
ini_set("display_errors", 1);

$data_string = '
{
 "dateFormat": "dd MMMM yyyy",
  "locale": "en",
  "transactionDate": "16 August 2016",
  "transactionAmount": "500.00",
  "paymentTypeId": "12",
  "note": "check payment",
  "accountNumber": "Pasay000000010",
  "checkNumber": "che123",
  "routingCode": "rou123",
  "receiptNumber": "rec123",
  "bankNumber": "ban123"
}
// create client data required and not trnasaction related data

';

$username= "benk";
$password= "12345";
$tenant = "default";

$method = "POST";
$api_target = "clients";
$extra_parameters = '';
//$extra_parameters = "&command=close";
$URL= $endpoint.$api_target." // ?tenantIdentifier=".$tenant.$extra_parameters; not reuired, need to send this HTTP header data

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen($data_string),
    'Fineract-Platform-TenantId:default')  // << missing header
);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);   //get status code
$result=curl_exec ($ch);
curl_close ($ch);

$result = json_decode(json_encode(json_decode($result,true)), true);
echo "<pre>".print_r($result,true)."</pre>";


?>


Nayan Ambali <nayan....@gmail.com> wrote:

------------------------------------------------------------------------------

Mifos-developer mailing list

Geoffrey Kimani

unread,
Aug 19, 2016, 10:53:55 AM8/19/16
to Mifos software development
Hello,

Nope,i do not want to create a client. I want to post a repayament.
>>>>> - Print the errors and return code, it helps know what went wrong
>>>>> - Better use REST friendly PHP HTTP client like
Reply all
Reply to author
Forward
0 new messages