Sinch Engage: List Approved Sender Addresses
See more Sinch Engage Examples
Enumerate approved sender-address records with pagination. The returned address ID differs from the request ID issued during sender registration. Inspect display_status and destination eligibility before using a sender. This does not register, renew, or delete a sender.
Sinch Engage is the renamed MessageMedia platform. This uses the Engage API, not Sinch Conversation API credentials or endpoints. Create an Engage API key/secret and place {"api_key":"YOUR_KEY","api_secret":"YOUR_SECRET"} in private sinch-engage.json. Select the account's regional HTTPS host: https://au.app.api.sinch.com, https://eu.app.api.sinch.com, or https://us.app.api.sinch.com. Basic authentication here means the API key/secret over verified TLS. Do not ship account credentials in a public mobile, browser, or desktop application.
Transport success and API success are checked separately. On HTTP 429, honor Retry-After before a bounded retry. Check account permissions and regional credentials for 401/403. A timeout or 5xx response after submitting a write can leave its outcome uncertain: reconcile before retrying, especially sends and resource creation. Metadata is correlation data, not an idempotency key. Inspect error bodies privately because they can contain phone numbers and message content.
Chilkat C Downloads
#include <C_CkJsonObject.h>
#include <C_CkHttp.h>
#include <C_CkStringBuilder.h>
#include <C_CkHttpResponse.h>
#include <C_CkHashtable.h>
void ChilkatSample(void)
{
BOOL success;
HCkJsonObject config;
const char *apiHost;
HCkHttp http;
HCkStringBuilder url;
HCkHttpResponse resp;
HCkJsonObject result;
const char *nextToken;
HCkHashtable seenTokens;
int pageCount;
int i;
success = FALSE;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
// Store real credentials in private configuration, never in distributed client code.
config = CkJsonObject_Create();
CkJsonObject_putStrict(config,TRUE);
success = CkJsonObject_LoadFile(config,"sinch-engage.json");
if (success != TRUE) {
printf("Could not load private sinch-engage.json.\n");
CkJsonObject_Dispose(config);
return;
}
if ((CkJsonObject_JsonTypeOf(config,"api_key") != 1) || (CkJsonObject_StringOfEquals(config,"api_key","",TRUE) == TRUE) || (CkJsonObject_JsonTypeOf(config,"api_secret") != 1) || (CkJsonObject_StringOfEquals(config,"api_secret","",TRUE) == TRUE)) {
printf("The private configuration must contain api_key and api_secret.\n");
CkJsonObject_Dispose(config);
return;
}
// Choose the host for your Engage account: au, eu, or us. Do not guess from the recipient.
apiHost = "https://au.app.api.sinch.com";
http = CkHttp_Create();
CkHttp_putRequireSslCertVerify(http,TRUE);
CkHttp_putFollowRedirects(http,FALSE);
CkHttp_putConnectTimeout(http,20);
CkHttp_putReadTimeout(http,30);
CkHttp_putLogin(http,CkJsonObject_stringOf(config,"api_key"));
CkHttp_putPassword(http,CkJsonObject_stringOf(config,"api_secret"));
CkHttp_putBasicAuth(http,TRUE);
CkHttp_SetRequestHeader(http,"Accept","application/json");
url = CkStringBuilder_Create();
resp = CkHttpResponse_Create();
result = CkJsonObject_Create();
CkJsonObject_putStrict(result,TRUE);
nextToken = "";
seenTokens = CkHashtable_Create();
pageCount = 0;
while ((pageCount < 100)) {
CkStringBuilder_Clear(url);
CkStringBuilder_Append(url,apiHost);
CkStringBuilder_Append(url,"/v1/messaging/numbers/sender_address/addresses?page_size=50");
if (nextToken != "") {
CkStringBuilder_Append(url,"&token=");
CkStringBuilder_Append(url,CkHttp_urlEncode(http,nextToken));
}
success = CkHttp_HttpNoBody(http,"GET",CkStringBuilder_getAsString(url),resp);
// HttpJson/HttpNoBody also return false for HTTP 4xx/5xx responses.
if ((success != TRUE) && (CkHttpResponse_getStatusCode(resp) == 0)) {
printf("HTTP transport failed. Inspect diagnostics privately; do not blindly retry a write.\n");
CkJsonObject_Dispose(config);
CkHttp_Dispose(http);
CkStringBuilder_Dispose(url);
CkHttpResponse_Dispose(resp);
CkJsonObject_Dispose(result);
CkHashtable_Dispose(seenTokens);
return;
}
if ((CkHttpResponse_getStatusCode(resp) != 200)) {
printf("Unexpected HTTP status: %d\n",CkHttpResponse_getStatusCode(resp));
if (CkHttpResponse_getStatusCode(resp) == 429) {
printf("Retry-After: %s\n",CkHttpResponse_getHeaderField(resp,"Retry-After"));
}
CkJsonObject_Dispose(config);
CkHttp_Dispose(http);
CkStringBuilder_Dispose(url);
CkHttpResponse_Dispose(resp);
CkJsonObject_Dispose(result);
CkHashtable_Dispose(seenTokens);
return;
}
success = CkJsonObject_Load(result,CkHttpResponse_bodyStr(resp));
if (success != TRUE) {
printf("Expected a JSON response.\n");
CkJsonObject_Dispose(config);
CkHttp_Dispose(http);
CkStringBuilder_Dispose(url);
CkHttpResponse_Dispose(resp);
CkJsonObject_Dispose(result);
CkHashtable_Dispose(seenTokens);
return;
}
if (CkJsonObject_SizeOfArray(result,"data") < 0) {
printf("Expected an array in the response.\n");
CkJsonObject_Dispose(config);
CkHttp_Dispose(http);
CkStringBuilder_Dispose(url);
CkHttpResponse_Dispose(resp);
CkJsonObject_Dispose(result);
CkHashtable_Dispose(seenTokens);
return;
}
i = 0;
while ((i < CkJsonObject_SizeOfArray(result,"data"))) {
CkJsonObject_putI(result,i);
printf("Sender address ID: %s\n",CkJsonObject_stringOf(result,"data[i].id"));
printf("Sender: %s\n",CkJsonObject_stringOf(result,"data[i].sender_address"));
printf("State: %s\n",CkJsonObject_stringOf(result,"data[i].display_status"));
i = i + 1;
}
pageCount = pageCount + 1;
nextToken = "";
if (CkJsonObject_JsonTypeOf(result,"pagination.next_token") == 1) {
nextToken = CkJsonObject_stringOf(result,"pagination.next_token");
}
if (nextToken == "") {
printf("Completed pages: %d\n",pageCount);
CkJsonObject_Dispose(config);
CkHttp_Dispose(http);
CkStringBuilder_Dispose(url);
CkHttpResponse_Dispose(resp);
CkJsonObject_Dispose(result);
CkHashtable_Dispose(seenTokens);
return;
}
if (CkHashtable_Contains(seenTokens,nextToken) == TRUE) {
printf("Repeated pagination token; stopping to avoid a loop.\n");
CkJsonObject_Dispose(config);
CkHttp_Dispose(http);
CkStringBuilder_Dispose(url);
CkHttpResponse_Dispose(resp);
CkJsonObject_Dispose(result);
CkHashtable_Dispose(seenTokens);
return;
}
CkHashtable_AddInt(seenTokens,nextToken,1);
}
printf("Stopped at the example's 100-page limit. Save the continuation token to resume.\n");
CkJsonObject_Dispose(config);
CkHttp_Dispose(http);
CkStringBuilder_Dispose(url);
CkHttpResponse_Dispose(resp);
CkJsonObject_Dispose(result);
CkHashtable_Dispose(seenTokens);
}