Create Checks with Quickbooks API - quickbooks

Please help me on writing a check using the QuickBooks online(Qbo) API. I tried to do that but i'm always getting an error saying "Error validating Detail Lines:At least one detail line is required." Sample Code is in Below.. How should I add Lines for Checks.
Dim existingChk = New Qbo.Check()
Dim existingChks = commonService.FindAll(existingChk, 1, 10).ToList()
Dim payment = New Qbo.Payment()
Dim payments = commonService.FindAll(payment, 1, 10).ToList()
Dim qboCheck = New Intuit.Ipp.Data.Qbo.CheckHeader()
Dim bank = New Intuit.Ipp.Data.Qbo.Account()
bank.Type = Intuit.Ipp.Data.Qbo.AccountTypeEnum.Asset
Dim Banks = commonService.FindAll(bank, 1, 100).ToList()
Dim accountId As New Qbo.IdType
For Each bnk As Intuit.Ipp.Data.Qbo.Account In Banks
If bnk.Name = "Test Bank" Then
accountId = bnk.Id
End If
Next
qboCheck.BankAccountId = accountId
qboCheck.BankAccountName = "Test Bank"
qboCheck.TotalAmt = 20.0
qboCheck.Currency = Intuit.Ipp.Data.Qbo.currencyCode.USD
qboCheck.TxnId = payments(0).Id
Dim qboCustomer = New Intuit.Ipp.Data.Qbo.Customer()
Dim qboCustomers = commonService.FindAll(qboCustomer, 1, 10).ToList()
For Each cus As Intuit.Ipp.Data.Qbo.Customer In qboCustomers
If cus.Name.Contains("Customer1") Then
qboCheck.EntityId = cus.Id
End If
Next
qboCheck.EntityType = Qbo.EntityTypeEnum.Customer
Dim check = New Intuit.Ipp.Data.Qbo.Check()
check.Header = qboCheck
check.Id = New Qbo.IdType
check.Id.idDomain = existingChks(0).Id.idDomain
check.Id.Value = CInt(existingChks(0).Id.Value) + 1
Dim resultCheck As Qbo.Check = TryCast(commonService.Add(check), Qbo.Check)

