PHPackages                             cloudwelder/petitions-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. cloudwelder/petitions-api

ActiveLibrary[API Development](/categories/api)

cloudwelder/petitions-api
=========================

This package provides a wrapper for Petitions.io REST Api

0.4(9y ago)037MITPHPPHP &gt;=5.5

Since Apr 13Pushed 8y ago6 watchersCompare

[ Source](https://github.com/CloudWelder/Petitions.io-PHP-Wrapper)[ Packagist](https://packagist.org/packages/cloudwelder/petitions-api)[ RSS](/packages/cloudwelder-petitions-api/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (10)Dependencies (2)Versions (13)Used By (0)

Petitions.io API PHP Wrapper
============================

[](#petitionsio-api-php-wrapper)

This is PHP wrapper to Petitions.io API

Contents
--------

[](#contents)

- [Installation](#installation)
- [Pre-requisites](#pre-requisites)
- [Usage](#usage)
    - [Initializing the API](#initializing-the-api)
        - [Method 1: Using Credentials](#methods-1-using-api-credentials)
        - [Method 2: Using Personal Access Token](#method-2-using-personal-access-token)
    - [Generating Login URL](#generating-login-url)
    - [Acquring Access Token](#acquiring-access-token)
    - [Making API Calls](#making-api-calls)

Installation
------------

[](#installation)

Installation is done using composer. Run the following command to include this package into your project
`composer require cloudwelder/petitions-api`

Pre-requisites
--------------

[](#pre-requisites)

In order to use this package, you must have an active App at petitions.io. If you dont already have one, register for one at petitions.io After the registration, note down your `client_id`, `client_secret` and `redirect_uri`OR you could get a `personal access token` directly.

Usage
-----

[](#usage)

Make sure you have the following line in your code before using any of the API classes. Thi is **not** required if you are using a framework such as laravel.

```
require "vendor/autoload.php"
```

### Initializing the API.

[](#initializing-the-api)

To use any of the APi calls, you must first get an instance of the API and acquier an access token using any of the following methods.

### Methods 1: Using API credentials.

[](#methods-1-using-api-credentials)

```
use CloudWelder/PetitionsApi/PetitionsApi;

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

Substitute `client_id`, `client_secret`, `redirect_uri` with your own values.

### Generating Login URL

[](#generating-login-url)

To gain access rights from a user, you must first redirect him to petitions.io. You can use the `getRedirectUrl()` method to generate this url.

```
$redirectUrl = $api->generateRedirectUrl();
```

You can then use this url to reidrect the user or as the `href` of an html link.

```
echo "Click here to login";
```

### Acquiring Access Token

[](#acquiring-access-token)

Once the user has granted your app's access request, petitions.io will redirect the user to the url you have specified in `redirect_uri` settings in petitions.io. This is where you should acquire the access token using the autthorization code trnsmitted as part of the url.

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

Store this access\_token into data base or other persistant storage to use it later. Unless the user revokes the grant, this access token is valid for a long time (a year)

The `Token` object retuned will also contain a `refresh_token` in addition to `access_token`. You can retrive it using `getRfreshToken()` function. Rrefresh tokens can be used to regenerate the access token when they expire.

### Method 2: Using Personal Access Token.

[](#method-2-using-personal-access-token)

If you alreay have an active personal access token, you can initialize the API without any credentials

```
use CloudWelder/PetitionsApi/PetitionsApi;

$api = new PetitionsApi();
```

### Making API calls

[](#making-api-calls)

The API object provides four methods for making API calls. They all return an instance of `CloudWelder/PetitionsApi/Response`. The returned object contains HTTP response related information such as headers, statsu code and response content. Petitions.io always return response in JSON format. So you must parse the response body to actually use the data. However the ressponse opbjecthas a helper method `getResponseData()` whcich will return an associative array generated by parsing the response content.

Before making any API calls, remeber to set the access token using the `withToken()` method. This method is chainable so you can chain other methods to it.

The four API call methods are:

- **`get()` Used for making GET request to API end points.**Signature: `get($url, $data)`
    - `$url` The API end point
    - `$data` An associative array containing any data to be passed along with the call. Example:

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

- **`post()` Used for making POST requests to API end points.**
    Signature: `post($url, $data)`
    - `$url` The API end point
    - `$data` An associative array containing any data to be passed along with the call. Example:

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

- **`put()` Used for making PUT requests to API end points.**
    Signature: `put($url, $data)`
    - `$url` The API end point
    - `$data` An associative array containing any data to be passed along with the call. Example:

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

- **`delete()` Used for making DELETE requests to API end points.**
    Signature: `put($url)`
    - `$url` The API end point Example:

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

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~5 days

Total

10

Last Release

3315d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/cf0196f21e2f14bfcd2ce8ed98156d2601a2acfcbd77164520dae1a57987214e?d=identicon)[reneesh](/maintainers/reneesh)

---

Top Contributors

[![sr-verve-alwin](https://avatars.githubusercontent.com/u/7435416?v=4)](https://github.com/sr-verve-alwin "sr-verve-alwin (17 commits)")[![drafie](https://avatars.githubusercontent.com/u/808640?v=4)](https://github.com/drafie "drafie (1 commits)")

---

Tags

phpapipetitions

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/cloudwelder-petitions-api/health.svg)

```
[![Health](https://phpackages.com/badges/cloudwelder-petitions-api/health.svg)](https://phpackages.com/packages/cloudwelder-petitions-api)
```

###  Alternatives

[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.7k371.6k6](/packages/theodo-group-llphant)[hubspot/api-client

Hubspot API client

24015.5M18](/packages/hubspot-api-client)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3661.2M46](/packages/tencentcloud-tencentcloud-sdk-php)[resend/resend-php

Resend PHP library.

596.2M35](/packages/resend-resend-php)[checkout/checkout-sdk-php

Checkout.com SDK for PHP

563.5M11](/packages/checkout-checkout-sdk-php)[mozex/anthropic-laravel

Laravel integration for the Anthropic API: facade, config publishing, install command, testing fakes, messages, streaming, tool use, thinking, and batches.

72287.1k1](/packages/mozex-anthropic-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
