Home > Blockchain >  how to feed variable or json file to curl
how to feed variable or json file to curl

Time:04-09

I have seen many variants already on the forum but none worked for me, can anyone enlighten me with the correct curl -d syntax for the command to work ( properly get the data from $variable_json) ? Putting directly the text from varible into curl works without problem, but with variable it gives error. This variable is composed dynamically on the below pattern and must be able to call curl -d either by variable or json file.

$variable_json = '{\"customDomains\":[\"internal.test10.com\",\"external.test10.com\"],\"aadInfo\":{\"loginUrl\":\"https://developer.microsoft.com/en-us/graph/graph-explorer\"},\"name\":\"App-Test10\",\"category\":\"SAASDB_CATEGORY_COLLABORATION\",\"hostingPlatform\":2,\"score\":5,\"note\":\"This app was added by myself through API\",\"suffixSupport\":true,\"domains\":[],\"ipv4\":[],\"ipv6\":[],\"isCustomApp\":true}'

< $variable_json has already been enclosed and escaped with ' and " as for the variable above to be the final output needed >

curl -L -X POST 'https://company_domain.portal.cloudappsecurity.com/api/v1/discovery/app_catalog/create_custom_app/' -H "Authorization: Bearer $Token" -H 'Content-Type: application/json' -d "$variable_json"

or

curl -L -X POST 'https://company_domain.portal.cloudappsecurity.com/api/v1/discovery/app_catalog/create_custom_app/' -H "Authorization: Bearer $Token" -H 'Content-Type: application/json' -d '@C:\Users\Administrator\Desktop\the_file.json'

The answer can be for unix or powershell, any variant is fine.

Thank you

Edit:

The error received is:

{"name":[{"error":"This field is required","errorMessageCode":"CONSOLE_FORMS_FIELD_REQUIRED"}],"category":[{"error":"This field is required","errorMessageCode":"CONSOLE_FORMS_FIELD_REQUIRED"}],"customDomains":[{"error":"This field is required","errorMessageCode":"CONSOLE_FORMS_FIELD_REQUIRED"}],"note":[{"error":"This field is required","errorMessageCode":"CONSOLE_FORMS_FIELD_REQUIRED"}],"hostingPlatform":[{"error":"This field is required","errorMessageCode":"CONSOLE_FORMS_FIELD_REQUIRED"}],"score":[{"error":"This field is required","errorMessageCode":"CONSOLE_FORMS_FIELD_REQUIRED"}],"error":true}

Which is weird, because if I put the data from the json file by hand, it works without issues. My whole problem is that the command just wont parse properly the variable/file.json for the "-d pamater"

CodePudding user response:

I just abandonated the issue and put microsoft Lv3 to do it.

They are using cmdlets iwth some @[Ordered] json body....crap i've never seen

  • Related