How can I set a deposit tag for XRP transactions using the Coinbase API? - coinbase-api

I am playing with the Coinbase API and am attempting to send XRP from my Coinbase wallet to another account (outside of Coinbase). The Coinbase send API (https://developers.coinbase.com/api/v2#send-money) allows me to set the destination address but there is no means of setting the destination tag, which is required for XRP transfers.
How can I set the destination tag?

The Coinbase Pro API has documentation for their platform that hints at a possible solution (https://docs.pro.coinbase.com/?r=1#crypto). Two parameters of interest are destination_tag and no_destination_tag. So if you want to send XRP using Python, you might say the following:
client.send_money(account_id = <account-id>,
to = <destination-address>,
amount = <amount>,
currency = 'XRP',
destination_tag = <destination-tag>,
no_destination_tag = False)
If you don't want to use the destination tag, you can just omit the destination_tag parameter and set no_destination_tag to True.

Extremely late to this but figured it'll be useful for someone else stumbling onto this thread.
I've just tested putting deposit_tag into the POST request to Coinbase's API (not Coinbase Pro) and it successfully puts the deposit tag through.
Coinbase also doesn't allow you to send XRP if you don't specify a deposit tag, which is handy.

Related

Can I send an alert when a message is published to a pubsub topic?

We are using pubsub & a cloud function to process a stream of incoming data. I am setting up a dead letter topic to handle cases where a message cannot be processed, as described at Cloud Pub/Sub > Guides > Handling message failures.
I've configured a subscription on the dead-letter topic to retain messages for 7 days, we're doing this using terraform:
resource "google_pubsub_subscription" "dead_letter_monitoring" {
project = var.project_id
name = "var.dead_letter_sub_name
topic = google_pubsub_topic.dead_letter.name
expiration_policy { ttl = "" }
message_retention_duration = "604800s" # 7 days
retain_acked_messages = true
ack_deadline_seconds = 600
}
We've tested our cloud function robustly and consequently our expectation is that messages will appear on this dead-letter topic very very rarely, perhaps never. Nevertheless we're putting it in place just to make sure that we catch any anomalies.
Given the rarity of which we expect messages to appear on the dead-letter-topic we need to set up an alert to send an email when such a message appears. Is it possible to do this? I've taken a look through the alerts one can create at https://console.cloud.google.com/monitoring/alerting/policies/create however I didn't see anything that could accomplish this.
I know that I could write a cloud function to consume a message from the subscription and act upon it accordingly however I'd rather not have to do that, a monitoring alert feels like a much more elegant way of achieving this.
is this possible?
Yes, you can use Cloud Monitoring for that. Create a new policy and perform that configuration
Select PubSub Topic and Published message. Observe the value every minute and count them (aligner in the advanced option). Now, in the config, when it's above 0 from the most recent value, the alert is raised.
To filter on only your topic you can add a filter by topic_id on your topic name.
Then, configure your alert to send an email. It should work!

Where to store a Authorization Bearer Token in Salesforce?

We have an external vendor that requires us to include a bearer token in the http request header when we communicate with the API. This token shouldn't be left in the code unencrypted so where is the best place to store it? The Named Credential type doesn't seem to support storing a simple token and the Custom Setting option seems overly complicated and unnecessary. This is a single token string that will be used for every API call regardless of which user. I have searched high and low on google and haven't found an obvious solution that works.
There are some options but they're limited for your code as end user. A determined developer/sysadmin will learn the value eventually.
If you'd build a managed package you could use a protected custom setting (managed package's code could see it but not the client code, even sysadmins)
Check some of these:
https://developer.salesforce.com/page/Secure_Coding_Storing_Secrets
https://salesforce.stackexchange.com/questions/226110/what-is-the-best-way-of-storing-username-and-password-in-salesforce
https://salesforce.stackexchange.com/questions/478/using-transient-keyword-to-store-password-in-hierarchy-custom-setting
https://salesforce.stackexchange.com/questions/55008/is-encrypting-passwords-in-protected-custom-settings-a-security-requirement
You could make a custom setting with 2 text fields, 1 with encryption key and 1 with encrypted value in it. Look at Crypto class.
Blob exampleIv = Blob.valueOf('Example of IV123');
Blob key = Crypto.generateAesKey(128);
Blob data = Blob.valueOf('Data to be encrypted');
Blob encrypted = Crypto.encrypt('AES128', key, exampleIv, data);
Blob decrypted = Crypto.decrypt('AES128', key, exampleIv, encrypted);
String decryptedString = decrypted.toString();
System.assertEquals('Data to be encrypted', decryptedString);
Your initialisation vector could be org's id or something else that's easy to access and unlikely to change (I don't know if your vendor's API has test and prod endpoints but it's an added bonus that after sandbox refresh this will fail to decrypt OK until you change the custom setting... you wouldn't want to send test messages to production API), you'd generate key once & store it in setting.

Sending to another user with e-mail address

I am trying to create a script in Python to transfer funds to another Coinbase user when all I have is an e-mail address. I have been unsuccessful so far. How do I get another user's "id" when all I have is their e-mail address?
As a follow on, can I add a memo/note to the transfer? If so, how?
Finally figured it out with a little bit more searching and trial and error. For anyone else who may have this question:
First get the account ID for the currency you want to send.
account_list = client.get_accounts()['data']
ETH_id = [acc['id'] for acc in account_list if acc['balance']['currency'] == "ETH"][0]
Then use the send_money function (not transfer_money) to send to an e-mail address.
client.send_money(ETH_id,to="<e-mail address>", amount="0.0005", currency="ETH", description = "Hey look, it worked.")
The description keyword is for the memo.

How to get seller name from Seller Id using Amazon MWS API

I got the PriceChangedNotification by http://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_NotificationType.html.
It returns Seller ID of new offer per ASIN.
I need to get the Seller's name by Seller ID.
How can I do that?
What we did is took a list of the sellerID's and did a scrape using a URL like this: https://www.amazon.com/sp?seller=xxxxxxxxxxx for each seller id. Then pull the seller name out of the resulting html (look for id=sellerName) and stored that in a table. Then when I get a PriceChangedNotification, I join to my sellers table to produce my reports, or whatever else I may need.
Keepa has a nice API that can get this for you and lots of other things that MWS won't. It's not free, but it might be worth it if you have a bunch of things you want to get from Amazon and don't want to scrape everything yourself. Unfortunately, it seems MWS keeps becoming more restrictive.
https://keepa.com/#!discuss/t/request-seller-information/790?u=keepa
The rabbit hole brought me here. Considering I spent an hour googling and testing, here it is so the next one may save some time.
import requests
import urllib.request
import time
from bs4 import BeautifulSoup
seller_id = ""
s = requests.Session()
url = f"https://www.amazon.co.uk/sp?seller={seller_id}"
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0',
"Cookie":'i18n-prefs=GBP;' # won't work without this cookie
}
r = s.get(url, headers=headers)
# >> print(r) --> response 200
soup = BeautifulSoup(r.text, "html.parser")
soup.find("h1", {"id": "sellerName"}).text
important things to note: Amazon blocks scrapers, you'll need to simulate a http request. Use postman to ping the particular URL you are interested in and look at what headers it sends, in particular what cookies it sends. In this case my request wouldn't work without the i18n-prefs cookie.