Looks like it is a bug in .net devkit(I'm not 100% sure).
JavaDocs says accountId and itemId both are inherited from LinePurchase(PFB snapshot). But in .net devkit, I don't see those fields neither in LinePurchase nor in LineBase.
JavaDoc Ref - http://developer-static.intuit.com/SDKDocs/QBV2Doc/ipp-java-devkit-2.0.10-SNAPSHOT-javadoc/
API endpoints are working fine.
https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/v2/0400_quickbooks_online/check#Sample_Create_Request_XML
<?xml version="1.0" encoding="utf-8" ?>
<Check xmlns:ns2="http://www.intuit.com/sb/cdm/qbo" xmlns="http://www.intuit.com/sb/cdm/v2">
<Header>
<TxnDate>2013-08-09</TxnDate>
<BankAccountId>44</BankAccountId>
<EntityId>2</EntityId>
</Header>
<Line>
<Desc>Hard Disks</Desc>
<Amount>500</Amount>
<BillableStatus>NotBillable</BillableStatus>
<ItemId>4</ItemId>
<Qty>10</Qty>
<UnitPrice>50</UnitPrice>
</Line>
</Check>
PN -
<BankAccountId> : This account should be a 'checking' type.
<ItemId> : Item should have a 'ExpenseAccountRef' tag.
You can test this usecase, using ApiExplorer tool.
Link - https://developer.intuit.com/apiexplorer?apiname=V2QBO
If possible I'll try this using .net devkit on monday and confirm if it is a bug in .net devkit.
Thanks

Adding pseudo code for c# for BillpaymentHeader.
Similarly you can use it for CheckLine:
billheader.ItemsElementName = new ItemsChoiceType[1];
billheader.ItemsElementName[0] = ItemsChoiceType.BankAccountId;
billheader.Items = new object[1];
billheader.Items[0] = new Intuit.Ipp.Data.Qbo.IdType() { idDomain = Intuit.Ipp.Data.Qbo.idDomainEnum.QBO, Value = "1" };
Refer- How to add AccountID or ItemID when creating Checks in QuickBooks

If you have bill already then you can simply use billpayment API to create checks.
URL : https://quickbooks.api.intuit.com/v3/company/111111111111/billpayment?minorversion=4
request JSON data:
{
"VendorRef": {
"value": "1",
"name": "vendor_name"
},
"PayType": "Check",
"CheckPayment": {
"BankAccountRef": {
"value": "1",
"name": "Test Account"
}
},
"TotalAmt": 100.00,
"PrivateNote": "Acct. 1JK90",
"Line": [
{
"Amount": 100.00,
"LinkedTxn": [
{
"TxnId": "1",
"TxnType": "Bill"
}
]
}
]
}

Related

How do I use information from Roblox Games API?

So I am trying to make some code that gets information about games using the Roblox API. I do get data back when I send a request, but I can't figure out a way to use the data in the code. Because when I decode it, it looks like this:
{
["data"] = ▼ {
[1] = ▼ {
["allowedGearCategories"] = {},
["allowedGearGenres"] = ▶ {...},
["copyingAllowed"] = false,
["createVipServersAllowed"] = false,
["created"] = <creation date>,
["creator"] = ▶ {...},
["description"] = "",
["favoritedCount"] = 0,
["genre"] = "Comedy",
["id"] = <the id>,
["isAllGenre"] = false,
["isFavoritedByUser"] = false,
["isGenreEnforced"] = true,
["maxPlayers"] = 10,
["name"] = <the name>,
["playing"] = 0,
["rootPlaceId"] = <the id>,
["studioAccessToApisAllowed"] = false,
["universeAvatarType"] = "PlayerChoice",
["updated"] = <update date>,
["visits"] = 0
}
}
}
I censored some of the information about which game it is, but that information isn't important here. The important thing is that it says "1" under "data", and if I type that into the code, it uses it as a number. So I can't access anything further down in the list than "data".
Here is my code, if it helps:
local universe = Proxy:Get("https://api.roblox.com/universes/get-universe-containing-place?placeid="..placeId).body
local universeDecoded = http:JSONDecode(universe)
local universeId = universeDecoded.UniverseId
local placeInfo = http:JSONDecode(Proxy:Get("https://games.roblox.com/v1/games?universeIds="..universeId).body)
print(placeInfo.data)
Also, sorry for not knowing a lot of programming words, so I say stuff like "further down in the list". But I hope it's clear what I mean.
I figured it out myself. I just had to write
print(placeInfo.data[1])

Corda - Redeem Tokens - Token SDK + Accounts

I'm trying to use the token SDK for the first time and I am not being able to redeem the correct amount of tokens from a specific Corda account.
How I am issuing the tokens:
val accountInfo = accountService.accountInfo(accountId)
val accountKey = subFlow(RequestKeyForAccountFlow(accountInfo.state.data,initiateFlow(ourIdentity)))
val tokens = 10 of MyTokenType issuedBy ourIdentity heldBy accountKey
subFlow(IssueTokens(listOf(tokens), emptyList()))
I also implemented the function report() to Query the Vault to GET the amount of tokens for each account:
fun report (accountInfo: StateAndRef<AccountInfo>) : Amount<TokenType> {
val criteria = QueryCriteria.VaultQueryCriteria(
status = Vault.StateStatus.UNCONSUMED,
relevancyStatus = Vault.RelevancyStatus.RELEVANT,
externalIds = listOf (accountInfo.state.data.identifier.id)
)
val exprAggregate=
builder {
com.r3.corda.lib.tokens.contracts.internal.schemas.PersistentFungibleToken::amount.sum()
}
val aggregateCriteria =
QueryCriteria.VaultCustomQueryCriteria(exprAggregate)
val otherResult = serviceHub.vaultService.queryBy(
criteria = criteria.and(aggregateCriteria),
contractStateType = FungibleToken::class.java).otherResults[0]
val sum= if (otherResult == null) 0 else (otherResult as Long)
return sum.MyToken
If I issue 10 tokens for a specific account I receive this on the GET that calls my report function:
{
"value": {
"quantity": 10,
"displayTokenSize": 1,
"token": {
"tokenIdentifier": "MyToken",
"fractionDigits": 0,
"displayTokenSize": 1,
"customTokenType": false,
"regularTokenType": true,
"tokenClass": "com.r3.corda.lib.tokens.contracts.types.TokenType",
"pointer": false
}
},
"message": "Tokens in account."
}
This shows me that I am actually Issuing the tokens right, since the quantity of tokens is the 10 tokens that I just issued.
What I am doing in the Redeem flow:
val accountInfo = accountService.accountInfo(accountId)
val tokens: Amount<TokenType> = 10.MyToken
val heldByAccount: QueryCriteria = QueryCriteria.VaultQueryCriteria()
.withExternalIds(Collections.singletonList(accountInfo.state.data.identifier.id))
subFlow(RedeemFungibleTokens(amount = tokens, issuer = ourIdentity, observers = emptyList(), queryCriteria = heldByAccount))
But When I do the GET to run my report() functin it just gives me this as a response:
{
"value": {
"quantity": 0,
"displayTokenSize": 1,
"token": {
"tokenIdentifier": "MyToken",
"fractionDigits": 0,
"displayTokenSize": 1,
"customTokenType": false,
"regularTokenType": true,
"tokenClass": "com.r3.corda.lib.tokens.contracts.types.TokenType",
"pointer": false
}
},
"message": "Tokens in account."
}
This shows me that my Redeem flow it's not working because it is not only redeeming 10 tokens but all the tokens for that account, since the quantity is equals to zero.
Any ideas on how I can fix this?
Thanks a lot
I believe the answer is add a changeHolder to the RedeemFungibleTokens sub-flow you are calling.
Take a look at:
https://training.corda.net/libraries/accounts-exercise/

how to set custom example in #ApiResponse in swagger [duplicate]

I am facing issue with example in response.
#ApiResponse(code=200,
message="fetch list of Service/Config Resources",
response = testing.class,
responseContainer = "List",
examples=#Example(
value = #ExampleProperty(
mediaType = MediaType.APPLICATION_JSON_VALUE,
value = "{testingId: 1234, testingName = Testing Name}"
)
)
)
But getting response example as
[
{
"testingId": "string",
"testingName": "string"
}
]

