up Version >= 2.2

Inventory Deliveries Download

Once authorised, a client can download inventory deliveries belonging to any of its sites via the TWeb Public API. Inventory deliveries are returned in a JSON list. The process of downloading inventory deliveries may involve three requests to the Public API:

  1. A request to obtain a batch number for the download
  2. Requests to obtain the inventory deliveries for the batch
  3. Requests to tag inventory deliveries as received (this is optional)

When the client makes a request to obtain the batch number (Step 1) it also submits filters to specify which inventory deliveries are to be included in the batch. Once the client receives the batch number, then it can use this number to make multiple requests to obtain inventory deliveries for the batch (Step 2). Each request is limited to a maximum of 100 records and the client must specify the start and end indexes for the inventory deliveries to be downloaded. After each set of inventory deliveries have been received and correctly stored (Step 2), the client may wish to tag the inventory deliveries as received (Step 3). The tag status of an inventory delivery can be used as a filter during Step 1. This is useful if a client simply wants to download any inventory deliveries it has not previously received.

Step 1 - Requesting an Inventory Deliveries Batch Number

The endpoint depends on the server used by your company to login to TWeb:

T-WEB Server T-WEB Login URL API Authorisation Endpoint
www https://www.tweb.com.au/v2/ https://publicapi.tweb.com.au/v1/DeliveriesBatchNumber
www2 https://www2.tweb.com.au/v2/ https://publicapi2.tweb.com.au/v1/DeliveriesBatchNumber
gt https://gt.tweb.ttfuel.com/v2/ https://publicapi.gt.tweb.ttfuel.com/v1/DeliveriesBatchNumber
uae https://uae.tweb.ttfuel.com/v2/ https://publicapi.uae.tweb.ttfuel.com/v1/DeliveriesBatchNumber

The endpoint only accepts HTTP POST requests. The following POST parameters must be included with the request:

accessToken

Note that the Access Token may be submitted as a POST parameter or as a HTTP Cookie.

The following POST parameters may optionally be submitted with the request:

targetID
filterStartDatetime
filterEndDatetime
filterTaggedDeliveries
filterSiteNumber
filterTankNumber

For details regarding the Target ID, please refer to the following article: https://help.tweb.com.au/TWebPublicAPI/en/Authorisation/Execute#heading_request

filterStartDatetime is an optional POST parameter. This parameter specifies the lower time-limit (inclusive) for inventory deliveries included in the batch. For example, if set to 11:59PM on 31 Jan 2018 then only inventory deliveries occurring on and after this date and time will be included in the batch. The filterStartDatetime has the following validation rule specifications:

Rule Specification
Format yyyy-MM-dd HH:mm:ss (eg. 2018-01-31 23:59:00, which would mean 11:59PM on 31 Jan 2018)
Parsing The date and time must be valid
Default When this parameter is not specified, it value defaults to 1900-01-01 00:00:00

filterEndDatetime is an optional POST parameter. This parameter specifies the upper time-limit (inclusive) for inventory deliveries included in the batch. For example, if set to 11:59PM on 31 Jan 2018 then only inventory deliveries occurring before and on this date and time will be included in the batch. The filterEndDatetime has the following validation rule specifications:

Rule Specification
Format yyyy-MM-dd HH:mm:ss (eg. 2018-01-31 23:59:00, which would mean 11:59PM on 31 Jan 2018)
Parsing The date and time must be valid
Default When this parameter is not specified, it value defaults to 3000-01-01 00:00:00

filterTaggedDeliveries is an optional POST parameter. This parameter specifies whether to return inventory deliveries that have previously been downloaded via the Public API or not. It has the following validation rule specifications:

Rule Specification
Allowed values TaggedAndUntagged, UntaggedOnly, TaggedOnly
Default TaggedAndUntagged

filterSiteNumber is an optional POST parameter. This parameter specifies the site where inventory deliveries occurred. Site Numbers are allocated to all sites by TT. A list is available via TWeb. This filter has the following validation rule specifications:

