in reply to Perl Database Entries

I am not sure what is in $api_results, but it is defiantly not a DBI/DBD object that can be used to call a DBI/DBD method with. It has the TEXT output of the curl command thru a series of pipes.

and i am pretty sure that your final pipe in that command | \@csv is not doing anywhere near what you think it is, for it will resolve to something like | ARRAY(0xa3e43c) "jq" seems to be some sort of json post processor, maybe you just want to end with that and then parse its text output with split?

Replies are listed 'Best First'.
Re^2: Perl Database Entries
by cbtshare (Monk) on Jul 14, 2017 at 23:46 UTC

    yes jq is a json parse, the results I am trying to store in $api_results are

    105924,"sprinklr","Sprinklr",5562,"Sprinklr",false,false,"Farme@.socia +l","shared","2017-05-08T09:54:29.787-07:00","active",false,false 108459,"toll-brothers-spredfast","Toll Brothers - Spredfast",5561,"Sp +redfast",false,false,"toll@social","shared","2017-06-07T18:03:52.862- +07:00","active",false,false 1034,"twitter-sportchek","Twitter - SportChek",44,"Twitter - Shared",f +alse,false,"sportchek","shared","2017-06-09T23:22:15.571-07:00","acti +ve",false,false 109291,"rei-spredfast","REI - Spreast",5561,"Spredfast",false,false,"r +eitea@cial","shared","2017-06-19T12:33:33.561-07:00","active",false,f +alse

    So the api call works, I just need to put that info in a database

      If i were doing it, i'd skip curl and use LWP, then JSON

      As that may turn out to be too much for you you might want to skip jg. at least. Something like

      $api_results=`curl -H "Authorization: token 5FEFAQ1W4" https://www.b +om/api/v2/organizations/company/admin/groups/"$groid"/installations?p +age=1`; use JSON; my $json=new JSON; my $unjson=$json->allow_nonref->decode($api_results); $app_insert = $dbh->prepare("INSERT IGNORE INTO apps(id, app_slug, a +pp_Name, provider_id, provider_slug, provider_saml, config_saml, conf +ig_login, config_url, created_date, status, key_vault, mfa_code) VALU +ES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?") or die $dbh->errstr; for my $row (@$unjson) { my @insert; for my $var (qw/.id .slug .name .provider.id .provider.name .provider.capabilities.has_saml .configuration.sam +l .configuration.login .configuration.install_type .created .keyvault .requires_mfa_code /){ push @insert,$row->{$var}; } # var $app_insert->execute(@api) or die $app_insert->errstr; } # row

        $api_results contents are below 100442,"spredfast-tim-hortons","Spredfast - Tim Hortons",5561,"Spredfa +st",false,false,"timhortons@icuc.social","https://www.spredfast.com", +"2017-03-03T09:52:30.440-08:00","active",false,false,"shared"

        My new code is below

        use JSON; my $json=new JSON; my @unjson=$json->allow_nonref->decode($api_results); $app_insert = $dbh->prepare("INSERT INTO bitium_apps(id, app_slug, ap +p_Name, team_id, provider_id, provider_slug, provider_saml, config_saml, confi +g_login, config_url, created_date, status, key_vault, mfa_code, configuration_i +nstall) VALUES (?, ?, ?, \"$response\", ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?") o +r die $dbh->errst$ for my $row (@unjson) { my @insert; for my $var (qw/.id, .slug, .name, .provider.id, .provider.name, .provider.capabilities.has_saml, .configuration.sa +ml, .configuration.login, .configuration.url, .created +_at, .status, .key_vault, .requires_mfa_code, .configur +ation.install_type /){ push @insert,$row->{$var}; } # var $app_insert->execute(@insert[0,1,2,4 .. 15]) or die $app_insert->e +rrstr; } # row

        But I get the following error: garbage after JSON object, at character offset 7 (before ""spredfast-tim-horto...") at bitium.pl line 69. line 69 is my @unjson=$json->allow_nonref->decode($api_results);

        ok thank you, just from the reading of your code I presume the last line is meant to be (untested)
        $app_insert->execute(@insert) or die $app_insert->errstr; } # row
        I will try this solution as well