casting a List<object> into NancyFx response

I am trying to build an Nancy OData support app using LinqToQuerystring. I got below sample code. it is working for any query url like:
http:/test/?$filter=Recommended eq true
Get["/test"] = _ =>
{
var dict = (IDictionary)Request.Query.ToDictionary();
new List<Movie>
{
new Movie
{
Title = "Matrix (The)",
ReleaseDate = new DateTime(1999, 3, 31),
DurationInMinutes = 136,
MetaScore = 73,
Director = "Wachowski Brothers",
Recommended = true
},
new Movie
{
Title = "There and Back Again, An Unexpected Journey",
ReleaseDate = new DateTime(2012, 12, 14),
DurationInMinutes = 169,
MetaScore = 58,
Director = "Peter Jackson",
Recommended = false
}
}.AsQueryable()
.LinqToQuerystring(dict);
return dict;
}
You can solve this by calling ToDictionary first.
i.e
var dict = (IDictionary<string, object>) Request.Query.ToDictionary();
...
.LinqToQuerystring(dict);
This is probably because of the way LinqToQuerystring handles Dictionary under the hood, outputting them in an intermediate window causes:
(IDictionary<string, object>) Request.Query
{Nancy.DynamicDictionary}
[Nancy.DynamicDictionary]: {Nancy.DynamicDictionary}
Keys: Count = 2
Values: Count = 2
(IDictionary<string, object>) Request.Query.ToDictionary()
Count = 2
[0]: {[one, one]}
[1]: {[two, 2]}
Edit:
Based on your comment I assume you want to ALWAYS return JSON.
If that's the case the way you would do that is to return:
return Response.AsJson(dict);
This will serialize the dictionary as JSON for you.

FedEx Webservice for printing Multiple shipping labels

