That’s correct—I’m referring to when you make a request to POST /1.1/ton/bucket/ta_partner.
That’s great as it helps us eliminate that as a possible issue.
What do you see when you make a GET request using the location header value? What you should see is one hashed entity per line, as follows.
$ twurl -H ton.twitter.com "/1.1/ton/data/ta_partner/2417045708/gsc5WiuqPaXRSUA.txt"
c2bcd645a4baf0db743103c72231b1424b7601664d8ce44cacc614549f822a41
17fbc61536f4a0169924772b3d7eb83691978d83e3c2480e669e3b29e8749961
...
e32f5b173a82318a67a3bd6a5932109dacdc43b4b97614c73f46abab86f80873
Because we expect one hashed value per line.
If, instead, the response contains newline characters, it’s not correct.
# indicates that the data was not sent correctly
c2bcd645a4baf0db743103c72231b1424b7601664d8ce44cacc614549f822a41\n17fbc61536f4a0169924772b3d7eb83691978d83e3c2480e669e3b29e8749961\n...\ne32f5b173a82318a67a3bd6a5932109dacdc43b4b97614c73f46abab86f80873\n
Uploading the audience list
Let’s say we’re just trying to send three hashed entities.
In the request
# incorrectly sends data
$ twurl -X POST -H ton.twitter.com "/1.1/ton/bucket/ta_partner" --header "Content-Type: text/plain" --header "X-TON-Expires: Sat, 14 Jan 2017 06:01:00 GMT" -d "c2bcd645a4baf0db743103c72231b1424b7601664d8ce44cacc614549f822a41\n17fbc61536f4a0169924772b3d7eb83691978d83e3c2480e669e3b29e8749961\ne32f5b173a82318a67a3bd6a5932109dacdc43b4b97614c73f46abab86f80873\n"
This request mirrors the one in the Python example, above. The file data that we’re sending in that example includes the newline characters.
However, while this is a perfectly reasonable way to construct the request at the command line, the data will not be sent correctly (when using bash). The reason is that, “A Posix standard shell does not interpret C escapes.”
$ echo "hello\nworld"
hello\nworld
See this Stack Overflow post for more details.
As the linked post explains, there is a way to have bash recognize the newline characters: using the $'...' quotation form.
# correctly sends data
twurl -X POST -H ton.twitter.com "/1.1/ton/bucket/ta_partner" --header "Content-Type: text/plain" --header "X-TON-Expires: Sat, 14 Jan 2017 06:01:00 GMT" -d $'c2bcd645a4baf0db743103c72231b1424b7601664d8ce44cacc614549f822a41\n17fbc61536f4a0169924772b3d7eb83691978d83e3c2480e669e3b29e8749961\ne32f5b173a82318a67a3bd6a5932109dacdc43b4b97614c73f46abab86f80873\n'
From a file
We can do better and directly send the data from a file.
# file contents
$ cat hashed_user_ids.txt
c2bcd645a4baf0db743103c72231b1424b7601664d8ce44cacc614549f822a41
17fbc61536f4a0169924772b3d7eb83691978d83e3c2480e669e3b29e8749961
...
e32f5b173a82318a67a3bd6a5932109dacdc43b4b97614c73f46abab86f80873
(Note: no actual ellipses, just one hashed user ID per line.)
We’ll use a subshell to get the file contents: "$(<hashed_user_ids.txt)".
$ twurl -t -X POST -H ton.twitter.com "/1.1/ton/bucket/ta_partner" --header "Content-Type: text/plain" --header "X-TON-Expires: Sat, 14 Jan 2017 06:01:00 GMT" -d "$(<hashed_user_ids.txt)"
opening connection to ton.twitter.com:443...
opened
starting SSL for ton.twitter.com:443...
SSL established
<- "POST /1.1/ton/bucket/ta_partner HTTP/1.1\r\nContent-Type: text/plain\r\nX-Ton-Expires: Sat, 14 Jan 2017 06:01:00 GMT\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nAccept: */*\r\nUser-Agent: OAuth gem v0.5.1\r\nAuthorization: OAuth oauth_body_hash=\"Zu1XQVum1avNt7OuWd%2F3U7qDfkI%3D\", oauth_consumer_key=\"...\", oauth_nonce=\"ZXLIrFsPX89nSY8IWTSry3IKOmegeZkhnDyHAN7Ss\", oauth_signature=\"s6IK0HKKDPfUh3jABYfYZhicD6g%3D\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"1483863050\", oauth_token=\"...\", oauth_version=\"1.0\"\r\nConnection: close\r\nHost: ton.twitter.com\r\nContent-Length: 6499\r\n\r\n"
<- "c2bcd645a4baf0db743103c72231b1424b7601664d8ce44cacc614549f822a41\n17fbc61536f4a0169924772b3d7eb83691978d83e3c2480e669e3b29e8749961\ne32f5b173a82318a67a3bd6a5932109dacdc43b4b97614c73f46abab86f80873"
-> "HTTP/1.1 201 Created\r\n"
-> "connection: close\r\n"
-> "content-length: 0\r\n"
-> "content-type: text/plain\r\n"
-> "date: Sun, 08 Jan 2017 08:10:50 GMT\r\n"
-> "location: /1.1/ton/data/ta_partner/2417045708/gsc5WiuqPaXRSUA.txt\r\n"
-> "server: tsa_b\r\n"
-> "set-cookie: guest_id=v1%3A148386305067403704; Domain=.twitter.com; Path=/; Expires=Tue, 08-Jan-2019 08:10:50 UTC\r\n"
-> "strict-transport-security: max-age=631138519\r\n"
-> "x-connection-hash: e0724f963fa2564e3964b3f8ab00b530\r\n"
-> "x-content-type-options: nosniff\r\n"
-> "x-rate-limit-limit: 90000\r\n"
-> "x-rate-limit-remaining: 89999\r\n"
-> "x-rate-limit-reset: 1483863950\r\n"
-> "x-response-time: 30\r\n"
-> "x-tsa-request-body-time: 72\r\n"
-> "\r\n"
reading 0 bytes...
-> ""
read 0 bytes
Conn close
You’ll then use /1.1/ton/data/ta_partner/2417045708/gsc5WiuqPaXRSUA.txt as the input_file_path value in the subsequent request to the POST accounts/:account_id/tailored_audience_changes endpoint.