Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Linux Commands»How To POST JSON data with Curl Command Line

    How To POST JSON data with Curl Command Line

    RahulBy RahulJuly 6, 20171 Min ReadUpdated:March 28, 2019

    Question- How to POST JSON data with curl? How to POST JSON data with curl command line? How do I POST JSON data on Linux terminal?

    You can add -H "Content-Type: application/json" header value to Post the JSON data to curl command line.

    For example, I have an API URL https://api.example.com/v2/login, that is used to authenticate the application. Now passing the username and password in JSON format using the curl command line tool.

    curl -X POST -H "Content-Type: application/json" \
     -d '{"username":"abc","password":"abc"}' \
     https://api.example.com/v2/login
    

    You can also write the username and password in a user.json file. Now use this file to pass the JSON data to curl command line.

    curl -X POST -H "Content-Type: application/json" \
     -d @user.json \
     https://api.example.com/v2/login
    
    curl json POST
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleTasksel – A Group Package Installation Tool for Debian
    Next Article How to Enable URL Rewrite in IIS

    Related Posts

    How to Search Recently Modified Files in Linux

    2 Mins Read

    Bash Printf Command

    Updated:December 23, 20212 Mins Read

    Tee Command in Linux with Examples

    4 Mins Read

    How to Scan Open Ports with Nmap

    5 Mins Read

    Handling filenames with spaces in Linux

    3 Mins Read

    How To Compare Two Files in Linux

    Updated:August 23, 20215 Mins Read

    5 Comments

    1. Albert on January 22, 2021 11:02 pm

      how to use “Authentication: XXX”?

      I have a case as bellows:
      curl -u admin:admin123 -X POST -H ‘Content-Type: application/json’ -d “@a.json” “http://abc.net:7180/api/v33/clusters/CDH_5.14/services/hdfs/snapshots/policies/hdfs_snapshot_p3”

      But got 405 error. how to fix it? # grep hdfs_snapshot_p3 cloudera-scm-server.log
      2021-01-22 16:44:50,176 INFO scm-web-1371570:com.cloudera.enterprise.JavaMelodyFacade: Entering HTTP Operation: Method:POST, Path:/v33/clusters/CDH_5.14/services/hdfs/snapshots/policies/hdfs_snapshot_p3
      2021-01-22 16:44:50,183 INFO scm-web-1371570:com.cloudera.enterprise.JavaMelodyFacade: Exiting HTTP Operation: Method:POST, Path:/v33/clusters/CDH_5.14/services/hdfs/snapshots/policies/hdfs_snapshot_p3, Status:405
      I google online, some webpage said not to Allow POST. do not know how to do that. Can anyone help?

      Reply
    2. Kim on May 27, 2020 9:26 am

      Thank you. I’ve been looking for a solution to loading a JSON file into a curl command for days – this has fixed it.
      Thank you again!

      Reply
    3. Vikramsinh Jadhav on October 30, 2018 6:14 pm

      this is very helpful. thanks a lot !!

      Reply
    4. VIJAY on April 20, 2018 2:33 am

      Hi Rahul,

      Thanks for this valuable information.

      I need to send the mail to the testers with the Jenkins URL using my notification API. I am using the same method you mentioned above, Can you tell me how to invoke the URL in JSON data in dynamic way, since the uri will change for each build.

      CURL COMAND:
      ==============
      curl -d “@request.json” -H “Content-Type: application/json” -H “Authentication: XXX” -X POST https://<notification API URL/notifications/quick-send

      JSON FILE
      ==========
      {
      "templateId": "",
      "recipientPhoneNumber": "",
      "recipientEmail": "[email protected]",
      "recipientChannelId": "",
      "recipientDeviceType": "",
      "subject": "JENKINS BDD TEST",
      "message": "HELLO JENKINS",
      "substitutionData": {},
      "inAppMessage": "",
      "inAppSubstitutionData": {},
      "extras": {},
      "scheduled": "2018-1-28T23:38:21.701Z",
      "archiveAfter": "2018-01-28T23:38:21.701Z",
      "emailReplyTo": ""
      }

      URL of Jenkins:
      ———————
      https://jenkins.eastus.cloudapp.azure.com/view/all/job/PojectName/1/cucumber-html-reports/overview-features.html

      Reply
    5. su on February 15, 2018 12:08 pm

      Hello,

      Thanks for update ideas.

      Reply

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Enable / disable Firewall in Windows
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    • How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.