Help Center


Api clients - Auth Code flow

https://app.chaskiq.io/rails/active_storage/representations/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBbXdEIiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--827f2d0b5794f7bb660c48b79e228655bd857bed/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCem9MWm05eWJXRjBTU0lJYW5CbkJqb0dSVlE2RkhKbGMybDZaVjkwYjE5c2FXMXBkRnNIYVdscGFRPT0iLCJleHAiOm51bGwsInB1ciI6InZhcmlhdGlvbiJ9fQ==--cf24ea7784b3789671bb09c4029aca003c26b32d/me.jpg

Written by Miguel Michelson

updated

Chaskiq provides a Graphql API were you can query , create, update and delete campaings all the things that are provided in the admin inteface in which also consumes the same API. In order to consume and mutate Chaskiq data you'll need to authenticate your requests via Oauth2.

Create application

when you have logged into the Chaskiq panel , go to yourapp.com/oauth/applications and create a new application. If your application will be consumed by native application in which not requires redirection callback you can use the urn:ietf:wg:oauth:2.0:oob value for callback.

Connect to application Example:

This is a ruby example in which you can connect to the API. The xxx values expect the proper app_id & secret generated on the oauth application you created in the previous step.

callback = "urn:ietf:wg:oauth:2.0:oob"

secret = "xxxxx-api-secret"

app_id = "xxxx-app_id"

client = OAuth2::Client.new(app_id, secret, site: "https://app.chaskiq.io")

client.auth_code.authorize_url(redirect_uri: callback)

The last line will give you a url that you will need to visit in order to authorize the application.


 => "https://app.chaskiq.io/oauth/authorize?client_id=xxx-app-id&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code"

and you will get something like this:

Once you've authorized the integration the platform will provide the code to make authorized requests to the API

The authorization code is the grant access that you can use to retrieve a new access_token. The following is a Ruby example with the Oauth2 gem to retrieve the access_token:

require 'oauth2'

client = OAuth2::Client.new(client_id, client_secret, :site => 'http://localhost:3000')

client.auth_code.authorize_url(:redirect_uri => 'http://localhost:3000/callback')

token = client.auth_code.get_token(authorization_code_value, :redirect_uri => 'http://localhost:3000/callback')