Rule Specification
Format /[0-9]{6}/, eg. 123456
Default When this parameter is not specified then inventory deliveries for all sites will be returned

filterTankNumber is an optional POST parameter. This parameter specifies the tank number where inventory deliveries occurred. This filter has the following validation rule specifications:

Rule Specification
Allowable characters integers only
Minimum value 1
Maximum value 1000


Request Examples

A request for the Batch Number that includes the Access Token from the file where it was stored during authorisation:

curl -b cookiejar.txt -skX POST -d "targetID=abc123&filterStartDatetime=2018-01-31 23:59:00&filterEndDatetime=2018-03-01 00:00:00&filterTaggedDeliveries=UntaggedOnly&filterSiteNumber=123456" https://publicapi.tweb.com.au/v1/DeliveriesBatchNumber

A request for the Batch Number that includes the Access Token as a POST parameter in the body:

curl -skX POST -d "accessToken=0123456789ABCDEF0123456789ABCDEF01234567&targetID=abc123&filterStartDatetime=2018-01-31 23:59:00&filterEndDatetime=2018-03-01 00:00:00&filterTaggedDeliveries=UntaggedOnly&filterSiteNumber=123456" https://publicapi.tweb.com.au/v1/DeliveriesBatchNumber

Step 1 - Response

The response from the Batch Number endpoint has the following JSON format:

{
"Data": {
"Items": [
{
"NewBatchNumber": 123
}
],
"Meta": {
"Endpoint": "/v1/DeliveriesBatchNumber",
"SubmittedFilters": {
"filterEndDatetime: "2018-03-01 00:00:00",
"filterSiteNumber": "123456",
"filterStartDatetime": "2018-01-31 23:59:00",
"filterTaggedDeliveries": "UntaggedOnly"
},
"TargetID": "abc123",
"Title": "Public API: Deliveries Batch Number",
"TotalRecords": 1000
}
},
"Error": {
"Code": 0,
"Status": "OK"
}
}

The batch number is an integer and is available in the Data.Items[0].NewBatchNumber JSON property.

The total number of inventory deliveries for the given filters is also an integer and is available in the Data.Meta.TotalRecords JSON property.

The Error JSON property is included in all responses from the TWeb Public API. The possible responses when requesting an Inventory Deliveries Batch Number are:

Error Code Error Name Explanation
0 OK A Batch Number has been assigned and returned.
1 Server Error This issue either does not fit any of the other codes or is due to a bug in the Public API code.
4000 Rate Limit Exceeded This is the second request within a 1 second period.
4002 Account Inactive Account Inactive.
4003 Session Expired Session Expired.
4008 Invalid Access Token The Access Token was not valid.
4104 Invalid Target ID The Target ID did not conform to the specifications.
4105 Invalid Filter One of the submitted filters was invalid. The Error.Status JSON property will specify which filter was incorrect.
4400 Unable To Allocate Delivery Batch Number There was an error while attempting to generate a new Batch Number.
4401 Unable To Assign Deliveries To Batch Number There was an error while attempting to allocate inventory deliveries to a Batch Number.

Step 2 - Requesting a Page of Inventory Deliveries

Once the client has the Inventory Deliveries Batch Number, this can be used to download inventory delivery data. The endpoint used for this depends on the server used by your company to login to TWeb:

T-WEB Server T-WEB Login URL API Authorisation Endpoint
www https://www.tweb.com.au/v2/ https://publicapi.tweb.com.au/v1/Deliveries
www2 https://www2.tweb.com.au/v2/ https://publicapi2.tweb.com.au/v1/Deliveries
gt https://gt.tweb.ttfuel.com/v2/ https://publicapi.gt.tweb.ttfuel.com/v1/Deliveries
uae https://uae.tweb.ttfuel.com/v2/ https://publicapi.uae.tweb.ttfuel.com/v1/Deliveries

