Making your first API call
Making API calls is a three step process:
- Create an API client
- Authenticate
- Make your API calls
Create an API client
Before you can do anything you must create an API client using your Podio API key. Head over to Podio to generate a client_id and client_secret before continuing.
Podio-php exposes a bunch of static methods on its classes. You’ll be using more of these later, but for now you just need to use the main PodioClient
class. You only have to create it once before making any API calls. Call it with the client_id and client_secret from your [API key]((https://podio.com/settings/api).
Now you’re ready to authenticate.
Authentication
Podio supports multiple forms of authentication depending on what you want to do. Use the server-side flow for web apps where you need Podio users to access your app, app authentication when you just need access to a single app without user interaction and use password authentication for testing or if you have no other way out. Read more about authentication in general at the Podio developer site.
Server-side flow
The server-side flow requires you to redirect your users to a page on podio.com to authenticate. After they authenticate on podio.com they will be redirected back to your site. Read about the flow on the developer site.
The example below handles three cases:
- The user has not authenticated and has not been redirected back to our page after authenticating.
- The user has already authenticated and they have a session stored using the session manager.
- The user is being redirected back to our page after authenticating.
See Scopes & Permissions for details about the scope parameter to PodioClient::authorize_url
App authentication
App authentication doesn’t require any direct user authentication and is thus much simpler. You can simply pass the app id and app token directly to the authentication function:
Password authentication
Password authentication works the same way as app authentication, but you have full access to any data the user has access to. As it’s bad practice to store your Podio password like this you should only use password-based authentication for testing or if you cannot use any of the other options.
Refreshing access tokens
Under the hood you receive two tokens upon authenticating. An access token is used to make API calls and a refresh token is used to get a new access/refresh token pair once the access token expires.
You should avoid authenticating every time your script runs. It’s highly inefficient and you risk running into rate limits quickly. Instead use a session manager to store access/refresh tokens between script runs to re-use your tokens.
Podio-php will automatically refresh tokens for you, but it’s your responsibility to store the updated tokens after you’re done making API calls. Otherwise you may be left with expired tokens. Use a session manager to automate this process.
Managing multiple authentications
You can end up in a situation where you need to switch between multiple authentications. This usually happens if you are using app authentication and need to switch between multiple apps.
To switch from one authentication to another simply create another API client: