Using the Gmail API call
https://www.googleapis.com/gmail/v1/users/userId/messages/id
return chats with label SENT
I have used the following code for getting the message content
$url = "https://www.googleapis.com/gmail/v1/users/$useremail/messages/$messageid?format=full";
$response = $gmailInstance->performHttpRequest($gmailAuthObj, $useremail, $url);
$responseBody = json_decode($response->getResponseBody(), TRUE);
I got the following response for the above API call
{
"id": msgid,
"threadId": threadid,
"labelIds": [
"CHAT",
"SENT"
],
"snippet": "sometext",
"historyId": 7 digit numeric,
"internalDate": "1371160444361",
"payload": {
"partId": "",
"mimeType": "text/html",
"filename": "",
"headers": [{
"name": "From",
"value": "Test User \u003ctuser#tdom.com\u003e"
}],
"body": {
"size": 20,
"data": somerandomstring
}
},
"sizeEstimate": 100
}
Does anybody know why the API response return chat message with SENT label in it? Is there a way to avoid this (SENT label from chat response)?
Related
I believe I am successfully posting a new post to the endpoint
https://api.linkedin.com/v2/ugcPosts
using (similar to)
{
"author": "urn:li:organization:1234567",
"lifecycleState": "PUBLISHED",
"specificContent": {
"com.linkedin.ugc.ShareContent": {
"shareCommentary": {
"attributes": [],
"text": "Some share text"
}
}
},
"visibility": {
"com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
}
}
The response I get is
{"id":"urn:li:share:01234567890123456789"}
But then when I go to the company page, the post is not visible. Note that the IDs are redacted here. Is there another step I have to take?
edit: I went to verify the post with the endpoint https://api.linkedin.com/v2/ugcPosts/[redacted URN]?viewContext=AUTHOR and my post is a success
{
"lifecycleState": "PUBLISHED",
"specificContent": {
"com.linkedin.ugc.ShareContent": {
"shareCommentary": {
"inferredLocale": "en_US",
"attributes": [],
"text": "Test article sharing article on LinkedIn API , please ignore"
},
"media": [
{
"media": "urn:li:digitalmediaAsset:XXXXXXXXXXXXXX",
"title": {
"attributes": [],
"text": "image"
},
"thumbnails": [],
"status": "READY"
}
],
"shareFeatures": {
"hashtags": []
},
"shareMediaCategory": "IMAGE"
}
},
"visibility": {
"com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
},
"created": {
"actor": "urn:li:person:XXXXXXXXXXXXXX",
"time": 1649285262053
},
"author": "urn:li:organization:XXXXXXXXXXXXXX",
"clientApplication": "urn:li:developerApplication:XXXXXXXXXXXXXX",
"versionTag": "0",
"id": "urn:li:share:XXXXXXXXXXXXXX",
"firstPublishedAt": 1649285262053,
"lastModified": {
"actor": "urn:li:csUser:7",
"time": 1649285262122
},
"distribution": {
"externalDistributionChannels": [],
"distributedViaFollowFeed": true,
"feedDistribution": "MAIN_FEED"
},
"contentCertificationRecord": "{\"spamRestriction\":{\"classifications\":[],\"contentQualityClassifications\":[],\"systemName\":\"MACHINE_SYNC\",\"lowQuality\":false,\"contentClassificationTrackingId\":\"073BB82AD64A7608E3F142B6D0362E3D\",\"contentRelevanceClassifications\":[],\"spam\":false},\"originCountryCode\":\"ca\",\"modifiedAt\":1649285262024,\"contentHash\":{\"extractedContentMd5Hash\":\"0725A7E31B109EB4CFB84D2648CE3EC8\",\"lastModifiedAt\":1649285262023}}"
}
What am I missing here?? Why is it now showing on LinkedIn??
edit2 : went ahead and tried to share the post again, now all the posts are gone from the company page when viewed as admin, but showing (except the API posts) as a member.... How broken is this API ??????
I will answer my own post. Uploads using CurlFile DO NOT WORK, you have to use Guzzle... Once the upload & publishing are done, the feed will unbreak itself.. The company page will be broken if the endpoint is still waiting for upload while you post.
$client = new \GuzzleHttp\Client();
$res = $client->request('PUT', $__url, [
'headers' => [
'Authorization' => 'Bearer ' . $__token
],
'body' => fopen($__file, 'r')
]
);
if($res){
$res = json_decode($res->getBody());
}
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'm working on integrating PayPal to my site, however I've got to the point where it requests me to pass the id back to the client. And I'm not sure how to do this. Any help would be great.
This is the last JSON code I get from the PayPal servers. As I'm doing it from the server side code.
{
"id":"PAY-5VL741754E714161BLHUWCKY",
"intent":"sale",
"state":"created",
"payer":
{
"payment_method":"paypal"
},
"transactions":
[{
"amount":
{
"total":"4.00",
"currency":"USD",
"details":
{
"subtotal":"2.00",
"tax":"2.00",
"shipping":"1.00",
"shipping_discount":"-1.00"
}
},
"description":"The payment transaction description.",
"custom":"PlayerID",
"invoice_number":"merchant invoice",
"item_list":
{
"items":
[{
"name":"item 1",
"description":"item 1 description",
"price":"1.00",
"currency":"USD",
"tax":"1.00",
"quantity":1
},
{
"name":"item 2",
"description":"item 2 description",
"price":"1.00",
"currency":"USD",
"tax":"1.00",
"quantity":1
}]
},
"related_resources":
[]
}],
"create_time":"2017-10-20T02:36:27Z",
"links":
[{
"href":"h.t.t.p.s.:././.a.p.i...s.andbox.paypal.com/v1/payments/payment/PAY-5VL741754E714161BLHUWCKY",
"rel":"self",
"method":"GET"
},
{
"href":"h.t.t.p.s.:././.w.w.w...s.andbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-3U757031AX945661J",
"rel":"approval_url",
"method":"REDIRECT"
},
{
"href":"h.t.t.p.s:././.a.p.i...s.a.ndbox.paypal.com/v1/payments/payment/PAY-5VL741754E714161BLHUWCKY/execute",
"rel":"execute",
"method":"POST"
}
]}
You can use the json_decode() function (function docs) to decode the JSON information into a multi-dimensional array.
The following script will echo out the ID as required (provided $response is the JSON-encoded response from the PayPal transaction):
$data = json_decode($response, true);
echo $data['id'];
I worked it out, and its the following.
$response1 = json_decode($response);
$payment_id = $response1->id;
$payment_id = print_r($payment_id, true);
print ("{
\"id\": \"$payment_id\"
}");
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)
I am trying to integrate eventbrite with infusionsoft. I used eventbrite webhook to get the order api_url once an order is placed on my event. Using that api_url and personal oauthtoken, i am able to get the details of the particular order by passing the token "api_url?token=xxxxx"
This is the json response of the webhook after the order is placed
{"config": {"action": "order.placed", "user_id": "xxxxx", "endpoint_url":"http://example.com", "webhook_id": "xxxx"}, "api_url": "https://www.eventbriteapi.com/v3/orders/xxxx/"}
I am passing the personal token to the order api_url "https://www.eventbriteapi.com/v3/orders/xxxx?token=xxxx"
The json response got from the above is
{
"resource_uri": "https://www.eventbriteapi.com/v3/orders/xxxx/",
"id": "xxxxx",
"changed": "2015-09-09T09:41:31Z",
"created": "2015-09-09T09:41:30Z",
"costs": {
"payment_fee": {
"currency": "GBP",
"display": "\u00a30.00",
"value": 0
},
"gross": {
"currency": "GBP",
"display": "\u00a30.00",
"value": 0
},
"eventbrite_fee": {
"currency": "GBP",
"display": "\u00a30.00",
"value": 0
},
"tax": {
"currency": "GBP",
"display": "\u00a30.00",
"value": 0
},
"base_price": {
"currency": "GBP",
"display": "\u00a30.00",
"value": 0
}
},
"name": "test67 test67",
"first_name": "test67",
"last_name": "test67",
"email": "test67#gmail.com",
"status": "placed",
"time_remaining": null,
"event_id": "xxxx"
}
Following is the code i am using to retrieve the json response
$url = $api_url.'?token=xxxx';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
The problem is it only gives the basic information of the event. It does not give the attendees information in response. Can you help me with an idea or example to retrieve the attendees list belonging to a specific order id?
And is it possible to get the attendees list only using the personal oauth token?