Created
March 18, 2016 13:32
-
-
Save andreeacretu/3d4ff32fe60ddb671cc6 to your computer and use it in GitHub Desktop.
Get subuser list PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $url = 'https://api.sendgrid.com/'; | |
| $user = 'SG_username'; | |
| $pass = 'SG_password'; | |
| $params = array( | |
| 'api_user' => $user, | |
| 'api_key' => $pass, | |
| 'task' => 'get', | |
| ); | |
| $request = $url.'apiv2/customer.profile.json'; | |
| // Generate curl request | |
| $session = curl_init($request); | |
| // Tell curl to use HTTP POST | |
| curl_setopt ($session, CURLOPT_POST, true); | |
| // Tell curl that this is the body of the POST | |
| curl_setopt ($session, CURLOPT_POSTFIELDS, $params); | |
| // Tell curl not to return headers, but do return the response | |
| curl_setopt($session, CURLOPT_HEADER, false); | |
| // Tell PHP not to use SSLv3 (instead opting for TLS) | |
| curl_setopt($session, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2); | |
| curl_setopt($session, CURLOPT_RETURNTRANSFER, true); | |
| // obtain response | |
| $response = curl_exec($session); | |
| curl_close($session); | |
| // print everything out | |
| $decodedResp = json_decode($response); | |
| $fp = fopen('subusers.txt', 'w'); | |
| $subuserArray = array(); | |
| foreach ($decodedResp as $singleSubuser) | |
| { | |
| array_push($subuserArray, $singleSubuser->username); | |
| } | |
| foreach( $subuserArray as $subuser){ | |
| fputcsv($fp, explode(',', $subuser)); | |
| } | |
| fclose($fp); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment