Implementing a stand-alone curl command

Tags: #<Tag:0x00007ff5d1c61398>


We’d really prefer to use json api access but we have SOAP open for our account.

I was wondering if someone can answer if a simple command line curl.exe can implement the calls to the phplist.
And we need only the call for adding a user, a single email address added to the list.
Not a cron job, not a php script, but a version of the curl.exe call from inside them.
That we will construct and automate from our (vfp) code later on.
I went through many threads on the forum but didn’t see anything like that.

From windows/dos prompt.

Thanks in advance!
Sime Atanasov

PS what’s up with the rule “New users can only put 2 links in a post”? Couldn’t even put one sample of the curl command I’ve tried.

Were you using the code toolbar button </> ?


Thanks for the quick reply!

No, I didn’t use the code toolbar button </> . Should I?

Btw, what helped me was this excerpt from your post on the old forum. With curl and emails.csv. That I can’t post because of that limitation. Not even one curl command, where it finds a link?

It didn’t not error out but didn’t add the email address I have in the emails.csv.
Replaced list[0]=7 with list[0]=1 (as I have one list of subscribers only) but no difference.
Am I constructing the list id correctly?

Thanks again!

curl -v -F login=admin -F password=xxx -F import_file=@emails.csv -F lists[0]=7 -F notify=no -F htmlemail=1 -F import=import http://xxxx/lists/admin/?page=import1 .

And I was using:

c:\curl> curl -v -F -F password=‘xxxxx’ -F “importcontent=emailaddress” -F “listname[0]=‘sa’” -F “importlists[1]=1” -F “checkvalidity=1” ‘’ -o c:\temp\curlout.html

with no results

Sorry for the parsed messages. I think I’ve found what it didn’t like as more than two links for new forum users. It was the @ sign, so I was able to post the command when I replaced the real email address to be added with [emailaddress].
In case someone else comes up with this issue about posting on the forum.

I meant, what didn’t work was this syntax:

curl -v -F -F password=‘xxxxxxxxx’ -F “importcontent=<email.csv” -F “importlists[0]=1” -F “checkvalidity=1” -F “doimport=Import emails” ‘’ -o c:\temp\curlout.html

And what worked was the previous excerpt from your post on the old forum. Less single and double quotes involved. I guess it depends on the phplist and curl versions.

A quick update: After message 301, changing http to https and dealing with the curl-ca-bundle.crt SSL certificate file, I got the communication going on, and a message about invalid token, when trying to add an email address via curl.
Could not get … --cookie-jar cookie.txt … import1.log working.
And, the Windows CMD doesn’t like
TK=$(grep -o ‘tk=[[:alnum:]]*’ c:\temp\import1.log | head -1)
Anyone knows how do I get and implement the token in order to issue another command to add an user? Not from a php code, or perl, just pure curl.exe from windows/dos command line.

A quick update: somehow got it working without any php script, right from windows/dos command prompt curl. I can see the email address on the list of unconfirmed subscribers now.
The two new issues I have are:

  1. even after putting different combinations of lists[0]=1 , it doesn’t select any of the four lists we have. I’m not sure about the right syntax - the option in the page source of the webpage form signing (which works) vs the curl command option.
  2. and this might be related to 1), since I haven’t chosen any list: Can’t get the -F makeconfirmed=0 working. No confirmation email, which is critical. makeconfirmed=1 (instant confirmation) didn’t make any difference either.
    Any ideas? Thanks again!

The index and value should both be the list id, e.g. for list id 3


Duncan, thanks a bunch! It worked. I don’t know why I got stuck at (what I’ve noticed in other threads and the “View Page source” of the form signup web page) lists[0]=1, lists[0]=5, listname=newsletter etc. Fishing in the mud. Probably because I wasn’t sure after the right syntax and was guessing a lot. I thought importlists would be more for importing a csv of email addresses, not a single email address subscriber, which I need in my case.
Now, the bigger problem stays - I can’t get to receive the welcome/confirmation email, as I do when I test with the webform. Any idea why
-F makeconfirmed=0
or even
-F makeconfirmed=1
is not working for me?
I put it on par with -F htmlemail=1 curl option. Which might not be doing anything either :slight_smile:

@SimeAtanasov You started trying to use curl to import subscribers, but now you seem to be talking about the subscribe form. The subscribe form does not have a field to make the person confirmed. phplist will always set a new subscriber to unconfirmed.

Sorry, I didn’t explain that well. Yes, I’m trying to subscribe an user email with a curl command, and it works. The new subscriber shows up, and with the importlists[n]=n gets in the right list now. I can see that subscriber to the hosted phplist portal.
The final step of that is to include an option in the curl command to send the welcome/confirmation email to that email address.
I went to the subscribe form (its Page source) just “to borrow” the field and value for that: makeconfirmed=0 . To no avail though.

You are probably looking at the subscribe page when already logged-in as an admin. In that case phplist provides that option to make confirmed immediately, which is not an option on the public subscribe page. You should view the subscribe page as an anonymous user, say in a private window or logout from phplist.

phplist will usually send the confirmation request email but there are some cases when it does not. If it thinks it has sent the request already in the same php session then it won’t send again. That is to avoid accidental repeat subscriptions leading to multiple emails.

You should ensure that each curl request is a new session, or at least use a different email address each time.

Thanks Duncan! I’ll try that.

On the session topic, how do I request a new session or clear up the preview one(s)?
I was unable to get a session token with the curl.exe alone. Had the file cookie.txt created with “–cookie-jar cookie.txt” addition but did not get a token.
Fortunately (or not), the new subscription worked w/o the session token/key, maybe because, as you said, I supplied the admin credentials to the curl command. Also, --insecure helped me pass the crt not executing the curl. Not ideal.

@SimeAtanasov You need to show the command that you are using, otherwise it is just guessing. Please use the code button </> to make it more readable.

The command that works for me is:

curl -v --insecure -F -F password=xxxxxxxxxxx -F -F importlists[2]=2 -F notify=no -F makeconfirmed=0 -F htmlemail=1 -F import=import

Everything works but sending the confirmation/welcome email. Subscriber’s email added to the right list.

It doesn’t get instantly confirmed either, like with makeconfirmed=1 .

Next, I was going to try adding a variation of
to . I’m not sure how, page will have two values…

Thanks again!

    as a contribution to the discuss forum: I just noticed the last message came to me by email too, notified. Not the previous 14-15. Maybe that doesn't happen for new users, in case they're spamming? I don't know. Also, I can edit only the last of my messages on the thread. Not a big deal again. Win7, opera.

@SimeAtanasov You are now referring to the import simple page not the subscribe page which I thought your last reply indicated.

The import pages do not send a confirmation email.