post https://secure.fusebill.com/v1/Credits
This function allows you to create a credit on a specific customer for a specific amount.
Request Parameters
Property | Type | Description | Required |
---|---|---|---|
reference | String | The text reference that is added to the credit. [Max Length: 500 characters] | Optional |
effectiveTimestamp | DateTime | The effective timestamp of this credit | Yes |
customerId | Integer | This is the Fusebill Customer Id of the customer the credit will apply against. | Yes |
amount | Decimal | This is the amount of the credit. | Yes |
creditAllocations | List of objects. Definition below | This is an optional list of credit allocations which tells Fusebill how to split the value of this credit over many invoices. | Optional |
Credit Allocations Resource Properties
Property | Type | Description |
---|---|---|
invoiceId | Number | This is the Invoice ID for the Invoice this payment allocation applies against. |
amount | Number | This is the dollar amount to apply against the above invoice. |
Examples
curl -X POST "https://secure.fusebill.com/v1/credits/" \
-H "Content-Type: application/json" \
-H "Authorization: Basic {APIKey}" \
-d "{customerId:{customerId},reference:'this is a test credit',amount:10,effectiveTimeStamp:'2017-01-16T10:00:00'}"
//Json Payload
string jsonData = "{customerId:{customerId},reference:'this is a test credit',amount:10,effectiveTimeStamp:'2017-01-16T10:00:00'}";
//Setup API key
string apiKey = "{APIKey}";
//Configure URI
WebRequest request = WebRequest.Create("HTTPS://secure.fusebill.com/v1/credits/");
//Add Content type
request.ContentType = "application/json";
//Add Api key authorization
request.Headers.Add(HttpRequestHeader.Authorization, "Basic " + apiKey);
//Set request method
request.Method = "POST";
//Add the json data to request
using (var streamWriter = new StreamWriter(request.GetRequestStream()))
{
streamWriter.Write(jsonData);
streamWriter.Flush();
streamWriter.Close();
}
//Perform the request
var httpResponse = (HttpWebResponse)request.GetResponse();
//Record the response from our request
var result = "";
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
result = streamReader.ReadToEnd();
}
#Import library JSON
import json
#Import library Requests
import requests
#Pass in a dictionary to the Headers parameter
headers = {'Authorization' : 'Basic {APIKey}', 'Content-Type' : 'application/json'}
#Pass in a dictionary to the Payload parameter
payload = {"customerId":{id},"reference":'this is a test credit',"amount":10,"effectiveTimeStamp":'2017-02-10T10:00:00'}
#Pass in your URI, Payload and Headers
r = requests.post('https://secure.fusebill.com/v1/credits', data=json.dumps(payload), headers=headers)
print(r.content)
{
"reference": "Returned item discount",
"customerId": 655643,
"amount": 2,
"effectiveTimestamp": "2020-01-01",
"creditAllocations": [
{
"invoiceId": 566935,
"amount": 2
}
]
}
Response
{
"reference":"this is a test credit",
"effectiveTimestamp":"2017-01-16T10:00:00",
"description":null,
"customerId":172677,
"amount":10.0,
"currency":"USD",
"unallocatedAmount":10.0,
"reversableAmount":10.0,
"invoiceAllocations":[
],
"debits":[
],
"id":7613682,
"uri":"https://secure.fusebill.com/v1/credits/7613682"
}
{
"ErrorId": 0,
"HttpStatusCode": 400,
"Errors": [
{
"Key": "Api Error",
"Value": "The sum of allocations 3.0 cannot exceed the credit amount 2.0"
}
]
}