curl / Mailing Lists / curl-users / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Re: {"code":"INVALID_RECORDS", "fields":[{"code":"INVALID_RECORDS", "message":"Invalid [name] provided for record data

From: Timothe Litt <litt_at_acm.org>
Date: Wed, 26 Oct 2022 06:14:09 -0400

On 26-Oct-22 04:56, Kaushal Shriyan via curl-users wrote:
> Hi,
>
> I have the below bash shell script
>
> #!/bin/bash
>
> echo "Please enter the domain name to be added"
> read domainname
>
> echo "Fully qualified domain name to be added is
> ${domainname}.mydomain.com <http://mydomain.com>"
>
> echo "Please enter the IP Address to be added"
> read ipaddress
>
> curl -X PATCH https://api.godaddy.com/v1/domains/mydomain.com/records \
>   -H "Authorization: sso-key xxxxxxxxxxxxxxxxxxxxxxxx:xxxxxxxxxxxxx" \
>   -H 'Content-Type: application/json' \
>   --data '[{"type": "A","name": "$domainname","data":
> "$ipaddress","ttl": 600}]'
>
> {"code":"INVALID_RECORDS","fields":[{"code":"INVALID_RECORDS","message":"Invalid
> [name] provided for record data,
> [$domainname].","path":"records"}],"message":"One or more of the given
> records is invalid","errors":["Invalid [name] provided for record
> data, [$domainname]."]}
>
> I am encountering INVALID_RECORDS as per the above output. Please
> guide me. Thanks in advance.
>
> Best Regards,
>
> Kaushal


The answer is in the error message.  "$domainname" is an invalid [name]
in the data.  This is a shell usage issue.

The argument to --data is delimited by single quotes, which inhibits
variable expansion.

If you want to do it this way, use double quotes - you will then need to
backslash-escape the quotes in the JSON.

e.g. --data "[{\" ...}]"

Alternatively, use --data _at_filename; you can create the file many ways -
a here-is document can do expansion and minimize the quotes.  e.g.
-|-data _at_- <<EOF|

|[{"type": "A","name": "$domainname","data": "$ipaddress","ttl": 600}]|

|EOF|

Timothe Litt
ACM Distinguished Engineer
--------------------------
This communication may not represent the ACM or my employer's views,
if any, on the matters discussed.


-- 
Unsubscribe: https://lists.haxx.se/listinfo/curl-users
Etiquette:   https://curl.se/mail/etiquette.html
Received on 2022-10-26