Getting a users mailbox current history Id

I'd like to start syncing a users mailbox going forward so I need the most recent historyId of the users mailbox. There doesn't seem to be a way to get this with one API call.
The gmail.users.history.list endpoint contains a historyId which seems to be what I need, from the docs:
historyId unsigned long The ID of the mailbox's current history record.
However to get a valid response from this endpoint you must provide a startHistoryId as a parameter.
The only alternative I see is to make a request to list the users messages, get the most recent history id from that, then make a request to gmail.users.history.list providing that historyid to get the most recent one.
Other ideas?
Did you check out https://developers.google.com/gmail/api/guides/sync ?
Depending on what your use-case is, to avoid races between your current state and when you start to forward sync, you'll need to provide an appropriate historyId. If there were a "get current history ID" then anything between your previous state and when you got those results would be lost. If you don't have any particular existing state (e.g. only want to get updates and don't care about anything before that) then you can use any historyId returned (e.g. on a message or thread) as you mention.
Small example for C# users (mentioned in comments by #EricDeFriez).
Nuget package Google.Apis.Gmail.v1 must be installed. See also quickstart for .NET developers.
var service = new GmailService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
var req = service.Users.GetProfile("me");
req.Fields = "historyId";
var res = req.Execute();
Console.WriteLine("HistoryId: " + res.HistoryId);
This answer is related to the Java Gmail API Client Library using a service account.
I found that the gmail.users.getprofile() will not work as the object that it returns is of type Class Gmail.Users.GetProfile which does not have an interface to getting a historyId.
com.google.api.services.gmail.model.Profile actually has a getHistoryId() function, but calling service.users().getProfile() will return a Class Gmail.Users.GetProfileobject instead.
To get around this, I use the history.list() function which will always return the latest historyId as part of its response.
Gmail service = createGmailService(userId); //Authenticate
BigInteger startHistoryId = BigInteger.valueOf(historyId);
ListHistoryResponse response = service.users().history().list("me")
.setStartHistoryId(startHistoryId).setMaxResults(Long.valueOf(1)).execute();
I set the max number of results to be 1 to limit the unnecessary data that I get returned back and I will receive a payload that looks like:
{"history":[{"id":"XXX","messages":[{"id":"XXX","threadId":"XXX"}]}],"historyId":"123456","nextPageToken":"XXX"}
The historyId (123456) will be the current historyId of the user. You can grab that historyId using response.getHistoryId()
You can also see that the latest historyId is given in the response if you use the API tester for Users.history: list
https://developers.google.com/gmail/api/v1/reference/users/history/list

Resources