Avatar of Alpha_AI
Alpha_AI asked on

How to i use the idHttp to do the following?

I need to connect and send messages. Here is the api. Any help would be appreciated.

https://www.directsms.com.au/info/api/http.html
Delphi

Avatar of undefined
Last Comment
Lukasz Zielinski

8/22/2022 - Mon
ASKER
Alpha_AI

Or if you can give me code for all functions in the api, that would be even better.
ASKER
Alpha_AI

It must be using the idHttp component from indy.
Lukasz Zielinski

here's sample of using CONNECT:
procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo1.Lines.Text := IdHTTP1.Get('http://api.directsms.com.au/s3/http/connect?username=my_user&password=my_password&licence_key=my_lic_key');
end;

rest of function in similar way.

ziolko.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER
Alpha_AI

THanks heaps, it recommends that i instead use the post command.
How would i do that?
ASKER CERTIFIED SOLUTION
Lukasz Zielinski

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
Alpha_AI

It doesnt work properly
so ive gotten my connectionid

and then i use

procedure TForm1.SendMessageClick(Sender: TObject);
var
  id : string;
  getstring : string;
  thestring : string;
  Parameters2 : TStringList;
begin
Parameters2 := TStringList.Create;
try
connection := 'connectionid='+theconnectionid;
Parameters2.Add(connection);
Parameters2.Add('message='+Memo1.Text);
Parameters2.Add('to=0417085662');
id := idHttp1.Post('http://api.directsms.com.au/s3/http/send_two_way_message',Parameters2);
finally
showmessage(id);
Parameters2.Free;
end;
end;

This is supposed to send a message but the response im getting back is

err: invalid connection id; please use the connect() operation before calling other operations

Ive already connected by using this:

procedure TForm1.ConnectClick(Sender: TObject);
var
  Parameters1 : TStringList;
begin
Parameters1 := TStringList.Create;
try
Parameters1.Add('username=myuserid');
Parameters1.Add('password=mypassword');
Showmessage(Parameters1.Text);
theconnectionid := idHttp1.Post('http://api.directsms.com.au/s3/http/connect',Parameters1);
finally
showmessage('Connected: '+theconnectionid);
delete(theconnectionid,1,4);
Parameters1.Free;
end;
end;

Weird, any clues?
ASKER
Alpha_AI

the reason why i have to delete some characters is because it adds 'id: ' onto the connectionid.
so i delete those characters so i can get the real connection id.

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Lukasz Zielinski

when sending message make sure that your connection ID is exactly 32 characters long.

ziolko
ASKER
Alpha_AI

Apparently it changes to 34 to 32
why i dont know
how would i fix that, i tried trim and that didnt work
Lukasz Zielinski

if it changes from 32 to 34 it means you have end of line marker at the end, try this:

finally
 showmessage('Connected: '+theconnectionid);
 delete(theconnectionid,1,4);
 SetLength(theconnectionid, 32);
 Parameters1.Free;
end;

ziolko.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Lukasz Zielinski

or even better:

finally
 showmessage('Connected: '+theconnectionid);
 theconnectionid := Copy(theconnectionid, 4, 32);
 Parameters1.Free;
end;

ziolko.