2
using (var httpClient = new HttpClient())
{
    httpClient.BaseAddress = new Uri("https://platform.clickatell.com/");

    httpClient.DefaultRequestHeaders.Accept.Clear();
    httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

    httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "wyOtm7-eRq-dSHWORr6hfw==");

    var stringContent = new StringContent("{\"content\":\"Test Message\",\"to\":[\"61400000000\"]}");
    stringContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

    var httpResponseMessage = AsyncHelper.RunSync(() => httpClient.PostAsync("messages", stringContent));

    var result = httpResponseMessage.Content.ReadAsStringAsync().Result;
}

result is: {"messages":[],"error":"Invalid or missing Integration API Key. - "}

But my API Key is exactly as defined by Clickatell.

Additional info: The Clickatell site displays the following Json curl call (note: I can't get curl working in order to test it).

CURL CALL:
==========
curl -i \
-X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Authorization: wyOtm7-eRq-dSHWORr6hfw==" \
-d '{"content": "Test Message Text", "to": ["61400000000"], "from": "+1234567890"}' \
-s https://platform.clickatell.com/messages

The only difference is that I am specifying my token as a bearer token. Without it I get a format exception.

Thankyou to anyone who may be able to shed some light on my issue.

Craig
  • 417
  • 3
  • 12
  • Another interesting thing... the API responds with Accepted (202) even though it has clearly taken issue with my API Key. – Craig Nov 22 '16 at 11:35

3 Answers3

2

FOR TEST API Manually

You can check it by Using Postman APP of Google Chrome

Steps :-

  1. Install POSTMAN (Go to google chrome app section search for postman)
  2. Create one API
  3. Select Method as POST
  4. Add This URL https://platform.clickatell.com/messages
  5. Go to header Section and ADD Headers
  6. Add Key = Content-Type , value = application/json
  7. Add Key = Accept , value = application/json
  8. Add Key = Authorization , value = Your API Key
  9. Go to body section
  10. Select as raw
  11. Add this in contant

    { "content": "Test Msg.", "to": ["+919999999999"] }

  12. Click on send

  13. You will find response for that.

By following above process you can also test you API manually.

1

I think I've worked it out. It looks like I need to use an invalid authorization header.

httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", "xxxxxxxxxxxxxxxxxxxxxx==");
Lynn Crumbling
  • 12,985
  • 8
  • 57
  • 95
Craig
  • 417
  • 3
  • 12
0

To solve this problem please follow below steps :

  1. Login to you clickatell account.
  2. Go to SMS integration (left side menu).
  3. Select (click on) your integration name.
  4. You will find Renew button followed by API Key.
  5. Click on Renew button and it will renew your API Key.
  6. Now save or publish your integration.
  7. Make sure that your SMS integration should be in active mode. (you can change status from SMS integration (left side menu) status tab)

Create one Entity( name : OTPRequestEntity)

public class OTPRequestEntity
{
    [JsonProperty("content")]
    public string content { get; set; }

    [JsonProperty("to")]
    public List<string> to { get; set; }
}

Go to your code and add headers :-

OTPResponseEntity entOTPResponseEntity = new OTPResponseEntity();
List<string> numbers = new List<string>();
numbers.Add("Your Mobile Number");
string apiBaseAddress = "https://platform.clickatell.com";
var objHttpClient = new HttpClient();
objHttpClient.BaseAddress = new Uri(apiBaseAddress);
objHttpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
objHttpClient.DefaultRequestHeaders.Add(HttpRequestHeader.ContentType.ToString(), "application/json");
objHttpClient.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", "Your API Key");
var vendRequest = new OTPRequestEntity
{
    content = "Your Message.",
    to = numbers
};
HttpResponseMessage apioresponse = await objHttpClient.PostAsJsonAsync("/messages", vendRequest).ConfigureAwait(false);
apioresponse.EnsureSuccessStatusCode();
if (apioresponse.StatusCode == HttpStatusCode.Accepted)
{
    string responseString = await apioresponse.Content.ReadAsStringAsync().ConfigureAwait(false);
    entOTPResponseEntity = JsonConvert.DeserializeObject<OTPResponseEntity>(responseString);
}

in entOTPResponseEntity object you will get API response.