How do I delete all cards that belong to my app? - google-mirror-api

I'm trying to simply delete a few cards that were created by my app. However, it appears as though the list() method cycles through every single card in the entire user's timeline.
My code below is slightly modified from the example in the documentation under the timeline list. When I attempted to use this, it accidentally looped through every card in my timeline using up my entire 1,000 / day quota in just a few seconds before the operation timed out.
def delete_previous_cards(self):
"""
This cleans up any cards that may have been leftover.
"""
result = []
request = self.mirror_service.timeline().list()
while request:
try:
timeline_items = request.execute()
result.extend(timeline_items.get('items', []))
request = self.mirror_service.timeline().list_next(request, timeline_items)
except errors.HttpError, error:
print 'An error occurred: %s' % error
break
for item in result:
item_id = item['id']
self.mirror_service.timeline().delete(id=item_id).execute()
What's the best way to efficiently delete the cards created by my app?

There's a JavaScript based tool that an Explorer wrote for just this purpose: Glass Cleaner.

It looks to me like the Python example is missing any concept of a pageToken, most of the other language examples have a nextPageToken and loop until the response does not have a nextPageToken. If you keep requesting the first page over and over even if you only have three cards you will quickly exhaust your API quota.
The rest of this answer is general information about list and delete and some curl commands you can safely experiment with that won't loop and exhaust your quota quite as quickly. Make special note of the nextPageToken property in the returned JSON from list commands ...
LIST and DELETE are weird and don't follow the documentation exactly in my experience.
Here is a sample CURL command for List.
curl -x http://localhost:5671 -H "Authorization: Bearer YOUR_TOKEN_HERE"
https://www.googleapis.com/mirror/v1/timeline
It returns 10 items for the user and app that are associated with the token.
It includes deleted items (isDeleted set to true) but does not show the isDeleted property in the output JSON. This is weird.
If you modify it slightly:
curl -x http://localhost:5671 -H "Authorization: Bearer YOUR_TOKEN_HERE"
https://www.googleapis.com/mirror/v1/timeline?isDeleted=true
(note the trailing parameter) now you get the same list but the output JSON includes the isDeleted property. The lesson for me here is you should probably be requesting isDeleted=false for looping delete requests.
To delete an item you can do this:
curl -x http://localhost:5671 -H "Authorization: Bearer YOUR_TOKEN_HERE"
-H "Content-Type: application/json" -v -X DELETE
https://www.googleapis.com/mirror/v1/timeline/ID_OF_A_TIMELINE_CARD
Note you have to use an actual id from a card you got from a list command at the end. Grab one from a list command above.
When you do a successful DELETE the response is a 204, which in a RESTful world can indicate delete success.
Then if you do a subsequent list as in the first example above the item will come right back and not be marked as deleted because the isDeleted property is missing.
Pages seem to be 10 in size, but I guess that could change, since I didn't find that documented anywhere.
nextPageToken values seem to frequently have identical beginnings and ends, and they are very long strings, so it can be confusing to look at them and you might inadvertently think they are identical when they are not, lesson here is to compare very carefully in the middle.
Maybe those curl commands help you experiment when your API quota comes back, and I would experiment with testing for a null or empty string nextPageToken to tell you when to exit your loop. The equivalent java code is:
} while (request.getPageToken() != null && request.getPageToken().length() > 0);
Good luck, and great question.

Related

Gatling - how to run gatling tests to load test same rest URI request with different query param and the corresponding request payload

