You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I can send a curl that includes the key in the header (Authorization: AccessKey <access_key>) and successfully sends an SMS. This uses the API at "https://api.bird.com"
But when I use the same key on the REST API ("https://rest.messagebird.com") I get an "incorrect access_key" error. I am using the official Ruby SDK (this one) to hit the REST API.
Do I need a different access key? Is the REST API still supported?
Did you get this to work? I've also tried to add a custom policy for the channels, but nothing seems to work with the Ruby client. Curl requests from the new API examples work though.
I ended up creating a minimal client for my simple use case. Perhaps it will help you...
require"net/http"require"json"# The messagebird-rest-api gem uses the old REST api which isn't supported.# There is no gem for the new API.classBirdServiceMESSAGES_BASE_URL="https://api.bird.com/workspaces/%{workspace_id}/channels/%{channel_id}/messages".freezeACCESS_KEY=Rails.application.credentials.dig(:bird,:access_key)WORKSPACE_ID=Rails.application.credentials.dig(:bird,:workspace_id)SMS_CHANNEL_ID=Rails.application.credentials.dig(:bird,:sms_channel_id)definitialize(workspace_id,channel_id,access_token)@workspace_id=workspace_id@channel_id=channel_id@access_token=access_tokenend@@client=BirdService.new(WORKSPACE_ID,SMS_CHANNEL_ID,ACCESS_KEY)defself.client@@clientenddefsend_sms(receiver_number,message_text)uri=URI(format(MESSAGES_BASE_URL,workspace_id: @workspace_id,channel_id: @channel_id))request_body={receiver: {contacts: [{identifierValue: receiver_number}]},body: {type: "text",text: {text: message_text}}}beginresponse=Net::HTTP.post(uri,request_body.to_json,headers)ifresponse.is_a?(Net::HTTPSuccess)handle_success(response)elsehandle_error(response)endrescueStandardError=>ehandle_exception(e)endendprivatedefheaders{"Content-Type"=>"application/json","Authorization"=>"Bearer #{@access_token}"}enddefhandle_success(response)message_data=JSON.parse(response.body)message_id=message_data["id"]status=message_data["status"]created_at=message_data["createdAt"]puts"Message sent successfully!"puts"Message ID: #{message_id}"puts"Status: #{status}"puts"Created At: #{created_at}"enddefhandle_error(response)error_data=JSON.parse(response.body)error_message=error_data["error"] || "Unknown error"puts"Error sending message: #{response.code} - #{error_message}"enddefhandle_exception(exception)puts"Exception occurred while sending message: #{exception.message}"endend
Thank you! I did open a support case with Bird, I'm curious where that ends.
There's more SDK's on this org, which all use the REST API, not sure what's going on.
Edit: Got an update that the REST API is considered legacy and new signups for this API are no longer possible.
Activity
tdegrunt commentedon Jun 27, 2024
Did you get this to work? I've also tried to add a custom policy for the channels, but nothing seems to work with the Ruby client. Curl requests from the new API examples work though.
spinosa commentedon Jun 27, 2024
I ended up creating a minimal client for my simple use case. Perhaps it will help you...
tdegrunt commentedon Jun 28, 2024
Thank you! I did open a support case with Bird, I'm curious where that ends.
There's more SDK's on this org, which all use the REST API, not sure what's going on.
Edit: Got an update that the REST API is considered legacy and new signups for this API are no longer possible.