This guide will show you how to get logs for your recently sent SMS messages through the Infobip Go SDK.
The logs will tell you the specific status of each of your recently sent messages. For detailed information on the full capabilities of the Infobip SMS channel, check the API Reference.
Prerequisites
- Basic Go and API knowledge
- Go 13 (or newer) installation
- A running Go project
Steps overview
- Install the Infobip SDK.
- Import the required packages.
- Create an Infobip client.
- Send a message, if you haven’t already.
- Configure query parameters.
- Get the logs.
- Check the logs (optional).
Install the Infobip SDK
The SDK can be retrieved as a normal Go library, using the go get
command as follows:
go get "github.com/infobip-community/infobip-api-go-sdk/v3"
Import the required packages
You’ll need the Infobip client and models imported into your source code:
import (
//..
"github.com/infobip-community/infobip-api-go-sdk/v3/pkg/infobip"
"github.com/infobip-community/infobip-api-go-sdk/v3/pkg/infobip/models"
)
Create an Infobip client
To create the main client, you need to specify your API key, and custom base URL.
You can get them by logging into your Infobip account.
// Secrets configuration
baseURL := "your base URL here"
apiKey := "your api key here"
// Initialize Infobip client
client, _ := infobip.NewClient(baseURL, apiKey)
Send a message, if you haven’t
To get actual data in the logs, you need to have sent messages recently. If you haven’t, please send a message, following our Send SMS Guide.
Configure query parameters
You can configure many filters in the GetSMSLogsParams
struct. You can check them out by typing .
in your IDE, or going to the struct definition.
queryParams := models.GetSMSLogsParams{
Limit: 10,
}
Get the logs
Call the endpoint to get your outbound sent SMS logs.
resp, respDetails, _ := client.SMS.GetLogs(context.Background(), queryParams)
Note that logs can only contain the messages sent in the last 48 hours, and you can only retrieve 1000 messages per API call.
Check the logs (optional)
To verify that the logs are good, you can print the response and the return status code.
fmt.Printf("Logs: %+vn", resp)
fmt.Printf("HTTP response: %sn", respDetails.HTTPResponse.Status)
You should see the logs slice and a 200 OK
status code.
Logs: {Results:[{BulkID: MessageID:35643407711003572788 To:523311800428 From:59895 Text:Hello from Infobip Go SDK! SentAt:2022-06-28T16:34:37.195+0000 DoneAt:2022-06-28T16:34:37.366+0000 SmsCount:1 MccMnc:33403 Price:{PricePerMessage:0 Currency:EUR} Status:{Action: Description:Message delivered to handset GroupID:3 GroupName:DELIVERED ID:5 Name:DELIVERED_TO_HANDSET} Error:{Description:No Error GroupID:0 GroupName:OK ID:0 Name:NO_ERROR Permanent:false}}]}
HTTP response: 200 OK
The logs have many fields that you can access with the .
as with any struct.
resp.Results[0].Status.Description
resp.Results[0].MessageID // and so on ...
That’s all for this guide. Thanks for reading!