API integration (GraphQL) of Cyanite AI via Bearer format

Hey there folks!

I’m currently trying to integrate the Cyanite AI to Touchdesigner. The AI works with an GraphQL API via Bearer format.

I already tried to integrate the API via the Web Client DAT, but unfortunately it looks like the authentication format Bearer is not supported in Touchdesigner (see attachment).

Should it be possible to integrate the API via Python?
(I’ve worked some time with Touchdesigner, but I’m pretty new to Python)

Many thanks in advance for any help!

Hey @jos_ra

Briefly looking at the doc, I feel that all you have to do is pass the access token in the request headers.

Here: Sending API requests | Cyanite.ai API Documentation

The important bit is the following: Authorization: Bearer ACCESS_TOKEN

You get the access token from creating an integration: Creating an integration | Cyanite.ai API Documentation

And the sample curl cmd

curl \
  -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ACCESS_TOKEN"\
  --data '{ "query": "query LibraryTracksQuery { libraryTracks(first: 10) { edges { node { id } } } }", "variables": { "first": 10 } }' \
  https://api.cyanite.ai/graphql

So, what we get from the sample above: it’s a POST request, with a header property setting the content-type, and another setting the Authorization.

If you go add a WebClient DAT in TouchDesigner, add a Table DAT right before it with 2 columns and 2 rows, passing it to the first input.

Content-Type	application/json
Authorization	Bearer ACCESS_TOKEN

Edit, with screenshot:

Should do the trick.

Let me know if that helps,

Best,
Michel

Hi @JetXS,

thanks so much for your detailed answer! It really helps a lot to understand this whole integration.

I tried to integrate the API as you described, but unfortunately I got an 422 error.
Am I doing something wrong?

Again, many thanks.

Best,
Josefa

Maybe it could be that you are not passing any query in the body of the request

{
  "query": "query LibraryTracksQuery { libraryTracks(first: 10) { edges { node { id } } } }",
  "operationName": "...",
  "variables": { "first": 10 }
}

From our doc https://docs.derivative.ca/Web_Client_DAT

The second input is the data/parameters to send in the request. This can be a table with two columns, structured as name/value pairs. It can also just be text, in which case it will be sent as is. If the request method doesn’t have a request body (eg. GET, OPTIONS) then it will append the input to the URL as query parameters if a table, otherwise it will be sent as the request data.

Try passing your query (which should follow the Cyanite AI doc) from a Text DAT connected to the second input of the WebClient DAT.

Best,
Michel

Thank you!

Now I’m getting a 400 Bad Request.

But I just used the example request body, which I’m not quite sure about.

Best,
Josefa

You could have a look at the details of the error message that the Cyanite API returned, if any. Maybe there are details about what message they are expecting in the API documentation.

It’s likely that the message is badly formatted…

Maybe Cyanite’s support could identify the issue.

Good luck!

Best,
Michel

Alright, maybe I can find out more in the documentation.
Thanks a lot for your support!

Best,
Josefa

1 Like

Followup: the solution was actually pretty easy. The operationName has to be “LibraryTracksQuery”.

1 Like