UPS Rates API issue for multiple shipment dates - json

I am using UPS Rates API ( JSON based with option Shoptimeintransit) to get available delivery dates for supplied shipment date.
https://www.ups.com/upsdeveloperkit/downloadresource?loc=en_CA
In DeliveryTimeInformation, I am setting pickup info.
{
"Security": {
"UsernameToken": {
"Username": "xxxxxxx",
"Password": "xxxxxxx"
},
"UPSServiceAccessToken": {
"AccessLicenseNumber": "xxxxxxxxxxx"
}
},
"RateRequest": {
"Request": {
"RequestOption": "Shoptimeintransit",
"TransactionReference": {
"CustomerContext": "Your Customer Context"
}
},
"CustomerClassification": {
"Code": "00"
},
"PickupType": {
"Code": "06"
},
"Shipment": {
"DeliveryTimeInformation": {
"PackageBillType": "07",
"Pickup": {
"Date": "20170925",
"Time": "1140"
}
},
"Shipper": {
"ShipperNumber": "xxxxxxx",
"Address": {
"City": "Kansas City",
"StateProvinceCode": "MO",
"CountryCode": "US",
"PostalCode": "xxxx"
}
},
"ShipTo": {
"Address": {
"City": "Redwood",
"StateProvinceCode": "CA",
"CountryCode": "US",
"PostalCode": "xxxx"
}
},
"ShipFrom": {
"Address": {
"City": "Kansas City",
"StateProvinceCode": "MO",
"CountryCode": "US",
"PostalCode": "xxxx"
}
},
"Package": {
"PackagingType": {
"Code": "02"
},
"Dimensions": {
"UnitOfMeasurement": {
"Code": "IN"
},
"Length": "5",
"Width": "4",
"Height": "3"
},
"PackageWeight": {
"UnitOfMeasurement": {
"Code": "LBS"
},
"Weight": "1"
}
},
"NumOfPieces": "3",
"ShipmentRatingOptions": {
"NegotiatedRatesIndicator": ""
}
}
}
}
Question is, I need available delivery dates for next N shipment dates, but API only takes single shipment date in DeliveryTimeInformation > Pickup section.
So, one possibility is to call API N times and combine results, which doesn't seems a good idea.
Anyone knows any related API that use to take pickup dates as list and return all possible delivery dates,service codes for supplied data.

The Docs state Max Allowed: 1 for DeliveryTimeInformation, so no.
You can request it for the next API update (each January and July) through customer service, but you'll have to make N requests 'till then.

Related

How to retrieve Tables with their sub-tables as json in rails?

For exemple I have several models like: Name, Location, Login,...and I want to get all tables with their sub-tables combined as a json after querying in rails, like this:
{
"name": {
"title": "mr",
"first": "brad",
"last": "gibson"
},
"location": {
"street": "9278 new road",
"city": "kilcoole",
"state": "waterford",
"postcode": "93027",
"coordinates": {
"latitude": "20.9267",
"longitude": "-7.9310"
},
"timezone": {
"offset": "-3:30",
"description": "Newfoundland"
}
},
"login": {
"uuid": "155e77ee-ba6d-486f-95ce-0e0c0fb4b919",
"username": "silverswan131",
"password": "firewall",
"salt": "TQA1Gz7x",
"md5": "dc523cb313b63dfe5be2140b0c05b3bc",
"sha1": "7a4aa07d1bedcc6bcf4b7f8856643492c191540d",
"sha256": "74364e96174afa7d17ee52dd2c9c7a4651fe1254f471a78bda0190135dcd3480"
}
}
If you're only using Rails, then you can get most of this functionality with the .as_json method provided by ActiveModel::Serializers::JSON
You can produce JSON similar to your example like so:
name = Name.first
location = Location.first
login = Login.first
ActiveRecord::Base.include_root_in_json = true
{
**name.as_json(except: :id),
**location.as_json(include: {
coordinates: { only: [:latitude, :longitude] },
timezone: { only: [:offset, :description] },
}),
**login.as_json(except: :id)
}

Structure data inside a Document database

