Announcement

Collapse
No announcement yet.

Using CURL Windows to post json

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using CURL Windows to post json

    I'm trying to execute the following in a Windows Batch file

    Code:
    curl.exe -X POST "https://api.inxpress.com/imcs_gateway/c_1/" -H "Content-Type: application/json" -D^
    {^
       "request_id":"pm77",^
       "request_time":"2020-12-24",^
       "account":"accountname",^
       "password":"apikey",^
       "gateway":"UK",^
       "carrierCode":"C_1",^
       "origin":{^
          "city":"ROCHDALE",^
          "postal_code":"OL16 5DB",^
          "country":"GB"^
       },^
       "destination":{^
          "city":"Bellville",^
          "postal_code":"7530",^
          "country":"ZA"^
       },^
       "product_code":"P",^
       "content_type":"WPX",^
       "weight_unit":"kg",^
       "dimension_unit":"cm",^
       "currency":"GBP",^
       "insured_value":"3.00",^
       "dutiable":true,^
       "commercial_value":"5.00",^
       "pieces":[^
          {^
             "name":"Piece 1",^
             "weight":5.0,^
             "height":8.0,^
             "depth":12.0,^
             "width":12.0,^
             "quantity":1,^
             "custom_value":10.0^
          }^
       ]^
    }
    This is the response

    Code:
    curl: (6) Could not resolve host: request_id
    curl: (6) Could not resolve host: request_time
    curl: (6) Could not resolve host: account
    curl: (6) Could not resolve host: password
    curl: (6) Could not resolve host: gateway
    curl: (6) Could not resolve host: carrierCode
    curl: (3) [globbing] unmatched brace in column 8
    curl: (6) Could not resolve host: city
    curl: (6) Could not resolve host: postal_code
    curl: (6) Could not resolve host: country
    curl: (3) [globbing] unmatched close brace/bracket in column 1
    curl: (3) [globbing] unmatched brace in column 13
    curl: (6) Could not resolve host: city
    curl: (6) Could not resolve host: postal_code
    curl: (6) Could not resolve host: country
    curl: (3) [globbing] unmatched close brace/bracket in column 1
    curl: (6) Could not resolve host: product_code
    curl: (6) Could not resolve host: content_type
    curl: (6) Could not resolve host: weight_unit
    curl: (6) Could not resolve host: dimension_unit
    curl: (6) Could not resolve host: currency
    curl: (6) Could not resolve host: insured_value
    curl: (6) Could not resolve host: dutiable
    curl: (6) Could not resolve host: commercial_value
    curl: (3) [globbing] bad range specification in column 9
    curl: (3) [globbing] unmatched brace in column 1
    curl: (6) Could not resolve host: name
    curl: (6) Could not resolve host: weight
    curl: (6) Could not resolve host: height
    curl: (6) Could not resolve host: depth
    curl: (6) Could not resolve host: width
    curl: (6) Could not resolve host: quantity
    curl: (6) Could not resolve host: custom_value
    curl: (3) [globbing] unmatched close brace/bracket in column 1
    curl: (3) [globbing] unmatched close brace/bracket in column 1
    So I have something wrong with the way I'm formatting the data.

    Any help very much appreciated

  • #2
    did you try putting quotes around the json data. Before first brace { and last brace }

    Comment


    • #3
      Originally posted by Steve Bouffe View Post
      I'm trying to execute the following in a Windows Batch file
      What's with all the "^"s ?

      They are batch file continuation line markers, but I suspect they are messing up what is actually being passed to CURL.


      Comment


      • #4
        I did find a solution by putting the json data in a file and then calling like this

        Code:
        curl.exe -X POST "https://api.inxpress.com/imcs_gateway/dhlparceldom" -H "Content-Type: application/json" -d @test-data.txt

        Comment

        Working...
        X