Mifos X API Documentation
Much of the presentation ideas here have been taken from the very good API reference (https://stripe.com/docs/api)
The Mifox X API is organized around REST. Our API is designed to have predictable, resource-oriented URLs, to use HTTP response codes to indicate API errors, and to use built-in HTTP features, like HTTP authentication and HTTP verbs, which can be understood by off-the-shelf HTTP clients. JSON will be returned in all responses from the API, including errors.
API Endpoint
https://thedomainname/
Summary of Resource URL Patterns
- /v1/offices
- /v1/offices/template
- /v1/offices/{OFFICEID}
- /v1/loanproducts
- /v1/loanproducts/template
- /v1/loanproducts/{PRODUCTID}
- /v1/configurations
- /v1/configurations/currency
- /v1/reports
- /v1/reports/{REPORTNAME}
- /v1/additionalfields
- /v1/additionalfields/{datasetType}/{datasetName}/{datasetPKValue}
Authentication
JPW: Keith, this needs to change to whatever is right after authentication has been added. Don't know if you will go with keys or passwords (I assume passwords)... but can you fix it so we have one user or one user per role that doesn't need a password or always has a password of 'password' so we can let ppl do stuff from the browser and/or REST plugins? We can talk about this.
STRIPE content: You authenticate to the Mifos X API by providing one of your API keys in the request. You can manage your API keys from your account. You can have multiple API keys active at one time. Your API keys carry many privileges, so be sure to keep them secret!
Authentication to the API occurs via HTTP Basic Auth. Provide your API key as the basic auth username. You do not need to provide a password.
All API requests must be made over HTTPS. Calls made over plain HTTP will fail. You must authenticate for all requests.
curl https://api.stripe.com/v1/charges \
-u vtUQeOtUnYr7PGCLQ96Ul4zqpDUO4sOE:
JPW: We'll update this after... curl uses the -u flag to pass basic auth credentials (adding a colon after your API key will prevent it from asking you for a password). A sample test API key has been provided in all the examples on the page, so you can test out any example right away.
Errors
JPW:Need to update this Stripe uses conventional HTTP response codes to indicate success or failure of an API request. In general, codes in the 2xx range indicate success, codes in the 4xx range indicate an error that resulted from the provided information (e.g. a required parameter was missing, a charge failed, etc.), and codes in the 5xx range indicate an error with Stripe's servers.
Not all errors map cleanly onto HTTP response codes, however. When a request is valid but does not complete successfully (e.g. a card is declined), we return a 402 error code.
All errors return JSON with a type (one of card_error, invalid_request_error, or api_error) and message describing the particular problem.
Attributes
- type
- The type of error returned (card_error, invalid_request_error, api_error) Card errors are the most common type of error you should expect to handle. They result when the user enters a card that can't be charged for some reason. Invalid request errors arise when your request has invalid parameters. API errors cover any other type of problem (e.g. a temporary problem with Stripe's servers) and should turn up only very infrequently.
- message
- A user-friendly message describing the error
- code
- optional
- For card errors, additional information about the user-friendly message to display for this error (e.g. "Your card was declined.")
- param
- optional
- The parameter the error relates to if the error is parameter-specific. You can use this to display a message near the correct form field, for example.
HTTP Status Code Summary
- 200 OK - Everything worked as expected.
- 400 Bad Request - Often missing a required parameter.
- 401 Unauthorized - No valid API key provided.
- 402 Request Failed - Parameters were valid but request failed.
- 404 Not Found - The requested item doesn't exist.
- 500, 502, 503, 504 Server errors - something went wrong on Stripe's end.
Errors
Type: invalid_request_error
Type: api_error
Type: card_error
| Code | Details |
|---|---|
| invalid_number | The card number is invalid |
| incorrect_number | The card number is incorrect |
| invalid_expiry_month | The card's expiration month is invalid |
| invalid_expiry_year | The card's expiration year is invalid |
| invalid_cvc | The card's security code is invalid |
| expired_card | The card has expired |
| invalid_amount | An invalid amount was entered |
| incorrect_cvc | The card's security code is incorrect |
| card_declined | The card was declined. |
| missing | There is no card on a customer that is being charged. |
| duplicate_transaction | A transaction with identical amount and credit card information was submitted very recently. |
| processing_error | An error occurred while processing the card. |
Additional Fields
In Mifos X, any number of "Sets" of "Additional Fields" can be configured for a Mifos X database table ("Type").
For example, portfolio_client is the database table that holds client data. Typically, MFI's want more client related fields than is provided by Mifos X out-of-the-box. The MFI might add a Set called "Additional Info" containing some fields that are typically input when creating a client. They might then add another Set called "Highly Improbable Info" containing some fields that are only input in exceptional circumstances.
The additional fields resource allows you to retrieve and update any Additional Fields data that has been configured in Mifos X.
The Mifos X Individual Lending client application uses a JQuery plugin called stretchydata which, itself, uses this additional fields resource to provide a pretty flexible additional fields User Interface (UI). Put a link to an example here.
List Additional Fields Sets
Lists the Sets of additional fields have been defined in Mifos X.
Arguments
- type
- optional
- The Additional Field Type (Mifos X database table) to restrict the output to
Example Request: http://localhost:8080/mifosng-provider/api/v1/additionalfields?type=portfolio_client
GET https://thedomainname/v1/additionalfields
{
"additionalFieldsSets": [
{
"id": 1,
"name": "Additional Information",
"type": "portfolio_client"
},
{
"id": 9,
"name": "Highly Improbable Info",
"type": "portfolio_client"
}
]
}
Retrieve Additional Fields
Returns the Set of Additional Fields data for the ID provided. The ID is the id field of the Type table e.g. portfolio_client might have an id value of 4. The output is a JSON formatted "Generic Resultset". The Generic Resultset contains Column Heading as well as Data information. The Column Heading information may include allowed values (columnValues array).
Arguments
NoneExample Request: http://localhost:8080/mifosng-provider/api/v1/additionalfields/portfolio_client/Additional Information/2
GET https://thedomainname/v1/additionalfields/{TYPE}/{SET}/{ID}
{
"columnHeaders": [
{
"columnName": "Ethnic Group",
"columnType": "String",
"columnLength": 50,
"columnDisplayType": "List",
"columnValues": [
"Bedouin",
"Berber",
"Italian",
"Miknasa",
"Mrazig",
"Other",
"Unknown"
]
},
{
"columnName": "Ethnic Group Other",
"columnType": "String",
"columnLength": 50,
"columnDisplayType": null,
"columnValues": []
},
{
"columnName": "Household Location",
"columnType": "String",
"columnLength": 50,
"columnDisplayType": "List",
"columnValues": [
"East Sikkim",
"North Sikkim",
"South Sikkim",
"West Sikkim",
"Other"
]
},
{
"columnName": "Household Location Other",
"columnType": "String",
"columnLength": 50,
"columnDisplayType": null,
"columnValues": []
},
{
"columnName": "Religion",
"columnType": "String",
"columnLength": 50,
"columnDisplayType": "List",
"columnValues": [
"Protestant",
"Catholic",
"Muslim",
"Animist",
"Atheist",
"Other",
"Unknown"
]
},
{
"columnName": "Religion Other",
"columnType": "String",
"columnLength": 50,
"columnDisplayType": null,
"columnValues": []
},
{
"columnName": "Knowledge of Person",
"columnType": "String",
"columnLength": 50,
"columnDisplayType": "List",
"columnValues": [
"Staff member",
"Spouse of staff member",
"Son/daughter of staff member",
"Friend of staff member",
"Not known by any staff member",
"Other"
]
},
{
"columnName": "Gender",
"columnType": "String",
"columnLength": 10,
"columnDisplayType": "List",
"columnValues": [
"Female",
"Male"
]
},
{
"columnName": "Whois",
"columnType": "Text",
"columnLength": 0,
"columnDisplayType": null,
"columnValues": []
}
],
"data": [
{
"row": [
"Berber",
null,
"East Sikkim",
null,
"Animist",
"jjjjjjj",
"Son/daughter of staff member",
"Female",
"its\r\nme of\r\ncourse\r\nyes\r\nend and the end of it all"
]
}
]
}
Update Additional Fields
Updates the Set of Additional Fields data for the ID provided. The ID is the id field of the Type table e.g. portfolio_client might have an id value of 4.
JPW note: currently using ed_transType = "E" for edit and ed_transType = "A" for new... probably need to not do that.
Arguments
NonePOST https://thedomainname/v1/additionalfields/{TYPE}/{SET}/{ID}
http://localhost:8080/mifosng-provider/api/v1/additionalfields/portfolio_client/Additional Information/2
Request Body:
Content-Type: application/json
{
"ed_transType":"E",
"Ethnic_Group":"Berber",
"Ethnic_Group_Other":"",
"Household_Location":"East Sikkim",
"Household_Location_Other":"",
"Religion":"Animist",
"Religion_Other":"jjjjjjj",
"Knowledge_of_Person":"Son/daughter of staff member",
"Gender":"Female",
"Whois":"its\r\nme of\r\ncourse\r\nyes\r\nend and the end of it all"
}
{
"entityId": 2
}
Reports
The reports resource allows you to run and receive output from pre-defined Mifos X reports. The default output is a JSON formatted "Generic Resultset". The Generic Resultset contains Column Heading as well as Data information. However, you can export to CSV format by simply adding "&exportCSV=true" to the end of your URI.
If Pentaho reports have been pre-defined, they can also be run through this resource. Pentaho reports can return HTML, PDF or CSV formats.
Add examples showing links to client listing report producing json, then csv, then a pentaho report producing html, pdf, csv
The Mifos X Individual Lending client application uses a JQuery plugin called stretchyreporting which, itself, uses this reports resource to provide a pretty flexible reporting User Interface (UI). Put a link to an example here.
List Reports
Lists all reports and their parameters. If a report has more than one parameter it will be listed the same number of times as it has parameters.
Arguments
- exportCSV
- optional, The only valid value is 'true'. If any other value is provided the argument will be ignored
- Output will be delivered as a CSV file instead of JSON.
Example Request: http://localhost:8080/mifosng-provider/api/v1/reports
GET https://thedomainname/v1/reports
{
"columnHeaders": [
{
"columnName": "report_id",
"columnType": "INT",
"columnLength": null,
"columnDisplayType": null,
"columnValues": []
},
{
"columnName": "report_name",
"columnType": "VARCHAR",
"columnLength": null,
"columnDisplayType": null,
"columnValues": []
},
{
"columnName": "report_type",
"columnType": "VARCHAR",
"columnLength": null,
"columnDisplayType": null,
"columnValues": []
},
... more "columnHeaders" entries
],
"data": [
{
"row": [
"29",
"Client Listing",
"Table",
null,
null,
"5",
null,
"selectOfficeId"
]
},
{
"row": [
"42",
"Client Listing - Additional and Unlikely",
"Table",
null,
null,
"5",
null,
"selectOfficeId"
]
},
{
"row": [
"30",
"Client Loans Listing",
"Table",
null,
null,
"5",
null,
"selectOfficeId"
]
},
... more "Row" entries
]
}
Running a Report
Runs a report and returns the report output.
Arguments
- R_'parameter names' ...
- optional, No defaults
- The number and names of the parameters depend on the specific report and how it has been configured. R_officeId is an example parameter name.
- Note: the prefix R_ stands for Reporting
- parameterType
- optional, The only valid value is 'true'. If any other value is provided the argument will be ignored
- Determines whether the request looks in the list of reports or the list of parameters for its data.
- exportCSV
- optional, The only valid value is 'true'. If any other value is provided the argument will be ignored
- Output will be delivered as a CSV file instead of JSON. Doesn't apply to Pentaho reports.
Example Request: http://localhost:8080/mifosng-provider/api/v1/reports/Client%20Listing?R_officeId=1
GET https://thedomainname/v1/reports/{REPORTNAME}
{
"columnHeaders": [
{
"columnName": "Office/Branch",
"columnType": "VARCHAR",
"columnLength": null,
"columnDisplayType": null,
"columnValues": []
},
{
"columnName": "Name",
"columnType": "VARCHAR",
"columnLength": null,
"columnDisplayType": null,
"columnValues": []
},
{
"columnName": "Joining Date",
"columnType": "DATE",
"columnLength": null,
"columnDisplayType": null,
"columnValues": []
}
],
"data": [
{
"row": [
"Demo MFI Head Office",
"O'Meara, Patrick",
"2009-01-04"
]
},
{
"row": [
"Demo MFI Head Office",
"O'Meara, Dennis",
"2009-01-04"
]
},
{
"row": [
"Demo MFI Head Office",
"Smith, John",
"2009-01-11"
]
},
... more "row" entries
]
}