I've building out a small app that connects to a Quickbooks API via an SDK. The SDK provides batch operations to help reduce the number of API requests needed.
However, I'm hoping to make a large amount of requests (ie: bulk deletes, uploads in the 100s/1000s). I've gotten the deletes to work, however, now I'm hoping to integrate Laravel's Queue system so that any items in the $batch that fail (due to these business-rules or other reasons) are sent to a worker who will reattempt them after waiting a minute .
Below is an example of a delete request.
class QuickBooksAPIController extends Controller
{
public function batchDelete(Request $request, $category)
{
$chunks = array_chunk($request->data, 30);
foreach ($chunks as $key => $value) {
$batch[$key] = $this->dataService()->CreateNewBatch();
foreach ($value as $id) {
$item = $this->dataService()->FindById($category, $id);
$batch[$key]->AddEntity($item, $id, "delete");
}
$batch[$key]->Execute();
}
return response()->json(['message' => 'Items Deleted'], 200);
}
}
The documentations are a bit sparse for my scenario though. How can I get the failed batch items on order to try again?
Is using batches even the right choice here? Because I have to hit the API anyway to get the $item... which doesn't make sense to me (I think I'm doing something wrong there).
EDIT:
I intentionally sent out a request with more then 30 items and this is the failure message. Which doesn't have the values that didn't make the cut.
EDIT#2:
Ended up using array_chunk to separate the payload into 30 items (which is the limit of the API). Doing so helps process many requests. I've adjusted my code above to represent my current code.
How can I get the failed batch items on order to try again?
If you look at Intuit's documentation, you can see that the HTTP response the API returns contains this information. Here's the example request they show:
{
"BatchItemRequest": [
{
"bId": "bid1",
"Vendor": {
"DisplayName": "Smith Family Store"
},
"operation": "create"
},
{
"bId": "bid2",
"operation": "delete",
"Invoice": {
"SyncToken": "0",
"Id": "129"
}
},
{
"SalesReceipt": {
"PrivateNote": "A private note.",
"SyncToken": "0",
"domain": "QBO",
"Id": "11",
"sparse": true
},
"bId": "bid3",
"operation": "update"
},
{
"Query": "select * from SalesReceipt where TotalAmt > '300.00'",
"bId": "bid4"
}
]
}
And the corresponding response:
{
"BatchItemResponse": [
{
"Fault": {
"type": "ValidationFault",
"Error": [
{
"Message": "Duplicate Name Exists Error",
"code": "6240",
"Detail": "The name supplied already exists. : Another customer, vendor or employee is already using this \nname. Please use a different name.",
"element": ""
}
]
},
"bId": "bid1"
},
{
"Fault": {
"type": "ValidationFault",
"Error": [
{
"Message": "Object Not Found",
"code": "610",
"Detail": "Object Not Found : Something you're trying to use has been made inactive. Check the fields with accounts, customers, items, vendors or employees.",
"element": ""
}
]
},
"bId": "bid2"
},
{
"Fault": {
"type": "ValidationFault",
"Error": [
{
"Message": "Stale Object Error",
"code": "5010",
"Detail": "Stale Object Error : You and root were working on this at the same time. root finished before you did, so your work was not saved.",
"element": ""
}
]
},
"bId": "bid3"
},
{
"bId": "bid4",
"QueryResponse": {
"SalesReceipt": [
{
"TxnDate": "2015-08-25",
"domain": "QBO",
"CurrencyRef": {
"name": "United States Dollar",
"value": "USD"
},
"PrintStatus": "NotSet",
"PaymentRefNum": "10264",
"TotalAmt": 337.5,
"Line": [
{
"Description": "Custom Design",
"DetailType": "SalesItemLineDetail",
"SalesItemLineDetail": {
"TaxCodeRef": {
"value": "NON"
},
"Qty": 4.5,
"UnitPrice": 75,
"ItemRef": {
"name": "Design",
"value": "4"
}
},
"LineNum": 1,
"Amount": 337.5,
"Id": "1"
},
{
"DetailType": "SubTotalLineDetail",
"Amount": 337.5,
"SubTotalLineDetail": {}
}
],
"ApplyTaxAfterDiscount": false,
"DocNumber": "1003",
"PrivateNote": "A private note.",
"sparse": false,
"DepositToAccountRef": {
"name": "Checking",
"value": "35"
},
"CustomerMemo": {
"value": "Thank you for your business and have a great day!"
},
"Balance": 0,
"CustomerRef": {
"name": "Dylan Sollfrank",
"value": "6"
},
"TxnTaxDetail": {
"TotalTax": 0
},
"SyncToken": "1",
"PaymentMethodRef": {
"name": "Check",
"value": "2"
},
"EmailStatus": "NotSet",
"BillAddr": {
"Lat": "INVALID",
"Long": "INVALID",
"Id": "49",
"Line1": "Dylan Sollfrank"
},
"MetaData": {
"CreateTime": "2015-08-27T14:59:48-07:00",
"LastUpdatedTime": "2016-04-15T09:01:10-07:00"
},
"CustomField": [
{
"DefinitionId": "1",
"Type": "StringType",
"Name": "Crew #"
}
],
"Id": "11"
}
],
"startPosition": 1,
"maxResults": 1
}
}
],
"time": "2016-04-15T09:01:18.141-07:00"
}
Notice the separate response object for each request.
The bId value is a unique value you send in the request, which is then echo'd back to you in the response, so you can match up the requests you send with the responses you get back.
Here's the docs:
https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/batch#sample-batch-request
Is using batches even the right choice here?
Batches make a lot of sense when you are doing a lot of things all at once.
The way you're trying to use them is... weird. What you should probably be doing is:
Batch 1
- go find all your items
Batch 2
- delete all the items
Your existing code doesn't make sense because you're trying to both find the item and delete the item in the exact same batch HTTP request, which isn't possible via the API.
I intentionally sent out a request with more then 30 items and this is the failure message.
No, it's not. That's a PHP error message - you have an error in your code.
You need to fix the PHP error, and then look at the actual response you're getting back from the API.
I am using a Facebook graph to fetch comments on particular posts. The response is something like this
{
"data": [
{
"message": "43211234",
"created_time": "2021-01-09T05:33:14+0000",
"from": {
"name": "USER NAME",
"id": "USER ID"
},
"id": "COMMENT ID"
}
],
"paging": {
"cursors": {
"before": "M...",
"after": "M.."
},
"next": "https://graph.facebook.com/v9.0/10...."
}
}
the response looks good, but I also want a shareable messenger link of the user who has commented so that I can talk to that person later. is there any solution for this? I searched for it but could not find any solution.
My bot is registered in several groups and receives data from them.
when receive the the json code.
{
"update_id": 753984481,
"message": {
"message_id": 158011,
"from": {
"id": 212105015,
"first_name": "\u0634\u0631\u06a9\u062a \u0635\u0628\u0627 \u0645\u0647\u0631 \u0633\u06cc\u0631\u0627\u0641"
},
"chat": {
"id": -196924840,
"title": "\u067e\u0631 \u067e\u0631\u0648\u0627\u0632 \u0635\u0628\u0627 \u0645\u0647\u0631 \u0633\u06cc\u0631\u0627\u0641",
"type": "group",
"all_members_are_administrators": true
},
"date": 1500091212,
"photo": [
{
"file_id": "AgADBAAD9qkxG98UMFNewex76YKoYAr-vBkABEvcu9cjuXx1WCQDAAEC",
"file_size": 1168,
"width": 67,
"height": 90
}
]
}
}
How do I know which message is sent from (Groups)?
as you can see, in your json message.chat.type is equal to "group", when your bot receives a message from a channel, its type value will be equal to "channel".
other difference between channels and groups is that the message.chat.id of channels are bigger (13 digit numbers)
Have built an video app that publish user actions towards Facebook.
In this app i have implemented an "Favorite" function that i have hooked up towards a basic open graph action "og.like"
I want to be able to display video's that user liked and apply my own styling to that.
Basically i want to display "Title" "Url" & "Image"
So i use the PHP-SDK towards authored user with active access token and execute
$response = $facebook->api(
'me/og.likes',
'GET'
);
// handle the response
How do i now sort out my correct fields and display them ?
Am not hardcore at either php or javascript but will be able to sort this out if i just can get a little push in the right direction. Like just showing the raw data
Update
Finally a little progress, adding
print_r ($response);
Will write out the raw data, Now i know that am on the right way.
Array returned
{
"data": [
{
"id": "123",
"from": {
"name": "Mathias",
"id": "APP_ID"
},
"start_time": "X",
"end_time": "X",
"publish_time": "X",
"application": {
"name": "APP_Name",
"namespace": "",
"id": "321"
},
"data": {
"object": {
"id": "139",
"url": "Url to like",
"type": "video.tv_show",
"title": "title"
}
},
"type": "og.likes",
"no_feed_story": false,
"likes": {
"count": 0,
"can_like": true,
"user_likes": false
},
"comments": {
"count": 0,
"can_comment": true,
"comment_order": "chronological"
}
},
And then the next..
From every app "like" i would like to display Url ,Title & Image
From what i understand so far my main problem is that this is nested arrays, Did try with single level arrays and there i did manage to display correct data just by
echo $response[name];
So how do i digg in and loop this around, All tips are welcome,
{
"id": "139",
"url": "url",
"type": "video.tv_show",
"title": "titke",
"image": [
{
"url": "image_URL",
"secure_url": "image_URL",
"type": "image/jpg",
"width": 1024,
"height": 576
}
Here's an example:
<?php foreach ( $response['data'] as $data ): ?>
<?php $Object = $data['data']['object']; ?>
<?php echo $Object['title']; ?><br />
<?php endforeach; ?>
I want to get details of public photo of any user's facebook account.
here is my image url : http://www.facebook.com/photo.php?fbid=346729048691589&set=a.346719012025926.83282.100000634900314&type=1&l=f48e02a2e3&permPage=1
and i want details of this photo so i have generated url like : http://graph.facebook.com/346729048691589/albums but getting data as blank array. and also in my album all the photos are public.
I read this url : How to use Facebook Photos in an iPhone App? and example getting the result and i want the same result also but some how i am not getting it.
And i read that we don't require access token if we want to use any public details of facebook but here i am not getting the result.
So Can any one help me?
Thanks
How to get data(json array) of facebook public photo by using photo url?
What I did was to take the fbid from the querystring of your image url in your question. Then I went to the graph API explorer tool and brought it up. See link: https://developers.facebook.com/tools/explorer?method=GET&path=346729048691589
When I did that it returned:
{
"id": "346729048691589",
"from": {
"name": "Development SandBox",
"id": "100000634900314"
},
"picture": "http://photos-c.ak.fbcdn.net/hphotos-ak-snc7/421606_346729048691589_216224001_s.jpg",
"source": "http://sphotos.xx.fbcdn.net/hphotos-snc7/421606_346729048691589_216224001_n.jpg",
"height": 469,
"width": 700,
"images": [
{
"width": 700,
"height": 469,
"source": "http://sphotos.xx.fbcdn.net/hphotos-snc7/s720x720/421606_346729048691589_216224001_n.jpg"
},
{
"width": 180,
"height": 120,
"source": "http://photos-c.ak.fbcdn.net/hphotos-ak-snc7/421606_346729048691589_216224001_a.jpg"
},
{
"width": 130,
"height": 87,
"source": "http://photos-c.ak.fbcdn.net/hphotos-ak-snc7/421606_346729048691589_216224001_s.jpg"
},
{
"width": 75,
"height": 50,
"source": "http://photos-c.ak.fbcdn.net/hphotos-ak-snc7/421606_346729048691589_216224001_t.jpg"
}
],
"link": "http://www.facebook.com/photo.php?fbid=346729048691589&set=a.346719012025926.83282.100000634900314&type=1",
"icon": "http://static.ak.fbcdn.net/rsrc.php/v1/yz/r/StEh3RhPvjk.gif",
"created_time": "2012-02-10T11:14:42+0000",
"position": 2,
"updated_time": "2012-02-10T11:14:43+0000",
"type": "photo"
}