I do have a test scenario to load test the API request with a different employee id (query param) and the corresponding payload, i do have all URIs handy to test, and Each POST request should execute only once.
so i assume, scn.inject(atOnceUser(1)) should be just 1 in my case, as user is a just single execution of a scenario from start to finish. Can someone confirm if my understanding is right. here i want all three POST requests to execute only once simultaneously.
I am planning to use scala3 to test the same. (like 100's of POST request simultaneously, with a different employee id each time, and submit POST request only once for each employee id)
POST: http://localhost:8080/orders/00000/product/item?employeeId=1234
payload A
POST: http://localhost:8080/orders/00000/product/item?employeeId=5678
payload B
POST: http://localhost:8080/orders/00000/product/item?employeeId=8352
payload C
and once the first round of testing is done, now i would like to execute the same POST request URIs (100s of POST URI's like above) with the different payload in round 2. In Round 2, the URI is still going to be the same with the same query param (employee id), but payload will be different from what i use for the previous round 1.
and again, i would like to run all below requests only once and run each request simultaneously. ((like 100's of POST request simultaneously)
POST: http://localhost:8080/orders/00000/product/item?employeeId=1234
payload D
POST: http://localhost:8080/orders/00000/product/item?employeeId=5678
payload E
POST: http://localhost:8080/orders/00000/product/item?employeeId=8352
payload F
and continue the same process as above for Round 3 and Round 4, with the same URI but with different payload, again execute all POST requests simultaneously, but execute each request only once.
Can you please help me with the approach to get this working?
Can you please advise how i should plan to store all these 100+ payload in the feeder file for each round, should i be having a single feeder file with 100+ post request body and Can you please advise if i should be storing all 100+ URIs with the query param in the feeder file as well? Note: for each round , the payload will be different
ffor eg: Round 1- 100+ POST URIs --> and corresponding 100+ request body
Round 2 - same 100+ POST URIs as Round 1 --> but this time different 100+ request body (corresponding payload for each URI)
Round 3 - same 100+ POST URIs as Round 1 --> but this time again different 100+ request body (corresponding payload for each URI)
Each URI has its own request payload for each round.

Array with 1 million number

We use Wizdler to get data. But we have to get data about 1 million person.
There is an alternative to search for only one or multiple.
We always writing ID here, one by one.
Our questions is, is there anyway to input 1 million number into here in one time?
We have also a list over all ID numbers too. Is that possible to input link to our files that has all numbers or we must write all number like that?
<int xmlns="http://schemas.microsoft.com/Arrays">123456</int>
<int xmlns="http://schemas.microsoft.com/Arrays">654321</int>
I have all Combination saved as text file. Looking like that.
0000000
0000001
0000002
0000003
etc...
It's not possible to use a link to your file in that SOAP request. The SOAP request has to contain all the identifiers you want to retrieve. Also, one million of rows will be presumably too much for that web service and you will need to split them to multiple chunks.
To create a SOAP request with all the numbers, you can use a command to generate all the int elements. Then you can just use any text editor to wrap it into a SOAP envelope. This will give you the request you can send to the web service.
In Linux environment, the command to generate the lines will look like this (identifiers.txt is the name of your file with all the identifiers, a is the namespace alias for http://schemas.microsoft.com/Arrays that has to be defined beforehand):
awk '$0="<a:int>"$0"</a:int>"' identifiers.txt
The result will look like this:
<a:int>0000000</a:int>
<a:int>0000001</a:int>
<a:int>0000002</a:int>
<a:int>0000003</a:int>
You can also generate the whole request, not only the repetitive part of it. The following example assumes that operation name is yourRequest and it is in the namespace yourNamespace. The int elements are also not wrapped in any other element. You have to alter this to match your scenario:
awk 'BEGIN{print "<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\">\n\t<Body>\n\t\t<yourRequest xmlns=\"yourNamespace\" xmlns:a=\"http://schemas.microsoft.com/Arrays\">"}{print "\t\t\t<a:int>"$0"</a:int>"}END{print "\t\t</yourRequest>\n\t</Body>\n</Envelope>"}' identifiers.txt > request.xml
After executing the previous command, the request.xml will have the following content:
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
<yourRequest xmlns="yourNamespace" xmlns:a="http://schemas.microsoft.com/Arrays">
<a:int>0000000</a:int>
<a:int>0000001</a:int>
<a:int>0000002</a:int>
<a:int>0000003</a:int>
</yourRequest>
</Body>
</Envelope>
For the SOAP envelope, I have used the namespace for SOAP 1.1 (http://schemas.xmlsoap.org/soap/envelope/). If your service understands SOAP 1.2 only, change the namespace accordingly (http://www.w3.org/2003/05/soap-envelope).
To call the web service, you can use curl:
curl -d "#request.xml" "http://url/to/your/web/service" -H "Content-Type: text/xml"
Add SOAPAction HTTP header if your web service requires it. Also change the content type from text/xml for SOAP 1.1 to application/soap+xml for SOAP 1.2.
With all that being said, the final request with million numbers will have approximately 18 MB at least. Such huge request will most likely fail because of a maximum POST size limit or a timeout. To work around this, split the request into smaller requests.

Quickbook No apptoken detected; (PHP)errorCode=003102; statusCode=401

I am new in quickbooks API implementation, I am always getting one error No apptoken detected; errorCode=003102; statusCode=401 when I am doing API call for customer add etc.
I am giving my steps, please look over that.
My sandbox info like that
Consumer Key: qyprdffbBBInX4a82jG73Mreyy96tC
Consumer Secret: IgpJzJrYvb9FmmdB7A0ECDGHG62Cp7dqVWjfMTvU
Access Token: qyprdlo3WrK0KhGZMTeA857AuKiVy2eaAmpXsRvG3jycYaMQ
Access Token Secret: TdPGpcUI8AiAdWFiCyb8jAAygH16bzU7VRGaspx4
I am Using PHP.
First I have generated oauth_signature.
$URL =
rawurlencode('https://sandbox-quickbooks.api.intuit.com/v3/company/408554291/customer');
$method = 'POST'; $parameter =
rawurlencode('oauth_consumer_key=qyprdffbBBInX4a82jG73Mreyy96tC&oauth_nonce=BlyqIBbv3R4T0P4qglAv1RjoYisMZk1449659733&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1449659733&oauth_token=qyprdlo3WrK0KhGZMTeA857AuKiVy2eaAmpXsRvG3jycYaMQ&oauth_version=1.0');
$ukey =
rawurlencode('IgpJzJrYvb9FmmdB7A0ECDGHG62Cp7dqVWjfMTvU').'&'.rawurlencode('TdPGpcUI8AiAdWFiCyb8jAAygH16bzU7VRGaspx4');
$hasmac = hash_hmac("sha1", $BaseURL,$ukey,1);
and My oauth_signature is jZ8JhECy/e0kpPbUdZp/o/EUC7U=
When i call API with this oauth_signature, i am getting Error 'No apptoken detected; errorCode=003102; statusCode=401'
My CURL call like this
curl -X POST -H 'Content-Type: application/json, Authorization: OAuth
oauth_token=qyprdlo3WrK0KhGZMTeA857AuKiVy2eaAmpXsRvG3jycYaMQ,oauth_consumer_key=qyprdffbBBInX4a82jG73Mreyy96tC,oauth_signature_method=HMAC-SHA1,oauth_timestamp=1449659733,oauth_version=1.0,oauth_nonce=BlyqIBbv3R4T0P4qglAv1RjoYisMZk1449659733,oauth_signature=jZ8JhECy/e0kpPbUdZp/o/EUC7U='
-d '{"data": [{"BillAddr":{"Line1":"86 A Topsia","City":"Kolkata","Country":"India","CountrySubDivisionCode":"WB","PostalCode":"700102"},"Title":"Mr.","GivenName":"ApurbaK","MiddleName":"Kumar","FamilyName":"ApurbaK","PrimaryPhone":{"FreeFormNumber":"564545465"},"PrimaryEmailAddr":{"Address":"apurbahazra12#navsoft.in"}}]}'
'https://sandbox-quickbooks.api.intuit.com/v3/company/408554291/customer'
Please look over that.
Thanks,
Apurba
Firstly, you don't want to be doing this yourself -- use a library. OAuth is complex, and implementing it yourself is going to be a hairy process, rife with errors.
Go grab a library:
https://github.com/consolibyte/quickbooks-php
Follow the quick-start guide linked there, and benefit from the examples:
https://github.com/consolibyte/quickbooks-php/tree/master/docs/partner_platform/example_app_ipp_v3
With that said, if you do decide to write it yourself, make sure you follow the OAuth spec:
https://www.rfc-editor.org/rfc/rfc5849
So far, the issues I immediately see with your implementation are:
You can't hard-code the timestamp like this: &oauth_timestamp=1449659733 The timestamp should be ever-changing, and set to the currenty timestamp.
You can't hard-code a nonce like this: &oauth_nonce=BlyqIBbv3R4T0P4qglAv1RjoYisMZk1449659733 The nonce has to change with every single request so this is going to fail after your first request.
You haven't normalized your request parameters / sorted them, per the spec.
This is the incorrect way to specify multiple headers with cURL: -H 'Content-Type: application/json, Authorization: OAuth .... Please see the cURL docs: http://curl.haxx.se/docs/manpage.html#-H
In the code you posted, you haven't actually set $BaseURL anywhere, so right now you're signing an empty string (unless you forgot to paste some code somewhere?)
What is $ukey set to? It doesn't appear to be defined in your code anywhere (did you forget to paste some code in?)

Consuming response headers in Apache Output filter

I am writing an apache module output filter that needs to consume a couple of internal-only response headers. These response headers are set by a perl based application running in the backend. The APR function I am using in my output filter is:
apr_table_get(r->headers_out, "x-my-response-header");
However, what seems to happen is that in my output filter I do not see the above response header set, up until the third or fourth bucket brigade - which is unfortunately already too late - I actually need to use the value of x-my-response-header to compute a new response header and set that in the response to the browser.
I insert my output filter this way:
ap_hook_insert_filter(insertOutputFilterHook, NULL, NULL, APR_HOOK_FIRST);
ap_register_output_filter(myFiltersName, myOutputFilter, NULL, AP_FTYPE_CONTENT_SET);
What I have verified:
The internal-only headers do appear on the HTTP response on my browser (haven't unset them yet)
The first two bucket brigade's buckets contain html page text
Questions:
What could be the reasons for why the internal-only response header not be set/visible in the first call to my output filter / first bucket brigade?
Is it possible to instead accumulate the first few bucket brigades and then start flushing them out once the internal only response header's value known?

API : Ticker info

The Coinbase Exchange API: ticker GET /products/<product-id>/ticker only provides the last close. In order to place a market order, I need the best ask and bid (based on the side) price. Almost all exchanges provide this with their ticker API, so I am little surprised coinbase doesn't.
What am I missing? Is there any way I can get that information.
You can use the Order Book endpoint: GET /products/<product-id>/book to get that information. Further details are available here.
Doing it with rest template, java. The end point to hit is:
$ while true ; do curl http://api.pro.coinbase.com/products/BTC-USD/ticker ; echo ; done
Make sure, you use https. http will return nothing
while true ; do curl http://api.pro.coinbase.com/products/BTC-USD/ticker ; echo ; done

Resources