Home > Net >  How to do a curl command with multiple "-d" elements with writing on one line
How to do a curl command with multiple "-d" elements with writing on one line

Time:11-27

I am trying to execute a curl command with multiple -d parameters (if that is even possible). Below is the command:

curl -X POST "localhost:8090/rest/myResource/myEndpoint?user=user01" \
 -d 'agg={
    "comm": {
        "date_histogram": {
            "field": "DERIVED_UNIFIED_TIMESTAMP",
            "calendar_interval": "month"
        }
    }
   }&
    q={
    "bool": {
        "must": [
            {
                "terms": {
                    "COMM_TYPE": [
                        "call",
                        "email",
                        "message"
                    ]
                }
            }
        ]
    }
}'

With the above format, the endpoint correctly sees the "agg" param but the "q" is empty.

If I collapse the -d to a single line it works. However, I don't want to have to do that because the user calling should be able to do it across lines. I would be grateful for any ideas. thanks

curl -X POST "localhost:8090/rest/myResource/myEndpoint?user=user01" \
 -d 'agg={"comm": {"date_histogram": {"field": "DERIVED_UNIFIED_TIMESTAMP","calendar_interval": "month"}}}&q={   "bool": { "must": [{"terms": {"COMM_TYPE": [                       "call","email", "message"] } }]}'

CodePudding user response:

removing the line feed and spaces before the "&q" (see below) was sufficient to get CURL to work properly.

curl -X POST "localhost:8090/rest/myResource/myEndpoint?user=user01" \
 -d 'agg={
    "comm": {
        "date_histogram": {
            "field": "DERIVED_UNIFIED_TIMESTAMP",
            "calendar_interval": "month"
        }
    }
   }&q={
    "bool": {
        "must": [
            {
                "terms": {
                    "COMM_TYPE": [
                        "call",
                        "email",
                        "message"
                    ]
                }
            }
        ]
    }
}'
  •  Tags:  
  • curl
  • Related