How to make requests

Weasl's API is open to use for you to develop with. This is done to make it easy for you to directly ask for data without having to use an interface in your programming language, giving you full control of how you communicate with the API.

Including your client ID

For any public endpoints for your account (which is all that's available right now), you need to send along your client ID in the header X-Weasl-Client-Id, for example, if you were using python:

import requests as req

url = 'https://api.weasl.in/end_users/me'
headers = {
  "X-Weasl-Client-Id": 'YOUR CLIENT ID HERE',
  "X-Weasl-Client-Secret": 'YOUR CLIENT SECRET HERE'
}

res = req.get(url, headers=headers)

This request will return a 401 because you didn't also send along the user's token:

Including your user's login token

Once logged in, your user's session lasts for 7 days by default. Their cookie is stored on your domain (never on Weasl's) and is passed when making requests to your website. You can find the cookie under the value: WEASL_AUTH-(your client ID here), for example, if my client ID was 1111111111, then my logged in users' cookies would be found under: WEASL_AUTH-1111111111.

Here's a small JavaScript utility function you can use to get the cookie value:

export const getToken = () => {
  const COOKIE_NAME = 'WEASL_AUTH-1111111111';
  const startIndex = document.cookie.indexOf(COOKIE_NAME);
  if (startIndex === -1) {
    return null;
  }
  const startSlice = startIndex + COOKIE_NAME.length + 1;
  const endIndex = document.cookie.slice(startIndex).indexOf(';');
  if (endIndex === -1) {
    return document.cookie.slice(startSlice);
  } else {
    return document.cookie.slice(startSlice, startIndex + endIndex);
  }
}

When passing the user's login token, you need to send it under the Authorization header, for example:

import requests as req

url = 'https://api.weasl.in/end_users/me'
headers = {
    'X-Weasl-Client-Id': 'YOUR CLIENT ID HERE',
    'Authorization': 'bearer USER TOKEN HERE',
}

res = req.get(url, headers=headers)

Did this help answer your question?

thumbs up
thumbs down

Thanks for the feedback! 🙏🏽


Help by drift