PHP code example of cloudwelder / petitions-api

1. Go to this page and download the library: Download cloudwelder/petitions-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cloudwelder / petitions-api example snippets




use CloudWelder/PetitionsApi/PetitionsApi;

$api = new PetitionsApi('client_id', 'client_secret', 'reidrect_uri');

$redirectUrl = $api->generateRedirectUrl();

echo "<a href='$redirectUrl'>Click here to login</a>";

$token = $api->generateTokenFromCode($_GET['code']);
$accessToken = $token->getAccessToken();

use CloudWelder/PetitionsApi/PetitionsApi;

$api = new PetitionsApi();

//Get the details of the active user.
$response = $api->withToken($accessToken)->get('users/me');
$userDetails = $response->getResponseData();

//Create a new petition.
$petitionData = [
  'title' =>  'My petition',
  'description' => 'This is a sample petition'
];
$response = $api->withToken($accessToken)->post('petitions', $petitionData);
$createdPetition = $response->getResponseData();

//Edit an existing petition
$petitionData = [
  'title' =>  'My new petition'
];
$response = $api->withToken($accessToken)->put('petitions/2', $petitionData);
$changedPetition = $response->getResponseData();

//Delete a petition
$response = $api->withToken($accessToken)->delete('petitions/2', $petitionData);