The endpoint only accepts HTTP POST requests. The following POST parameters must be included with the request:

accessToken
batchNumber
startRecord
endRecord

And the following POST parameters may optionally be submitted with the request:

targetID

Note that the Access Token may be submitted as a POST parameter or as a HTTP Cookie.

The Start Record specifies the record number to begin inventory delivery downloads at. Note that the count begins at 1, not 0, and is inclusive. For example, if set to 1 then inventory delivery record 1 in the batch will be returned as the first record in the result set. The Start Record has the following validation rule specifications:

Rule Specification
Format Integer
Minimum value 1
Maximum value TotalRecords

The End Record specifies the record number to begin inventory delivery downloads at. Note that the count begins at 1, not 0, and is inclusive. For example, if set to 1 then inventory delivery record 1 in the batch will be returned as the last record in the result set. The End Record has the following validation rule specifications:

Rule Specification
Format Integer
Minimum value 1
Maximum value TotalRecords

Furthermore, the Start Record and End Record must satisfy the following condition: (endRecord - startRecord) < 100. Because the start and end records are inclusive, 100 inventory deliveries can be downloaded by setting startRecord=1 and endRecord=100 (not 99 inventory deliveries!).

Request Examples

A request for Inventory Delivery data that includes the Access Token from the file where it was stored during authorisation:

curl -b cookiejar.txt -skX POST -d "targetID=abc123&batchNumber=123&startRecord=1&endRecord=1" https://publicapi.tweb.com.au/v1/Deliveries

A request for Inventory Delivery data that includes the Access Token as a POST parameter in the body:

curl -skX POST -d "targetID=abc123&accessToken=0123456789ABCDEF0123456789ABCDEF01234567&batchNumber=123&startRecord=1&endRecord=1" https://publicapi.tweb.com.au/v1/Deliveries

Step 2 - Response

The response from the Deliveries endpoint has the following JSON format:

{
"Data": {
"Items": [
{
  "TankNumber": 1,
"Type": 0,
"Grade": {
"GradeNum": 2,
"Name": "Unleaded"
},
"AmbientQuantity": 1000,
"AmbientUnitPrice": 1,
"AmbientAmount": 1000,
"AmbientTemperature": 0,
"L15Quantity": 0,
"L15UnitPrice": 0,
"L15Amount": 0,
"DateTime": "2018-03-01T00:00:00",
"Reference": "",
"Notes": "",
"SiteNumber": "123456",
"RowNumber": 1
}
],
"Meta": {
"Endpoint": "/v1/Deliveries",
"SubmittedFilters": {
"batchNumber": 123,
"endRecord": 1,
"startRecord": 1
},
"TargetID": "abc123",
"Title": "Public API: Download Deliveries"
}
},
"Error": {
"Code": 0,
"Status": "OK"
}
}

The inventory delivery data is returned as a list of objects in Data.Items. Each of the properties of that object are described in the following table:

Property Description
TankNumber The number of the tank for this delivery.
Type An integer representing the type of delivery:
0: Manual measurement (hand dipped, delivery receipt, etc).
1: An Automatic Tank Gauge (ATG) supplied reading.
2: A stock delivery automatically created at a T6 or TT1000 contoller from a monitored flow record.
3: A stock delivery created by an ID triggered stock movement.
4: An externally supplied measurement.
5: A TT controller-calculated theoretical measurement.
Grade.GradeNum The grade number of the fuel.
Grade.Name The name of the fuel.
AmbientQuantity The quantity of liquid delivered at ambient temperature.
AmbientUnitPrice The delivery unit price, i.e. the cost per unit of fuel for this delivery.
AmbientAmount The monetary amount for this delivery.
AmbientTemperature The ambient temperature for this delivery.
L15Quantity The quantity of liquid delivered, corrected for 15 degrees Celsius.
L15UnitPrice The delivery unit price, i.e. the cost per unit of fuel for this delivery.
L15Amount The monetary amount for this delivery.
DateTime The delivery date and time, formatted as yyyy-MM-ddTHH:mm:ss, where T is always the literal character T.
Reference The reference string associated with this delivery. Note that the source of this value depends on the delivery Type. It may have been generated manually by the Site Operator or automatically by hardware on site.
Notes The notes string associated with this delivery.
SiteNumber The Controller's Site ID.
RowNumber The Row Number that the delivery corresponds to.

