Clickatell API to send SMS

Hi, I have the following API to send SMS:

curl -i
-X POST
-H “Content-Type: application/json”
-H “Accept: application/json”
-H “Authorization: XXXXXXXXX”
-d ‘{“content”: “87684454”, “to”: [“000000000”]}’
-s https://platform.clickatell.com/messages

I set up the API Action as following:

But doesn’t work.

It is well done the set up of the api or is it wrong?

Thank You

Roberto

Hi. Try setting data type to JSON… and check your browser’s developer options to track what the actual request looks like.
I see that to requires a JSON array… so that could also be the reason for failure.

For Google Chrome, you can see it in the Network tab of Dev Tool/Inspect Element window.

Also, I would recommend using the server action API step. This client side API action will expose your keys. It should not be an issue though if the key is domain locked… else, use server side API call.

1 Like

Thank you @sid but also if I put JSON it doesn t works.

Have you concluded that this is the only issue with the API request you have setup?
In case you are not sure, try sharing the response too.

Can you share your form structure because “to” field must be an array .

that’s a big problem. I was thinking it must be an array… but sincerely I don’t know how to do it.

It is not problem .
Change input name to to[]

Then try again

Did you manage to get this working @updates?
I tried with to[] as suggested by @s.alpaslan and didn’t have much success
{“content”: “My Message”, “to”: [“MOBILENUMBER”]}

hi, unfortunately not. I had other jobs ti do so I leaved it on the side. hope next week to study something will keep you informed

1 Like

I’ve had a few issues with client-side API Actions recently and have found it much more reliable to use Server Connect to link to an action that contains an API Action. It also makes it a bit easier to add forms/tables to a page (particularly across multiple pages without having to define the Schema each time)

When creating the Globals for the input ‘to’, you can define it as an array:

There is also an issue in IOS 12 that can stop API calls working. By implementing it through Server Connect you also avoid this.

I hope this helps

1 Like

This has intrigued me, I signed up for a test account and like @updates
Having difficulty working out the method of sending the following in ServerConnect API Connector. I did try setting the to as an array.

{"content": "SMS Message Text", "to": ["CELLNUMBER"]}

Any advice appreciated

1 Like

we should require @ben a special webminar on it :wink:

Heres it is in javascript if it helps

var xhr = new XMLHttpRequest(),
    body = JSON.stringify({
        "content": "SMS Message Text",
        "to": ["4479760000000"]
    });
xhr.open("POST", 'https://platform.clickatell.com/messages', true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Authorization", "TcGNoNOTAREALKeyKv0XpaQ==");
xhr.onreadystatechange = function(){
    if (xhr.readyState == 4 && xhr.status == 200) {
        console.log('success');
    }
};

xhr.send(body);

OK, so managed to make it work:

  1. Set up the Server Connect form with ‘to’ and ‘content’ inputs - send as POST

  2. Set up POST globals for ‘to’ and ‘content’

  3. Add API Action with the following settings:
    image

  4. Add Header for ‘Authorization’ with the value of your API (without any quotes)

  5. Add Input Data for ‘to’ and ‘content’ set to the respective POST globals set up earlier

You had most of this but it appears that the key setting is setting the Data Type to form

This is tested on a test account for single messages to single recipients. Do you need multiple recipients per message?

Yes, I could need multiple numbers.

can you show more screenshots please?

i.e.: in the header should I write ‘Authorization’ or Authorization?

The names for headers and inputs are always without quotes. The values also don’t require quotes, unlike other areas of Wappler.

On the form make sure the name attribute for the inputs
image
reflects the POST variables you set up in Globals (Server Connect)
image

image

image

Once all set up, save it and then click ‘Define API Schema’ in the API Action step
image

The Authorization header should be completed already - just enter static values for the recipient (use the mobile number you set up in your account as the test number - in international format) and the message.
Click ‘Fetch Schema’ - you can show the response section at the bottom of this modal using the chevron underneath the Fetch Schema button.

1 Like

Thank you very much for your screenshots.

I followed your instruction but got error:

I set in the Globals the POST variables:

21

then I added the API Action in the server connect

27

I set up the API as per your instructions:
34

added the input data:

41

added the Header Authorization

then fetch schema

and I get

In nay case while trying one SMS arrived… means have to check carefully…

Very weird:

It works. Thank you very much for your support @bpj !!
Suggestions: sometimes instead to search for something wrong… it is better to write Authorization correctly… and everything will works!!