In order to use the Daisycon API you will need to have an active publisher account. Authentication with the Daisycon API is only possible with OAuth 2.1.
Daisycon API Authentication Guide (OAuth 2.1 with PKCE)
Authentication Overview
The Daisycon API only supports OAuth 2.1 with PKCE. Follow these steps:
- Set up a Developer Account
- Create an App & Retrieve Client Credentials
- Perform an Authorization Call & Token Exchange
- Start Using the API with Access Tokens
- Perform a Refresh Call
Step 1: Set Up a Developer Account
Before beginning, set up a developer account on the Daisycon platform. Note that you need an existing publisher or advertiser account to do so. For more details, see our Developer Account Setup guide.
Step 2: Create an App & Retrieve Client Credentials
After setting up a developer account, register your app in the Daisycon system to obtain a client ID and client secret. Be mindful of permissions, as your app should only have what it truly needs. For more details about how to create an app, see our Creating an App guide.
With or without client secret?
Every app uses PKCE. Whether you also send your client secret depends on where your code runs:
- Server-side app (your code runs on your own server, for example a PHP or Node.js integration): always include your client secret in the token exchange and refresh calls. This is the standard setup for most integrations.
- Client-side app (your code runs in the browser, for example a JavaScript app): never include your client secret, because anyone can read code that runs in a browser. Your app then authenticates with PKCE only.
Apps that connect without a client secret get fewer permissions. User management and account settings are not available to them, even when the app requests these permissions.
Step 3: Authorization Call & Token Exchange
1. Generate a Code Verifier
Use a random string of 43 to 128 characters (allowed characters: [A-Z, a-z, 0-9, "-", ".", "_", "~"]).
PHP Example:
function randomString($length) {
if ($length < 1) {
throw new InvalidArgumentException('Length must be a positive integer');
}
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~';
$out = '';
for ($i = 0; $i < $length; ++$i) {
$out .= $chars[random_int(0, strlen($chars) - 1)];
}
return $out;
}
$codeVerifier = randomString(43);JavaScript Example:
function generateRandomString(length) {
const allowedChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~';
const randomValues = crypto.getRandomValues(new Uint32Array(length));
let randomString = '';
for (let i = 0; i < length; i++) {
randomString += allowedChars.charAt(randomValues[i] % allowedChars.length);
}
return randomString;
}
const codeVerifier = generateRandomString(43);2. Create a Code Challenge
Hash the code verifier with SHA-256, then Base64 URL-encode it.
PHP Example:
function createCodeChallenge($codeVerifier): string {
return str_replace(
'=',
'',
strtr(base64_encode(hash('sha256', $codeVerifier, true)), '+/', '-_')
);
}
$codeChallenge = createCodeChallenge($codeVerifier);JavaScript Example:
async function generateCodeChallenge(codeVerifier) {
const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(codeVerifier));
return btoa(String.fromCharCode(...new Uint8Array(digest)))
.replace(/=/g, '')
.replace(/\+/g, '-')
.replace(/\//g, '_');
}
const codeChallenge = await generateCodeChallenge(codeVerifier);3. Redirect User to OAuth URL
Use the URL below, replacing placeholders with your app details. Be sure to URL encode all query parameter values, and ensure your redirect URI is registered to the app.
https://login.daisycon.com/oauth/authorize?response_type=code&client_id=APP_CLIENT_ID&redirect_uri=APP_REDIRECT_URI&code_challenge=GENERATED_CODE_CHALLENGEOptionally, you can add the state parameter with your own data, which will be returned to the callback redirect URL.
4. After a Successful Login
Upon successful login, the OAuth will redirect to your redirect URI with a code (and optionally, your state).
https://your-redirect.uri/and/path?code=OAUTH_CODE[&state=YOUR_STATE]5. Token Exchange
Use the received authorization code for token exchange. Include your client secret only if your app is a server-side app. If your app is a client-side app, do not include your client secret!
PHP Example (server-side, with client secret):
For Sandbox use "https://login.daisycon.com/oauth-sandbox/access-token"
function httpPost($url, $data) {
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
$response = httpPost('https://login.daisycon.com/oauth/access-token', [
'grant_type' => 'authorization_code',
'redirect_uri' => 'APP_REDIRECT_URI',
'client_id' => 'APP_CLIENT_ID',
'client_secret' => 'APP_CLIENT_SECRET',
'code' => 'RECEIVED_AUTH_CODE',
'code_verifier' => 'GENERATED_CODE_VERIFIER',
]);JavaScript Example (client-side, without client secret):
For Sandbox use "https://login.daisycon.com/oauth-sandbox/access-token"
const data = {
grant_type: 'authorization_code',
code: 'RECEIVED_AUTH_CODE',
client_id: 'APP_CLIENT_ID',
redirect_uri: 'APP_REDIRECT_URI',
code_verifier: 'GENERATED_CODE_VERIFIER'
};
fetch('https://login.daisycon.com/oauth/access-token', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
}).then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));Sample Response
{
"access_token": "string",
"refresh_token": "string"
}Step 4: Start Using the API
Now that you have an access token and a refresh token, you can start using the API by supplying the access token in the Authorization header.
Step 5: Refreshing the Token
After 30 minutes, your access token will expire. Use the refresh token to obtain a new access token and refresh token. A refresh token can only be used once, so be sure to store the new one! Refresh tokens are valid for 30 days.
Use the same setup as in the token exchange: include your client secret only if your app is a server-side app.
PHP Example (server-side, with client secret):
For Sandbox use "https://login.daisycon.com/oauth-sandbox/access-token"
function httpPost($url, $data) { ... }
$response = httpPost('https://login.daisycon.com/oauth/access-token', [
'grant_type' => 'refresh_token',
'redirect_uri' => 'APP_REDIRECT_URI',
'client_id' => 'APP_CLIENT_ID',
'client_secret' => 'APP_CLIENT_SECRET',
'refresh_token' => 'RECEIVED_REFRESH_TOKEN',
]);JavaScript Example (client-side, without client secret):
For Sandbox use "https://login.daisycon.com/oauth-sandbox/access-token"
const data = {
grant_type: 'refresh_token',
client_id: 'APP_CLIENT_ID',
refresh_token: 'RECEIVED_REFRESH_TOKEN'
};
fetch('https://login.daisycon.com/oauth/access-token', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
}).then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));Common Issues & Troubleshooting
- Token Permissions Error: Ensure app permissions align with user permissions. This issue typically occurs if the app requests permissions that the authenticating user does not have. To resolve this, check and adjust the app's permissions to match those of the user.
- Missing permissions without client secret: Apps that connect without a client secret cannot use user management and account settings. If your app runs on a server and needs these permissions, include your client secret.
- Client Authentication Failed: This error could be due to various reasons, such as an incorrect client ID, client secret, redirect URI, or code verifier. Verify that all values are correct and match exactly with what was registered, including any trailing slashes in the redirect URI.
- Server to Server Setup: If your app does not support user interaction, consider using our OAuth over CLI guide for a command-line-based authentication setup.
- TLS 1.3 Requirement: As of April 3rd, 2023, Daisycon API only supports TLS 1.3 for improved security. Ensure your environment is configured to use TLS 1.3.
Authentication in the Swagger Daisycon API documentation
In the Swagger Daisycon API documentation, you can interact with most of the available API resources. Authentication is also required here. To get started, follow these steps:
- Go to the Daisycon Common Data API documentation and locate the
/authenticatecall. - Click on Try it out to enable the fields for input.
- In the body section, replace the
"string"placeholders with your Daisycon username and password. Put them between the quotation marks. - Click on Execute.
If successful, you will receive the required authentication token in the response body. Copy this token (a long string), but do not include the double quotes.
- Next, go to the Swagger Daisycon API documentation for advertisers, publishers, or common data.
- Click on Authorize (usually found at the top of the page).
- In the Value field, paste the token you copied.
- Click on Authorize again.
If successful, the status will show as Authorized, and you can now make API calls using the authenticated session.
Additional Resources
We offer documentation and code examples. Feel free to contribute by sending pull requests.