Creating and Updating SRV in API using Powershell


#1

Hi,

So I’ve been working on getting the CloudFlare API to work using Powershell and I’ve hit recently a bit of a snag.
About a month ago I was able to create and Update SRV records with no issue, but now it doesn’t work anymore and I can’t see why this isn’t working anymore.
(Periods in the body has been removed due to limited links allowed)

$Body = @{
type = “SRV”
data = @{
service = “_test”
proto = “_tcp”
name = “test com”
weight = “100”
port = “5060”
target = “test test com”
priority = “10”
}
}

Running the body through a conversion to JSON and it comes out like this, which should be fine, and has been until recently:

{
“type”: “SRV”,
“data”: {
“service”: “_test”,
“proto”: “_tcp”,
“name”: “test com”,
“weight”: “100”,
“port”: “5060”,
“target”: “test test com”,
“priority”: “10”
}
}

Running this through: Invoke-RestMethod -Method Post -Uri “https://api.cloudflare.com/client/v4/zones/zone_id/dns_records” -Headers $Header -Body ($Body | ConvertTo-JSON) -ContentType “Application/JSON”

Im getting an error of the type 400 Bad Request

I want to mention that this is working fine for other records although the body on those are a bit different.
Anyone got any idea where I’m going wrong?


#2

I’ve also tried using curl through linux bash, but that doesn’t work either, although it’s been a while since I’ve used this so I might have forgotten how to do this properly.

curl -X POST “https://api.cloudflare.com/client/v4/zones/zone_id/dns_records
-H “X-Auth-Key: xxxxxxxxxxxxxxxxxxx”
-H “X-Auth-Email: [email protected]
-H “Content-Type: application/json”
–data ‘{“type”:“SRV”,“service”:"_test2",“proto”:"_tcp",“name”:“test.work”,“priority”:“10”,“weight”:“100”,“port”:“5061”,“target”:“test2.test.work”,}’

{“success”:false,“errors”:[{“code”:6007,“message”:“Malformed JSON in request body”}],“messages”:[],“result”:null}


#3

Try a payload that looks like this?

curl -X POST "https://api.cloudflare.com/client/v4/zones/"$zone_id"/dns_records" \ -H "X-Auth-Email: "$auth_mail \ -H "X-Auth-Key: "$auth_key \ -H "Content-Type: application/json" \ --data '{"zone_name":"example.com","zone_id":"'$zone_id'","type":"SRV","name":"_whatyouwant._tcp.example.com.","content":"SRV 0 0 8080 foo.example.com.","data":{"priority":0,"weight":0,"port":8080,"target":"foo.example.com","service":"_whatyouwant","proto":"_tcp","name":"example.com"},"proxied":false,"proxiable":false,"ttl":300,"priority":1}'


#4

Hi,

Was able to get this solved with help from support.
For the problem in PS, The payload contained priority, port and weight as strings, that caused the problem.

Same problem for curl, and that there should’ve been a second array containing everything, but type.

–data ‘{“type”:“SRV”,“data”:{“service”:"_test",“proto”:"_tcp",“name”:“test.work”,“priority”:10,“weight”:100,“port”:5061,“target”:“test2.test.work”}}’