Overview
Overview
The Quikly GraphQL API lets you build apps and other integrations using Quikly's urgency marketing platform. With the API, you can create unique experiences for your audiences natively within your app, or more tightly integrated with your website than the Javascript SDK may allow. This is the same API that powers Quikly's campaign microsites and embedded experiences.
Authentication
The GraphQL API requires a Quikly access token for making authenticated requests. Include the access token as a X-Quikly-Access-Token
header in your requests. Independent of this header, some API calls may require a Bearer
authorization token that uniquely identifies a user accessing the API (whereas the access token identifies your app).
Endpoint and Queries
All queries are run by sending a POST HTTP request to a single GraphQL endpoint:
1POST https://api.quikly.com/graphql
In GraphQL, queries are the the equivalent of REST's GET actions, but they allow you to fetch exactly the data you need. Any requests made to the GraphQL endpoint will be a POST request regardless if you are retrieving or modifying data.
Example Query
The following example shows a query for fetching basic details about a Quikly campaign, include the name, description, and customized labels used at various spots in the UI.
1query promoLandingQuery() {2 quikly(hashid: "XqyhklE") {3 id4 name5 description6 header: customContentFor(key: "embedded_instant_sign_in_header")7 finePrint8 buttonText: customContentFor(key: "embedded_instant_sign_in_button_text")9 image {10 url(variant: "original")11 }12 }13}
The response will be a json structure with a root-level "data" key and then data that mirrors what was requested in the query:
1{2 "data": {3 "quikly": {4 "id": "RGVhbC04Mzc3",5 "name": "Flash Promo Demo",6 "description": "",7 "header": "Sign into your account to get this offer.",8 "cookieNotRequired": true,9 "finePrint": "",10 "buttonText": "Sign in",11 "signInPixel": null,12 "image": {13 "url": "/assets/missing.png"14 }15 }16 }17}
Visit the official GraphQL site to learn more about queries.
Exploring the API
While specific GraphQL client libraries exist, you can access the GraphQL API from any programming language or framework that supports HTTP requests and JSON. While you are learning the API, a good way to test out queries and explore the schema is to the Quikly GraphQL API, but you can also use curl, a tool like Postman, or the language of your choice.
Use the GraphiQL App
Visit the GraphiQL Explorer to explore the schema and test out your queries. The GraphiQL Explorer allows you to authenticate, paste in your queries, supports autocompletion and syntax highlighting, and provides a detailed schema reference.
Use curl
Here is an example of loading data you might want to display on the first screen of a Quikly Drop. You could extend this example to work from any language that is capable of making HTTP requests. Note the POST body must be a valid JSON with a "query" key that contains the actual GraphQL query.
1curl -X POST https://api.quikly.com/graphql \2 -H 'Content-Type: application/json' \3 -H 'Accept: application/json; charset=utf-8' \4 -H 'X-Quikly-Access-Token: {account-token}' \5 -d @- << 'EOF'6{7 "query": "{8 quikly(hashid: \"WLYhqa\") {9 id10 name11 description12 header: customContentFor(key: \"embedded_instant_sign_in_header\")13 cookieNotRequired14 finePrint15 buttonText: customContentFor(key: \"embedded_instant_sign_in_button_text\")16 signInPixel: getPixel(placement: \"embedded-sign-in-js\") {17 content18 repeatable19 }20 image {21 url(variant: \"original\")22 }23 }24 }"25}26EOF
If you were making this request via Javascript, you could build your request body with something like this:
1const accountToken = '';2const options = {3 method: 'POST',4 headers: {Accept: 'application/json; charset=utf-8', 'Content-Type': 'application/json', 'X-Quikly-Access-Token': accountToken},5 body: JSON.stringify({6 query: `7 query promoLandingQuery {8 quikly(hashid: "XqyhklE") {9 id10 name11 }12 }13 `14 })15};1617fetch('https://api.quikly.com/graphql', options)18 .then(response => response.json())19 .then(response => console.log(response))20 .catch(err => console.error(err));
Mutations
In GraphQL, mutations are like any of the data-modifying REST verbs (PUT, POST, DELETE) that modify data on the server, but you can also specify the fields contained in (or the "shape of") the response. This example shows a mutation that attempts to claim a Quikly offer. This example makes use of variables, but you could also include the values directly in the mutation. If you do use variables, you pass them in a separate (usually JSON) variables dictionary.
1 mutation createEmbeddedClaim(2 $dealHashid: String!3 $email: String!4 ) {5 createEmbeddedClaim(6 input: { dealId: $dealHashid, email: $email }7 ) {8 errors {9 key10 message11 }12 user {13 id14 authToken15 }16 order {17 id18 qid19 receiptToken20 }21 }22 }
With curl:
1curl -X POST \2 http://api.quikly.com/graphql \3 -H 'Content-Type: application/json' \4 -H 'Accept: application/json; charset=utf-8' \5 -H 'X-Quikly-Access-Token: {account-token}' \6 -d @- << 'EOF'7{8 "query": "mutation createEmbeddedClaim(9 $dealHashid: String!,10 $email: String!11 ) {12 createEmbeddedClaim(13 input: { dealId: \$dealHashid, email: \$email }14 ) {15 errors {16 key17 message18 }19 user {20 id21 authToken22 }23 order {24 id25 qid26 receiptToken27 }28 }29 }",30 "variables": "{31 \"dealHashid\": \"WLYhqa\",32 \"email\": \"scott@quikly.com\"33 }"34}35EOF
Visit the official graphql.org site for more background on mutations.
We have built a collection of queries and mutations common to specific Quikly campaign types. Check out the GraphQL Examples.