I'm building a app that is going to serve as an agenda or a scheduling book for some services. It's planned to the app to work in a "per customer" way, Angular in the front-end and to use the new Google Firestore, for all the real time and pseudo-backendless stuff.
The question is, as I have never worked with NoSQL databases before, how should I structure the data inside Firestore?
I thought about something that would look like this:
{
//Collection
"customer-a": {
//Document
"info": {
"name": "Customer A",
"Phones": [{
"contact-name": "",
"number": ""
}],
"address": {
"type": "street",
"name": "",
"number": 0,
"neighborhood": "",
"city": "",
"state": "",
"zipcode": "",
"country": "",
"coordinates": {
"latitude": "",
"longitude": ""
}
}
},
//Document
"config": {
"active-theme": "",
"themes": [{}]
},
//Document
"customer-data": {
//SubCollection
"employees": {
//Document
"employee-a": {
"name": "",
"phone": "",
"rattings": [],
"address": {
"type": "street",
"name": "",
"number": 0,
"neighborhood": "",
"city": "",
"state": "",
"zipcode": "",
"country": ""
},
//SubCollection
"schedulings": {
//Document
"2017": {
"total": 300,
"scheduling": [{
"client": {
"name": "",
"phone": "",
"rating": 5,
},
"price": 10,
"services": [{
"name": "",
"price": 10
}],
"datetime": "",
}]
},
"2018": {
"total": 300,
"scheduling": [{
"client": {
"name": "",
"phone": "",
"classificacao": 5,
},
"price": 10,
"services": [{
"name": "",
"price": 10
}],
"datetime": "",
}]
},
}
}
},
//SubCollection
"stock": {}
}
}
}
I'm thinking on splitting the scheduling into years because I think it may grow in size a lot, but as I said, I've never worked with this kind of database, so I don't really know how much data I could nest inside a document, for example...
As an exaggerated amount of data for a base calculation I thought about around 200k "objects" that would be stored for each employee per year, is that much or it's ok to store that much data nested?
Should I keep creating sub collections inside Firestore or it should be one single collections to store only different documents and nest everything?
Hope someone can help me,
Thanks.

How to send user credentials safely through JSON

I read few articles about sending request via JSON safely and most of the questions resulted in using https(SSL).
Even if its SSL server, when we send the credentials through ajax, it can be viewed from html source right.(is that a very stupid question? i'm asking because i don't know).
Can someone direct me in the right way, how to send a request to an API securely using JSON.
Below is my sample code for UPS:
<script>
$(document).ready(function() {
//all variables are assigned before sending, I've trimmed the code
var formData = { "UPSSecurity": { "UsernameToken": { "Username": "xxxxxx", "Password": "xxxxxx" }, "ServiceAccessToken": { "AccessLicenseNumber": "xxxxxxxxxx" } }, "ShipmentRequest": { "Request": { "RequestOption": "validate", "TransactionReference": { "CustomerContext": "Test" } }, "Shipment": { "Description": "Description", "Shipper": { "Name": "Test Name", "AttentionName": "xxxxxx", "TaxIdentificationNumber": "123456", "Phone": { "Number": "1234567890", "Extension": "1" }, "ShipperNumber": "xxxxxx", "FaxNumber": "1234567890", "Address": { "AddressLine": "2311 York Rd", "City": "Sebastopol", "StateProvinceCode": "CA", "PostalCode": "95473", "CountryCode": "US" } }, "ShipTo": { "Name": to_name, "AttentionName": to_name, "Phone": { "Number": to_Phone }, "Address": { "AddressLine": to_AddressLine, "City": to_City, "StateProvinceCode": to_StateProvinceCode, "PostalCode": to_PostalCode, "CountryCode": to_CountryCode } }, "ShipFrom": { "Name": from_name, "AttentionName": from_name, "Phone": { "Number": from_Phone }, "FaxNumber": "1234567890", "Address": { "AddressLine": from_AddressLine, "City": from_City, "StateProvinceCode": from_StateProvinceCode, "PostalCode": from_PostalCode, "CountryCode": from_CountryCode } }, "PaymentInformation": { "ShipmentCharge": { "Type": "01", "BillShipper": { "AccountNumber": "xxxxxx" } } }, "Service": { "Code": service_code, "Description": service_description }, "Shi8mentRatingOptions": { "NegotiatedRatesIndicator": "0" }, "Package": { "Description": "Description", "Packaging": { "Code": "02", "Description": "Description" }, "Dimensions": { "UnitOfMeasurement": { "Code": "IN", "Description": "Inches" }, "Length": length, "Width": width, "Height": height }, "PackageWeight": { "UnitOfMeasurement": { "Code": "LBS", "Description": "Pounds" }, "Weight": weight } } }, "LabelSpecification": { "LabelImageFormat": { "Code": "GIF", "Description": "GIF" } } } };
$.ajax({
type : "POST",
url : "https://wwwcie.ups.com/rest/Ship",
crossDomain: true,
timeout : 240000,
contentType: 'application/json',
data : JSON.stringify(formData),
dataType : 'json',
success : function(response)
{
//process response
}
});
});
</script>
How can i send such a request safely by protecting my user credentials.
thanks.

How do I make a QBO v3 API Create, Update, and Delete Request with a JSON body