I am trying to connect to the FedEx shipping webservice v8.
Everything works fine when I only have one RequestedPackageLineItems set. When I add two items I get the following error.
"Invalid package count or invalid package sequence number."
My Code is as follows
ProcessShipmentRequest request = CreatePendingShipmentRequest();
ShipService service = new ShipService();
ProcessShipmentReply reply = service.processShipment(request);
...
private static ProcessShipmentRequest CreatePendingShipmentRequest()
{
ProcessShipmentRequest request = new ProcessShipmentRequest();
request.WebAuthenticationDetail = new WebAuthenticationDetail();
request.WebAuthenticationDetail.UserCredential = new WebAuthenticationCredential();
request.WebAuthenticationDetail.UserCredential.Key = "XXX";
request.WebAuthenticationDetail.UserCredential.Password = "XXX";
request.ClientDetail = new ClientDetail();
request.ClientDetail.AccountNumber = "XXX";
request.ClientDetail.MeterNumber = "XXX";
request.TransactionDetail = new TransactionDetail();
request.TransactionDetail.CustomerTransactionId = "*** Ground Domestic Shipping Request v8 using C# ***";
request.Version = new VersionId();
//Inside this method I set request.RequestedShipment.PackageCount = "2";
SetShipmentDetails(request);
SetPackageLineItems(request);
return request;
}
private static void SetPackageLineItems(ProcessShipmentRequest request)
{
request.RequestedShipment.RequestedPackageLineItems = new RequestedPackageLineItem[2];
request.RequestedShipment.RequestedPackageLineItems[0] = new RequestedPackageLineItem();
request.RequestedShipment.RequestedPackageLineItems[0].SequenceNumber = "1";
request.RequestedShipment.RequestedPackageLineItems[0].Weight = new Weight();
request.RequestedShipment.RequestedPackageLineItems[0].Weight.Value = 50.0M;
request.RequestedShipment.RequestedPackageLineItems[0].Weight.Units = WeightUnits.LB;
request.RequestedShipment.RequestedPackageLineItems[0].ItemDescription = "Item";
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions = new Dimensions();
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Length = "108";
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Width = "5";
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Height = "5";
request.RequestedShipment.RequestedPackageLineItems[0].Dimensions.Units = LinearUnits.IN;
request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences = new CustomerReference[3];
request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[0] = new CustomerReference();
request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[0].CustomerReferenceType = CustomerReferenceType.CUSTOMER_REFERENCE;
request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[0].Value = "[LOT NUMBER]";
request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[1] = new CustomerReference();
request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[1].CustomerReferenceType = CustomerReferenceType.INVOICE_NUMBER;
request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[1].Value = "45646";
request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[2] = new CustomerReference();
request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[2].CustomerReferenceType = CustomerReferenceType.P_O_NUMBER;
request.RequestedShipment.RequestedPackageLineItems[0].CustomerReferences[2].Value = "456446";
request.RequestedShipment.RequestedPackageLineItems[1] = new RequestedPackageLineItem();
request.RequestedShipment.RequestedPackageLineItems[1].SequenceNumber = "2";
request.RequestedShipment.RequestedPackageLineItems[1].Weight = new Weight();
request.RequestedShipment.RequestedPackageLineItems[1].Weight.Value = 50.0M;
request.RequestedShipment.RequestedPackageLineItems[1].Weight.Units = WeightUnits.LB;
request.RequestedShipment.RequestedPackageLineItems[1].ItemDescription = "Item";
....
}
Found out how to do this.
In order to get multiple shipping labels into one pdf the process is as follows.
Create a request
Fill in the shipping info
Post and get a reply.
Save that replay and the byte array and MasterShippingID
Create a new request and assign the master shipping id to it.
Added shipping weight and dimensions
Post and get reply
Save byte array with the other
Continue until all shipments are generated (max 200 per master shipping id)
Merge all the pdfs returned from FedEx into one pdf.
Do a happy dance.
A simpler approach, (though there is a cost) is the Shiprush SDK. It lets you build a single XML block and let ShipRush do all the funny stuff with fedex (or whoever).
They also support their tool.

Resources