in reply to Re: Perl Database Entries
in thread Perl Database Entries

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

Replies are listed 'Best First'.
Re^3: Perl Database Entries
by huck (Prior) on Jul 15, 2017 at 00:52 UTC

    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);

        what did you assign to $api_results? Remember my line dropped the pipe into jg, what you showed us above is not json

      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