The Error JSON property is included in all responses from the TWeb Public API. The possible responses when requesting Inventory Delivery data are:

Error Code Error Name Explanation
0 OK Inventory deliveries have been returned
1 Server Error This issue either does not fit any of the other codes or is due to a bug in the Public API code.
4000 Rate Limit Exceeded This is the second request within a 1 second period.
4002 Account Inactive Account Inactive.
4003 Session Expired Session Expired.
4008 Invalid Access Token The Access Token was not valid.
4100 Invalid Record Count The specified number of records did not match the number of records found in the database.
4104 Invalid Target ID The Target ID did not conform to the specifications.
4101 Invalid Start Record The start record was not valid.
4102 Invalid End Record The end record was not valid.
4103 Invalid Page Size The start and end records resulted in more than 100 records.
4202 Invalid Batch Number The Batch Number was not valid.

Step 3 - Tagging Inventory Deliveries

Once the client has the Inventory Deliveries Batch Number, this can be used to tag inventory deliveries as received. The endpoint used for this depends on the server used by your company to login to TWeb:

T-WEB Server T-WEB Login URL API Authorisation Endpoint
www https://www.tweb.com.au/v2/ https://publicapi.tweb.com.au/v1/TagDeliveries
www2 https://www2.tweb.com.au/v2/ https://publicapi2.tweb.com.au/v1/TagDeliveries
gt https://gt.tweb.ttfuel.com/v2/ https://publicapi.gt.tweb.ttfuel.com/v1/TagDeliveries
uae https://uae.tweb.ttfuel.com/v2/ https://publicapi.uae.tweb.ttfuel.com/v1/TagDeliveries

The endpoint only accepts HTTP POST requests. The following POST parameters must be included with the request:

accessToken
batchNumber
startRecord
endRecord

And the following POST parameters may optionally be submitted with the request:

targetID

These POST paramters are identical to those from Step 2, and the same validation rules apply.

Request Examples

A request for Inventory Delivery data that includes the Access Token from the file where it was stored during authorisation:

curl -b cookiejar.txt -skX POST -d "targetID=abc123&batchNumber=123&startRecord=1&endRecord=1" https://publicapi.tweb.com.au/v1/TagDeliveries

A request for Inventory Delivery data that includes the Access Token as a POST parameter in the body:

curl -skX POST -d "targetID=abc123&accessToken=0123456789ABCDEF0123456789ABCDEF01234567&batchNumber=123&startRecord=1&endRecord=1" https://publicapi.tweb.com.au/v1/TagDeliveries

Step 3 - Response

The response from the Inventory Deliveries endpoint has the following JSON format:

{
"Error": {
"Code": 0,
"Status": "OK"
},
"Data": {
"Meta": {
"TargetID": "abc123",
"Title": "Public API: Tag Deliveries",
"Endpoint": "/v1/TagDeliveries",
"SubmittedFilters": {
"batchNumber": 123,
"startRecord": 1,
"endRecord": 1
}
},
"Items": []
}
}

The Error JSON property indicates whether the inventory delivery tagging was successful or not. The possible responses when requesting Inventory Delivery data are the same as in Step 2, with one additional possible Error response:

Error Code Error Name Explanation
4403 Unable To Tag All Inventory Deliveries Some inventory deliveries could not be tagged. Note that when this error occurs then the status will indicate how many inventory deliveries were actually tagged, but not which ones.