Mailchimp : Filtering data returned form a cURL request - json

I'm trying to make curl request to mailchimp in order to retrieve members informations. According to the doc, a special parameters name fields can be passed to the query in order to filter the result to the desired fields. See straight from the doc :
Query string parameters :
fields
Type: Array
Title: Fields
Read only: false
A comma-separated list of fields to return. Reference parameters of
sub-objects with dot notation.
The following data structure is returned on a sucessfull request :
{"members":[{"id":"106b60f0cdc8db34b7aae820d345ebd8","email_address":"blabla#freddiesjokes.com"
,"unique_email_id":"88e38b5109","email_type":"html","status":"subscribed",
"merge_fields":{"FNAME":"","LNAME":""} .... ]}
As you can see the email_address field is present. Therefore the following request always return an {} to me
curl --request GET \
--url 'https://us14.api.mailchimp.com/3.0/lists/744415ffa6/members?fields=email_adress' \
--user 'smth:apikey' \
--include
Is there something wrong with the request ? Without the fields parameters it correctly fetch the data. I see it's supposed to be an array, which, for me, means i could chain the fields parameters such as fields=blabla&fields=john&fields=doe do i stand correct on this ?
Thanks for you help

Look at: https://developer.mailchimp.com/documentation/mailchimp/guides/get-started-with-mailchimp-api-3/ which suggests you need to separate different fields with a comma and use the lists. prefix as in:
curl https://us14.api.mailchimp.com/3.0/lists?fields=lists.email_adress'

Related

REG_EXTRACT and REG_REPLACE in ICDI

I'm using Informatica Cloud - ICDI mapping to process JSON data.
I have a JSON file with content as below.
[{a:1,b:2,c:3,d:4},{a:10,b:20,c:30,d:40},{a:100,b:200,c:300,d:400}]
I have this full JSON data in a string port in expression transformation. Now I want to extract the value with key or just the value for a and c from this string. How to use the REG_EXTRACT function to get all matches as output? Or how to use REG_REPLACE to eliminate the rest of the characters to get the desired output.
Expected Output: Comma and colon in the output are optional.
a:1,c:3,a:10,c:30,a:100,c:300
Have a look at this sample: regex101.com
Where I used this regex (?<a>a:(?<av>[^,]+))[^c]+(?<c>c:(?<cv>[^,]+))
You get the group a which contains the hole a-part with value of the current block, the group av which contains just the value of this part and the same stuff for c and cv

JSON_EXTRACT not working for nested json data

I want to select the data from my table which is json data so to show my table data is like this :
user_id: 1
metaname: mymetaname
meta_value: a:1:{i:0;a:10:{s:7:"street1";s:36:"shiv plaza";s:4:"city";s:5:"surat";s:5:"state";s:7:"gujarat";s:7:"zipcode";s:6:"395010";s:14:"dollet_country";s:2:"IN";s:10:"tostreet1l";s:5:"surat";s:7:"tocityl";s:5:"surat";s:8:"tostatel";s:5:"surat";s:10:"tozipcodel";s:6:"395000";s:17:"todollet_countryl";s:2:"IN";}}
And i am trying to run this query :
SELECT user_id,JSON_EXTRACT(meta_value, '$."city"') FROM `usermetatable`
But it's showing error :
[Invalid JSON text in argument 1 to function json_extract: "Invalid
value." at position 0.]
My json data in table can not be changed to other and it's correct JSON for sure, Could anyone correct above query ?
That's not JSON data. It looks like a serialized PHP object. See http://php.net/serialize
There's no MySQL function for extracting a field from that serialized object. You should fetch the whole object into a PHP app, and call unserialize() on it, then access the object members.

How to escape JSON in the URL using postman?

The Json string I am trying to pass as a parameter using Postman is:
{"event":"hello","data":"Smith"}
so in Postman, the above Json string for the GET would be appended below:
http://localHost:8080/....../foo?jasonRequest?{"event":"hello","data":"Smith"}
I'm getting HTTP Status 500 - java.net.URISyntaxException: Illegal character in query at index.
I've tried escaping the double quotes, but still no luck.
Your request has 2 ?. A GET request should only have one, after which the parameters are defined.
In Potman, you can add parameters by clicking the Params button and introduce one parameter per row:
Postman will automatically add those parameters to the request.
I assumed that the endpoint is foo/jasonRequest.
Hope this helps.

Error "attribute parameter is not in hash ref" when using Perl DBI selectall_hashref

I'm trying to get my first select to work using selectall_hashref from the Perl DBI module. I've opened a connection to the database (MySQL) successfully. I'm getting an error when I execute the following:
$dbh->selectall_hashref('SELECT id FROM users WHERE login=?',undef,"myusername");
DBI::st=HASH(0x1505a60)->_prepare(...): attribute parameter 'myusername' is not a hash ref at /usr/lib/x86_64-linux-gnu/perl5/5.20/DBD/mysql.pm line 238.
My table should be able to support this query, it has an id column and login column for each user.
The examples I've found for selectall_hashref show the ? substitution parameter being passed as the third parameter. The DBI documentation says that the second and third arguments should be %attr and #bind_values but doesn't give much documentation about them or show working examples.
What is causing the error, and more importantly how do you actually use the %attr and #bind_values correctly?
If you want to store everything as an arrayref where each row is a hashref (which is what your comment seems to indicate), you can use the selectall_arrayref() method with the Slice attribute:
$dbh->selectall_arrayref('SELECT id FROM users WHERE login=?', {Slice => {}}, 'myusername');
It's a little weird, but here's how it works:
If $slice is a hash reference, fetchall_arrayref fetches each row as
a hash reference. If the $slice hash is empty then the keys in the
hashes have whatever name lettercase is returned by default. (See
"FetchHashKeyName" attribute.) If the $slice hash is not empty,
then it is used as a slice to select individual columns by name. The
values of the hash should be set to 1. The key names of the returned
hashes match the letter case of the names in the parameter hash,
regardless of the "FetchHashKeyName" attribute.
It's a good idea to set the FetchHashKeyName attribute on the database handle to make your hash key names consistent; I happen to like NAME_lc in my applications.
The methods expects key column as the second parameter and attributes ref is passed as third one. In the result it builds a hash with the specified column as a key. What you probably want, is selectall_arrayref:
$ dbh->selectall_arrayref('SELECT id FROM users WHERE login=?',undef,"myusername");

solr update with json causes 'error parsing json field. unexpected object_start'

I downloaded solr 4.6.1 and I am attempting to update the solr index using the following via command line:
curl http://localhost:8983/solr/update?commit=true -H 'Content-type:application/json' -d '
[{
"id" : "1",
"phoneNumber_ss": [{"foo_ss" : "bar"}]
}]
'
I am using the example schema.xml, which is why i used all the "_ss" fields.
The issue is that when I execute this I get the following response:
{"responseHeader":{"status":400,"QTime":1},"error":{"msg":"Error parsing JSON field value. Unexpected OBJECT_START","code":400}}
This seems to be related to the value specified for phoneNumber_ss field which is an array of objects. If I make the value into an array or an object it works fine, its only when it is an array of objects that the issue occurs.
Any help is much appreciated.
I don't think Solr support storing objects into a multivalued field. You can store it as a array of string. You might also store the object as a string and parse it in your application.
If you have such use case that you want to have all the objects from Solr only, you can follow the steps..
Create a multivalued field for your keys.
Maintain the same order of keys and create another multivalued field for values.
So, you can get the keys and values in same order in different fields. But in this approach you might face problems while updating those multivalued fields. You might want to look here
And finally, you are also missing some syntax in your update statement.
set – set or replace a particular value, or remove the value if null is specified as the new value
add – adds an additional value to a list
Check http://wiki.apache.org/solr/UpdateJSON