Need help with inserting records from json array - SEMRUSH api response

Hi Guys
I'm trying to get a an api response from semrush to insert into a mysql database when the record is called.
For some reason I cannot figure out what it is not inserting.
The output from semrush api is this.
   Array
(
    [0] => Array
        (
            [domain] => digitalmarketer.com
            [rank] => 70337
            [organic_keywords] => 36220
            [organic_traffic] => 23685
            [organic_cost] => 161371
            [adwords_keywords] => 613
            [adwords_traffic] => 713
            [adwords_cost] => 5735
        )

)

Could you look at the insert script and see what I have done wrong
Thanks
matthewdacruzAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
We are working on this via a Live session.

It appears the issue is the insert_domain_rank.php file is looking for json. However, the semrush_domain_rank.php file is not outputting json.

https://www.semrush.com/blog/what-in-the-world-is-api-and-how-do-i-use-it/

Current
 <?php
//get array
 include_once( 'SemRush.php' );
 $s = new SemRush( 'http://digitalmarketer.com' );
 print_r( $s->callReport( "domain_rank", array( "export_columns" => "Dn,Rk,Or,Ot,Oc,Ad,At,Ac" ) ) );
 ?>

Open in new window



Test output
 <?php
/*
********************************************* 

    EXAMPLE OUTPUT
    Database;Domain;Rank;Organic Keywords;Organic Traffic;Organic Cost;Adwords Keywords;Adwords Traffic;Adwords Cost us;seobook.com;25689;3040;38517;254377;0;0;0

********************************************* 
*/

/*
Database;Domain;Rank;Organic Keywords;Organic Traffic;Organic Cost;Adwords Keywords;Adwords Traffic;Adwords Cost us;seobook.com;25689;3040;38517;254377;0;0;0
//get array
 include_once( 'SemRush.php' );
 $s = new SemRush( 'http://digitalmarketer.com' );
 print_r( $s->callReport( "domain_rank", array( "export_columns" => "Dn,Rk,Or,Ot,Oc,Ad,At,Ac" ) ) );
 
 */
$test_output = 'Database;Domain;Rank;Organic Keywords;Organic Traffic;Organic Cost;Adwords Keywords;Adwords Traffic;Adwords Cost us;seobook.com;25689;3040;38517;254377;0;0;0';

// convert to an array
$array = explode(";",$test_output);

// convert to json
$json = json_encode($array);

header('Content-Type: application/json');
echo $json;


 ?>

Open in new window


Final code should look something like this:
//get array
 include_once( 'SemRush.php' );
 $s = new SemRush( 'http://digitalmarketer.com' );
$array = explode(";", $s->callReport( "domain_rank", array( "export_columns" => "Dn,Rk,Or,Ot,Oc,Ad,At,Ac" ) ) );

// convert to json
$json = json_encode($array);

header('Content-Type: application/json');
echo $json;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
matthewdacruzAuthor Commented:
Thanks Scott
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.