Does assigning an API key via API overwrite an existing API key? | XM Community
Question

Does assigning an API key via API overwrite an existing API key?

  • 19 December 2023
  • 2 replies
  • 32 views

Userlevel 1
Badge +8

Via the API, I can, given a user’s API key - which not all users have - get a list of all that user’s surveys and surveys they’re collaborating on- limited to the first 100 surveys

QUESTION: Does assigning an API key via API overwrite an existing API key? I was thinking about looping through all users and assigning an API key, so that I can then loop through users and get a list of their surveys, but I’m worried it’ll overwrite any existing API keys and break any API calls the user has. Does anyone know? I’m afraid to try.

Here’s the API call I want to get a list of surveys for a user

And here’s the API call to post an API


2 replies

Userlevel 3
Badge +6

@riceball ,

API token cannot be created using create user API Token API. It can be used only if the user has not generated a API token before.

Instead, you can follow the below steps:

Step 1: Retirve the API token of different users using get user API token by passing the user id

Step 2: Get the list of surveys using the API token retrieved from step 1.

Userlevel 1
Badge +8

Okay, thanks! For anyone looking in the future, here’s how it seems to go, using the api docs linked above:

  • Loop through all user IDs in your brand and send the post to generate an API token.
    • If the user doesn’t already have an API token, you’ll get a 200OK and an API token returned.
      • Use this API token to generate a list of surveys
    • If the user does already have an API token, you’ll get a 400 bad request.
      • For this user, instead call the get user api endpoint.
      • Use the returned API token to generate a list of surveys.

Leave a Reply