2
Changing Domain's Outgoing IP
Question asked by John C. Reid - 3/22/2022 at 11:02 AM
Answered
Working on a solution to change a domain's outgoing IP programmatically through the SM API. We occasionally have a situation where one of the domains get's the IP on a RBL and we need to move a large number of domains to a new IP. Using the API documentation, but getting a super helpful response/error from SM: {"message":"An error has occurred."}"
Can anyone shine some light? Possibly see what I am missing in the code?
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://domain.com/api/v1/settings/sysadmin/domain-settings/'.$oneDomain);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$headers = array(
	"Accept: application/json",
	"Authorization:Bearer ".$SM_accessToken,
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$payload = json_encode(array('domainSettings' => array('outgoingIP' => $newIP)));

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$payload);

$response = curl_exec($ch);
curl_close($ch);

echo $response;

6 Replies

Reply to Thread
0
Tony Scholz Replied
Employee Post
Hello John. 

The two things to make sure of here are that you are authenticating as a system admin and have the full body correct. 

$payload='{"domainSettings":{"outgoingIP":"10.1.10.207"}}'; 
I am not sure but your payload may be off. 

curl 'http://sup-ascholz.st.local/api/v1/settings/sysadmin/domain-settings/ascholz.local/'; \
  -H 'Accept: application/json, text/plain, */*' \
  -H 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsIQZ......mSAAEN-0d2JPr20bRvSbKMMzQEYlDgSA' \
  -H 'Content-Type: application/json;charset=UTF-8' \
  -H 'Accept-Language: en-US,en;q=0.9' \
  --data-raw '{"domainSettings":{"outgoingIP":"10.1.10.207"}}'
or PowerShell


are you running this in PHP?

Thank you 
Tony
Tony Scholz System/Network Administrator SmarterTools Inc. www.smartertools.com
0
John C. Reid Replied
Yes, PHP.
Yes, auth'ing as a System Admin.
My payload value is: 

{"domainSettings":{"outgoingIP":"111.222.333.444"}}
0
John C. Reid Replied
It worked! I added all the curl options that you had (never needed this many before, but then again this is the first time I am setting versus just retrieiving data):
$headers = array(
	"Accept: application/json, text/plain, */*",
	"Authorization:Bearer ".$SM_accessToken,
	"Content-type: application/json;charset=UTF-8",
	"Accept-Language: en-US,en;q=0.9",
);
0
Tony Scholz Replied
Employee Post Marked As Answer
Hello John, 

You will want to add another header, Content-Type. 

'Content-Type: application/json',


Let me know if this resolves your issue. 

Thank you
Tony
Tony Scholz System/Network Administrator SmarterTools Inc. www.smartertools.com
0
Sabatino Replied
Sorry, not figured out why not do it at the server level

In setting / protocols / smtp out

if you change it there, it changes for all domains
Sabatino Traini Chief Information Officer Genial s.r.l. Martinsicuro - Italy
0
John C. Reid Replied
Sabatino, We have over 300 domains on the server and we spread them across 4-5 outgoing IPs to help with situations where one domain gets blacklisted. So I don't need to move ALL domains, just a portion at a time.

Reply to Thread