Convert API call to Xojo

I’m trying to create emails with the API of Selzy. I can use Postman fine:

A simple GET call copied into the browser works fine:

When try to use a UrlConnection I only get access denied:

Dim FormData As New JSONItem
FormData.Value("api_key") = "65oh666xxx"
FormData.Value("sender_name") = "Beatrix Willius from Moth Software"
FormData.Value("sender_email") = ""
FormData.Value("subject") = "test subject"
FormData.Value("body") = "<html><body>test body</body></html>"
FormData.Value("list_id") = "1"

theSocket.SetRequestContent(FormData.ToString, "application/json")
dim theResult as String = theSocket.SendSync("POST", "")

dim ResultDictionary as Dictionary = ParseJSON(theResult)
if ResultDictionary.HasKey("error") then
  MessageBox("There was an error when trying to create an email: " + EndOfLine + EndOfLine + ResultDictionary.Value("error"))
end if

What am I doing wrong?

What I think the documentation is suggesting for POST is to send form data. You can do this with the free open source class from Einhugur

Let us know if you get stuck or it doesn’t work.

Edit: Here’s all I could find about GET / POST and format

1 Like

Thanks, I’ll try that.

Selzy’s API is a bit strange, it looks like everything related to the email should be included in the URL parameters. Other APIs use POST data.

Selzy is expecting everything in the URL parameters, just like you did in Postman. &email
=TONAME <EMAILTO>&sender_name=

Are you sure the server is expecting a json?

Why not send it all the params in the URL like with Postman?

The “format” param you send in Postman is to tell the server the format of the response you are epecting.

Also, it looks like Selzy is for sending email campaigns, as in sending one or more emails to a group of people.
Is that really what you need @Beatrix_Willius ?

If you are looking for transactional emails (as in sending a different email to each person) it looks like you will need to use which is owned or a partner of Selzy.

@Jeremie_L : Selzy also allows POST data which is I’m trying to get working. GET works fine. I’m trying to send bulk emails to a list. I want to get rid of MailChimp where I still use RSS to email.

@Ivan_Tellez : No, I’m not sure if this is needed here.

@Tim_Parnell : I get the same result as before:

Dim FormData as MultipartFormDataContent = new MultipartFormDataContent()
FormData.Add("api_key", "65oh666cxxx")
FormData.Add("sender_name", "Beatrix Willius from Moth Software")
FormData.Add("sender_email", "")
FormData.Add("subject", "test subject")
FormData.Add("body", "<html><body>test body</body></html>")
FormData.Add("list_id", "1")
FormData.Add("format", "json")

Dim result as String = theSocket.SendSync("POST", "")

Do you have a link to the documentation that talks about POST? I couldn’t find it, but reading it might help understand the exact format.

See my post above, it’s all I could find about the optional POST method.

Can you show the raw request Postman sends? I know Paw/RapidAPI can show that, it would be helpful and could illustrate the difference in requests. You’re welcome to send it privately if necessary.

All parameters should be encoded in UTF-8. In the example above the parameters are given in the GET request, but you can send them through POST as well. Moreover, we strongly recommend that you send the api_key parameter through POST to ensure it’s not saved in proxy servers logs.

Here is the raw command from Postman:


I don’t think that this is form data.

Yea if it was Formdata then your parameters in your Postman would be in the body section like this:

So, yes it is not formdata. And More like just parameters, like Jeremie was hinting I think.

1 Like

You are correct, that looks like GET parameters to me…

Ah, I don’t use Postman so I wasn’t sure where those items ended up. I use Paw / RapidAPI :person_shrugging:

1 Like

From their docs:

The list of parameters for the method called is transferred in params . Parameters can be transferred either via a GET request or via POST. You are strongly recommended to use only POST requests, since the data transferred in them is not stored in logs of the servers engaged in the connection. This increases the security of your work through API.

So you could use “x-www-form_urlencoded” (or even “mutlipart/form-data”)

Something like:

var params As string = "param1=value1&param2=value2&param3=value3"
// you may be required to EncodeURLComponent all of the values.

mySocket.SetRequestContent(params, "x-www-form_urlencoded")
mySocket.Send("POST", "")
1 Like

Thanks for your help, guys.