Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sessions.CreateSessionTokenAsync(sessionId) returns 415 Unsupported Media Type #18

Open
jfoshee opened this issue Jan 29, 2025 · 1 comment

Comments

@jfoshee
Copy link

jfoshee commented Jan 29, 2025

Repro Code

var sdk = new ClerkBackendApi(bearerAuth: "sk_test_...");

var request = new CreateSessionRequestBody
{
    UserId = "user_...",
};
var response = await sdk.Sessions.CreateSessionAsync(request);
response.Session.Should().NotBeNull();
var sessionId = response!.Session!.Id;
sessionId.Should().NotBeNullOrEmpty();

var response2 = await sdk.Sessions.CreateSessionTokenAsync(sessionId);    // Throws 415

SDKError.Response

{StatusCode: 415, ReasonPhrase: 'Unsupported Media Type', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
  Date: Wed, 29 Jan 2025 16:32:46 GMT
  Connection: keep-alive
  CF-Ray: 909a9ec3adac69d9-DFW
  CF-Cache-Status: DYNAMIC
  clerk-api-version: 2021-02-05
  X-CFWorker: 1
  x-clerk-trace-id: 9897512248aa9bf77c337efd2bb57efb
  x-cloud-trace-context: 9897512248aa9bf77c337efd2bb57efb
  Server: cloudflare
  Content-Type: application/json
  Content-Length: 228
}}

Speculation

Note that Sessions.CreateSessionTokenAsync has an optional second parameter for overriding the default expiration.

If we make the request as so, then the request succeeds:

var response2 = await sdk.Sessions.CreateSessionTokenAsync(sessionId, new());

As sessionId is part of the request URL and the second argument is used for the request Body, it seems that the missing request body causes the problem.

@logangingerich
Copy link
Collaborator

Hi @jfoshee !
Thanks for the detailed write-up here. Like you mention, it sounds like the issue can be resolved by ensuring the second parameter (the request body) is always passed, even if it’s empty. This is why the working request adds an empty body: new().

In your opinion, do you thinking changing that field to be explicitly required would provide a good resolution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants