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

Space API endpoints include extra $ in paths when variable substitution occurs #47

Closed
murraysum opened this issue Jun 13, 2022 · 5 comments

Comments

@murraysum
Copy link

Issue

In several of the Space API endpoints when variable substitution occurs for the SPACE_ID or BROADCAST_ID there is a $ prepended to the identifier which makes the path incorrect. As a result the API rejects the request. For example, the create a space broadcast endpoint instead of making a request to https://api.mux.com/video/v1/spaces/my_space_id/broadcasts it makes a request to https://api.mux.com/video/v1/spaces/$my_space_id/broadcasts:

The following endpoints are effected:

  • Create a space broadcast
    local_var_path = '/video/v1/spaces/${SPACE_ID}/broadcasts'.sub('{' + 'SPACE_ID' + '}', CGI.escape(space_id.to_s))
  • Delete a space
    local_var_path = '/video/v1/spaces/${SPACE_ID}'.sub('{' + 'SPACE_ID' + '}', CGI.escape(space_id.to_s))
  • Delete a space broadcast
    local_var_path = '/video/v1/spaces/${SPACE_ID}/broadcasts/${BROADCAST_ID}'.sub('{' + 'SPACE_ID' + '}', CGI.escape(space_id.to_s)).sub('{' + 'BROADCAST_ID' + '}', CGI.escape(broadcast_id.to_s))
  • Get a space
    local_var_path = '/video/v1/spaces/${SPACE_ID}'.sub('{' + 'SPACE_ID' + '}', CGI.escape(space_id.to_s))
  • Get a space broadcast
    local_var_path = '/video/v1/spaces/${SPACE_ID}/broadcasts/${BROADCAST_ID}'.sub('{' + 'SPACE_ID' + '}', CGI.escape(space_id.to_s)).sub('{' + 'BROADCAST_ID' + '}', CGI.escape(broadcast_id.to_s))
  • Start a space broadcast
    local_var_path = '/video/v1/spaces/${SPACE_ID}/broadcasts/${BROADCAST_ID}/start'.sub('{' + 'SPACE_ID' + '}', CGI.escape(space_id.to_s)).sub('{' + 'BROADCAST_ID' + '}', CGI.escape(broadcast_id.to_s))
  • Stop a space broadcast
    local_var_path = '/video/v1/spaces/${SPACE_ID}/broadcasts/${BROADCAST_ID}/stop'.sub('{' + 'SPACE_ID' + '}', CGI.escape(space_id.to_s)).sub('{' + 'BROADCAST_ID' + '}', CGI.escape(broadcast_id.to_s))

How to reproduce

The default spaces example for creating a broadcast should show you the error:

api_instance = MuxRuby::SpacesApi.new
space_id = 'space_id_example' # String | The space ID.
create_broadcast_request = MuxRuby::CreateBroadcastRequest.new({live_stream_id: 'live_stream_id_example'}) # CreateBroadcastRequest | 

begin
  # Create a space broadcast
  result = api_instance.create_space_broadcast(space_id, create_broadcast_request)
  p result
rescue MuxRuby::ApiError => e
  puts "Error when calling SpacesApi->create_space_broadcast: #{e}"
end

You should get API response something like this (redacted the space_id):

ETHON: performed EASY effective_url=https://api.mux.com/video/v1/spaces/$redacted_space_id/broadcasts response_code=400 return_code=ok total_time=0.563622
Error when calling SpacesApi->create_space_broadcast:
HTTP status code: 400
Response headers: {"cache-control"=>"max-age=0, private, must-revalidate", "content-type"=>"application/json; charset=utf-8", "date"=>"Mon, 13 Jun 2022 16:04:47 GMT", "server"=>"Mux API Server v1.157.23", "x-request-id"=>"Fvg5rxBASuUuMp8DfAMF", "content-length"=>"88"}
Response body: {"error":{"type":"invalid_parameters","messages":["Invalid space id, failed to parse"]}}

Expected behaviour

When variable substitution occurs in the API paths $ is not prepended to identifiers and API requests are not rejected.

Actual behaviour

When variable substitution occurs in the API paths $ is prepended to identifiers and API requests are rejected.

murraysum pushed a commit to murraysum/mux-ruby that referenced this issue Jun 13, 2022
…rs for the SPACE_ID or BROADCAST_ID there is a $ prepended to the identifier which makes the path incorrect. As a result the API rejects the request. For example, the create a space broadcast endpoint instead of making a request to https://api.mux.com/video/v1/spaces/my_space_id/broadcasts it makes a request to https://api.mux.com/video/v1/spaces/$my_space_id/broadcasts

Fixes muxinc#47
@eropple
Copy link
Contributor

eropple commented Jun 13, 2022

Well, this is wild. Thanks for reporting it, and in such a detailed manner. We'll look into it ASAP.

@eropple
Copy link
Contributor

eropple commented Jun 13, 2022

Fix located. Will be deploying today.

@eropple
Copy link
Contributor

eropple commented Jun 13, 2022

And fix is out with mux-ruby 3.5.2. Thanks for bringing this to our attention with such a detailed bug report, it really helped.

@eropple eropple closed this as completed Jun 13, 2022
@clearlyTHUYDOAN
Copy link

@murraysum thanks for the great bug report! 🎉

As part of our OSS contribution program, we'd love to send you some swag as our way of saying thank you and recognizing your work. Please email me at [email protected] with your details and we'll get something sent out to you! 🎁

@murraysum
Copy link
Author

@eropple No problem at all. Thanks for fixing this so quickly, much appreciated. Loving the Mux real time API so far, it is awesome. 👏

@clearlyTHUYDOAN Thank you very much, that is very kind of you. I'll email you my details. 👍

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

3 participants