I'm constructing my own HTTP requests for use with the QuickBooks Online v3 REST API, 'rolling my own' in the words of Keith Palmer - Consolibyt's response to this post.
I particular, I want to create, update, and delete transactions and names using JSON-formatted request bodies. The documentation is very sparse with JSON examples, so this is all I could find:
{
...
"domain":"QBO"
"sparse":{"true","false"}
...
}
The API gives XML examples for creating, updating, and deleting transactions, and I have been able to use those in the API explorer successfully. (For other reasons, though, I don't want to work with XML. I want to work in JSON.)
In trying to figure out how to do the same thing with JSON, I did a read of an existing JournalEntry (in the API Explorer), getting this response and planning to build the request body starting from here:
{
"JournalEntry": {
"Adjustment": false,
"domain": "QBO",
"sparse": false,
"Id": "1056",
"SyncToken": "2",
"MetaData": {
"CreateTime": "2014-02-07T13:21:51-08:00",
"LastUpdatedTime": "2014-02-07T13:29:53-08:00"
},
"DocNumber": "4",
"TxnDate": "2014-02-08",
"CurrencyRef": {
"value": "USD",
"name": "United States Dollar"
},
"Line": [
{
"Id": "0",
"Description": "test entry",
"Amount": 102.0,
"DetailType": "JournalEntryLineDetail",
"JournalEntryLineDetail": {
"PostingType": "Credit",
"AccountRef": {
"value": "57",
"name": "Miscellaneous Income"
}
}
},
{
"Id": "1",
"Description": "test entry (UPDATED!)",
"Amount": 252.0,
"DetailType": "JournalEntryLineDetail",
"JournalEntryLineDetail": {
"PostingType": "Debit",
"AccountRef": {
"value": "29",
"name": "6240 Miscellaneous"
}
}
},
{
"Id": "2",
"Description": "test entry",
"Amount": 150.0,
"DetailType": "JournalEntryLineDetail",
"JournalEntryLineDetail": {
"PostingType": "Credit",
"AccountRef": {
"value": "82",
"name": "12100 Inventory Asset"
}
}
}
]
},
"time": "2014-02-07T14:21:16.181-08:00"
}
Here's the request body I'm using for an Update operation (on the same JournalEntry page of the API Explorer) -- note that I'm only changing the DocNumber (from 4 to 12345):
{
"Adjustment": false,
"domain": "QBO",
"sparse": false,
"Id": "1056",
"SyncToken": "2",
"MetaData": {
"CreateTime": "2014-02-07T13:21:51-08:00",
"LastUpdatedTime": "2014-02-07T13:29:53-08:00"
},
"DocNumber": "12345",
"TxnDate": "2014-02-08",
"CurrencyRef": {
"value": "USD",
"name": "United States Dollar"
},
"Line": [
{
"Id": "0",
"Description": "test entry",
"Amount": 102.0,
"DetailType": "JournalEntryLineDetail",
"JournalEntryLineDetail": {
"PostingType": "Credit",
"AccountRef": {
"value": "57",
"name": "Miscellaneous Income"
}
}
},
{
"Id": "1",
"Description": "test entry (UPDATED!)",
"Amount": 252.0,
"DetailType": "JournalEntryLineDetail",
"JournalEntryLineDetail": {
"PostingType": "Debit",
"AccountRef": {
"value": "29",
"name": "6240 Miscellaneous"
}
}
},
{
"Id": "2",
"Description": "test entry",
"Amount": 150.0,
"DetailType": "JournalEntryLineDetail",
"JournalEntryLineDetail": {
"PostingType": "Credit",
"AccountRef": {
"value": "82",
"name": "12100 Inventory Asset"
}
}
}
]
}
Here's the Response Body I get back:
{"Fault":{"Error":[{"Message":"An application error has occurred while processing your request","Detail":"System Failure Error: null","code":"10000"}],"type":"SystemFault"},"time":"2014-02-07T14:36:18.888-08:00"}
I'm also trying a sparse update, as per these instructions, just to keep things simple. The request body:
{
"sparse": "true",
"Id": "1056",
"SyncToken": "2",
"DocNumber": "12345"
}
The response body I get back (in bright red):
{"Fault":{"Error":[{"Message":"An application error has occurred while processing your request","Detail":"System Failure Error: null","code":"10000"}],"type":"SystemFault"},"time":"2014-02-07T14:05:05.197-08:00"}
I have a feeling the problem here is something small. Can you point out what it is? Alternatively, if you have a working example of a JSON request body (for create, update, and delete operations of a transaction, ideally), that would be very helpful too (as hopefully I could use it as a template).
You need to add Accept : application/json to your header.

Problem retrieving data from json output

I am a noob when it comes to json. The more I use it, I am starting to like it. I have a output that looks like this
[
{
"product": {
"id": "6",
"category": "Books",
"created": "2010-04-13 15:15:18",
},
"availability": [
{
"country": "United Kingdom",
"price": "$13.99",
},
{
"country": "Germany",
"price": "$13.99",
}
]
}
]
Actually I have listed only one product, But output has many products listed. I want to loop through this json output and get all the product's category, countries where they are available and price using fbjs.
I appreciate any help.
Thanks.
If your JSON is like this,
var products = [
{
"product": {
"id": "6",
"category": "Books",
"created": "2010-04-13 15:15:18",
},
"availability": [
{
"country": "United Kingdom",
"price": "$13.99",
},
{
"country": "Germany",
"price": "$13.99",
}
]
},
{
"product": {
"id": "7",
"category": "Books",
"created": "2010-04-13 15:15:18",
},
"availability": [
{
"country": "United Kingdom",
"price": "$13.99",
},
{
"country": "Germany",
"price": "$13.99",
}
]
}
]
You can iterate through:
for(var index = 0; index < products.length; index++) {
alert(products[index].product.category);
}