Can't load some ontologies from URL via GraphDB API - sparql

I can load the MonDO ontology into GraphDB Free 9 with the /rest/data/import/upload/{repositoryID}/url method with this body:
{
"context": "http://purl.obolibrary.org/obo/mondo.owl",
"data": "https://github.com/monarch-initiative/mondo/releases/download/current/mondo.owl",
"format": "RDF/XML"
}
I can also load this via the Workbench, but not programatically:
http://data.bioontology.org/ontologies/ICD9CM/submissions/17/download?apikey=8b5b7825-538d-40e0-9e9e-5ab9274a9aeb
I set the format line to "Turtle" and I'm getting 202 responses, but the workbench doesn't show any import. It seems like some of the time I see error messages on the workbench's import page, but I don't understand what corrective action to take.
For example, if I intentionally import ICD9 via the workbench, with the wrong format (RDF/XML), then I see
RDF Parse Error: Content is not allowed in prolog. [line 2, column 1]

curl 'http://localhost:7200/rest/data/import/upload/w2/url' -H 'Content-Type: application/json;charset=UTF-8' -H 'Accept: application/json, text/plain, */*' --data-binary '{"type":"url","name":"http://data.bioontology.org/ontologies/ICD9CM/submissions/17/download?apikey=8b5b7825-538d-40e0-9e9e-5ab9274a9aeb","format":"text/turtle","data":"http://data.bioontology.org/ontologies/ICD9CM/submissions/17/download?apikey=8b5b7825-538d-40e0-9e9e-5ab9274a9aeb","status":"NONE","message":"","context":"","replaceGraphs":[],"baseURI":null,"forceSerial":false,"timestamp":1534939094325,"parserSettings":{"preserveBNodeIds":false,"failOnUnknownDataTypes":false,"verifyDataTypeValues":false,"normalizeDataTypeValues":false,"failOnUnknownLanguageTags":false,"verifyLanguageTags":true,"normalizeLanguageTags":false,"verifyURISyntax":true,"verifyRelativeURIs":true,"stopOnError":true}}
GraphDB handles api key but you should provide file format in the way up or "format":"text/turtle". Hope this helps.

Thanks to Sava from Ontotext, I was able to construct this minimal curl command that successfully loads the ICD9CM Turtle file from the NCBO BioPortal.
curl -d \
'{"type":"url","format":"text/turtle","data":"http://data.bioontology.org/ontologies/ICD9CM/submissions/17/download?apikey=8b5b7825-538d-40e0-9e9e-5ab9274a9aeb","context":"http://data.bioontology.org/ontologies/ICD9CM/"}' \
-H 'Content-Type: application/json;charset=UTF-8' \
-X POST http://localhost:7200/rest/data/import/upload/disease_diagnosis_dev/url
I left out many of the keys, including the timestamp and all of the parserSettings.
I used the - d ... -X POST curl style instead of the --data-binary style
I don't claim to know all of the consequences of those decisions.
Here's my approach in R
library(httr)
post.endpoint <- "http://localhost:7200//rest/data/import/upload/disease_diagnosis_dev/url"
update.body <- '{
"type":"url",
"format":"text/turtle",
"context": "http://purl.bioontology.org/ontology/ICD9CM/",
"data": "http://data.bioontology.org/ontologies/ICD9CM/submissions/17/download?apikey=9cf735c3-a44a-404f-8b2f-c49d48b2b8b2"
}'
post.result <- POST(post.endpoint,
body = update.body,
content_type("application/json"))

curl 'http://localhost:7200/rest/data/import/upload/abc/url' -H 'Content-Type: application/json;charset=UTF-8' -H 'Accept: application/json, text/plain, */*' --data-binary '{"type":"url","name":"http://www.w3.org/TR/owl-guide/wine.rdf","format":"","data":"http://www.w3.org/TR/owl-guide/wine.rdf","status":"NONE","message":"","context":"","replaceGraphs":[],"baseURI":null,"forceSerial":false,"timestamp":1534939094325,"parserSettings":{"preserveBNodeIds":false,"failOnUnknownDataTypes":false,"verifyDataTypeValues":false,"normalizeDataTypeValues":false,"failOnUnknownLanguageTags":false,"verifyLanguageTags":true,"normalizeLanguageTags":false,"verifyURISyntax":true,"verifyRelativeURIs":true,"stopOnError":true}}'
where,
abc - is the repository id
http://www.w3.org/TR/owl-guide/wine.rdf - is the URL to import
1534939094325 - the current timestamp in seconds since epoch (in bash, equivalent to date +%s)
If you want to perform regular updates I advise you to put each file in its own graph (using the "context":"<file's url>") and then replace it with "replaceGraphs":"<file's url>". The database will create a delta and update only the changed statements.

Related

How can I create new TeamCity users through the API?

I want to create TeamCity users with various roles through the API. As long as I provide no role, I know how to do it, like so:
curl -X POST http://localhost:8111/app/rest/users \
-H "Content-Type: application/json" \
-d '{"username":"user", "password":"password"}' \
-u :<super-user-token>
Now, my issue is that e.g. I want to create an administrator. I tried this:
curl -X POST http://localhost:8111/app/rest/users \
-H "Content-Type: application/json" \
-d '{"username":"user", "password":"password", "roles": {"role": [{"roleId": "PROJECT_ADMIN"}]}}' \
-u :<super-user-token>
The roleId is a value that comes from the roles-config.xml file in folder <TeamCity Data Directory>/config, should be fine. I get the following error:
Responding with error, status code: 400 (Bad Request).
Details: jetbrains.buildServer.server.rest.errors.PartialUpdateError: Partial error updating user 'zadigus' {id=3}, nested errors: jetbrains.buildServer.server.rest.errors.PartialUpdat
eError: Partial error updating roles for user 'zadigus' {id=3}, nested errors: java.lang.IllegalArgumentException: Argument for #NotNull parameter 'scopeData' of jetbrains/buildServer/
server/rest/model/user/RoleAssignment.getScope must not be null
There was an error processing the request, but the data could be updated partially. Please ensure consistent data state.
because I provide no scope. I was not able to find any information about what values I can feed the scope field with. Where are they documented?
I am using TeamCity version 2022.04.4.
I found it. In order to get the possible values for the scope field, just run
curl -X POST http://localhost:8111/app/rest/users \
-H "Content-Type: application/json" \
-d '{"username":"user", "password":"password", "roles": {"role": [{"roleId": "PROJECT_ADMIN", "scope": "invalid-value"}]}}' \
-u :<super-user-token>
In the reply to this request, we get the information that possible values are either g or p:<projectId>.

How do I send a POST request via the command line in Windows [duplicate]

I use Ubuntu and installed cURL on it. I want to test my Spring REST application with cURL. I wrote my POST code at the Java side. However, I want to test it with cURL. I am trying to post a JSON data. Example data is like this:
{"value":"30","type":"Tip 3","targetModule":"Target 3","configurationGroup":null,"name":"Configuration Deneme 3","description":null,"identity":"Configuration Deneme 3","version":0,"systemId":3,"active":true}
I use this command:
curl -i \
-H "Accept: application/json" \
-H "X-HTTP-Method-Override: PUT" \
-X POST -d "value":"30","type":"Tip 3","targetModule":"Target 3","configurationGroup":null,"name":"Configuration Deneme 3","description":null,"identity":"Configuration Deneme 3","version":0,"systemId":3,"active":true \
http://localhost:8080/xx/xxx/xxxx
It returns this error:
HTTP/1.1 415 Unsupported Media Type
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=utf-8
Content-Length: 1051
Date: Wed, 24 Aug 2011 08:50:17 GMT
The error description is this:
The server refused this request because the request entity is in a format not supported by the requested resource for the requested method ().
Tomcat log:
"POST /ui/webapp/conf/clear HTTP/1.1" 415 1051
What is the right format of the cURL command?
This is my Java side PUT code (I have tested GET and DELETE and they work):
#RequestMapping(method = RequestMethod.PUT)
public Configuration updateConfiguration(HttpServletResponse response, #RequestBody Configuration configuration) { //consider #Valid tag
configuration.setName("PUT worked");
//todo If error occurs response.sendError(HttpServletResponse.SC_NOT_FOUND);
return configuration;
}
You need to set your content-type to application/json. But -d (or --data) sends the Content-Type application/x-www-form-urlencoded, which is not accepted on Spring's side.
Looking at the curl man page, I think you can use -H (or --header):
-H "Content-Type: application/json"
Full example:
curl --header "Content-Type: application/json" \
--request POST \
--data '{"username":"xyz","password":"xyz"}' \
http://localhost:3000/api/login
(-H is short for --header, -d for --data)
Note that -request POST is optional if you use -d, as the -d flag implies a POST request.
On Windows, things are slightly different. See the comment thread.
Try to put your data in a file, say body.json and then use
curl -H "Content-Type: application/json" --data #body.json http://localhost:8080/ui/webapp/conf
For Windows, having a single quote for the -d value did not work for me, but it did work after changing to double quote. Also I needed to escape double quotes inside curly brackets.
That is, the following did not work:
curl -i -X POST -H "Content-Type: application/json" -d '{"key":"val"}' http://localhost:8080/appname/path
But the following worked:
curl -i -X POST -H "Content-Type: application/json" -d "{\"key\":\"val\"}" http://localhost:8080/appname/path
You might find resty useful:
It's a wrapper round CURL which simplifies command line REST requests. You point it to your API endpoint, and it gives you PUT and POST commands (Examples adapted from the homepage).
resty http://127.0.0.1:8080/data #Sets up resty to point at your endpoing
GET /blogs.json #Gets http://127.0.0.1:8080/data/blogs.json
#Put JSON
PUT /blogs/2.json '{"id" : 2, "title" : "updated post", "body" : "This is the new."}'
# POST JSON from a file
POST /blogs/5.json < /tmp/blog.json
Also, it's often still necessary to add the Content Type headers. You can do this once, though, to set a default, of add configuration files per-method per-site: Setting default RESTY options
It worked for me using:
curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"id":100}' http://localhost/api/postJsonReader.do
It was happily mapped to the Spring controller:
#RequestMapping(value = "/postJsonReader", method = RequestMethod.POST)
public #ResponseBody String processPostJsonData(#RequestBody IdOnly idOnly) throws Exception {
logger.debug("JsonReaderController hit! Reading JSON data!"+idOnly.getId());
return "JSON Received";
}
IdOnly is a simple POJO with an id property.
You can use Postman to convert to CURL:
Note:
The latest Postman version has some UI upgrades and now the code link is available in the sidebar.
As an example, create a JSON file, params.json, and add this content to it:
[
{
"environment": "Devel",
"description": "Machine for test, please do not delete!"
}
]
Then you run this command:
curl -v -H "Content-Type: application/json" -X POST --data #params.json -u your_username:your_password http://localhost:8000/env/add_server
I just run into the same problem. I could solve it by specifying
-H "Content-Type: application/json; charset=UTF-8"
This worked well for me.
curl -X POST --data #json_out.txt http://localhost:8080/
Where,
-X Means the HTTP verb.
--data Means the data you want to send.
You can use Postman with its intuitive GUI to assemble your cURL command.
Install and Start Postman
Type in your URL, Post Body, Request Headers etc. pp.
Click on Code
Select cURL from the drop-down list
copy & paste your cURL command
Note: There are several options for automated request generation in the drop-down list, which is why I thought my post was neccessary in the first place.
HTTPie is a recommended alternative to curl because you can do just
http POST http://example.com/some/endpoint name=value name1=value1
It speaks JSON by default and will handle both setting the necessary header for you as well encoding data as valid JSON. There is also:
Some-Header:value
for headers, and
name==value
for query string parameters. If you have a large chunk of data, you can also read it from a file have it be JSON encoded:
field=#file.txt
Using CURL Windows, try this:
curl -X POST -H "Content-Type:application/json" -d "{\"firstName\": \"blablabla\",\"lastName\": \"dummy\",\"id\": \"123456\"}" http-host/_ah/api/employeeendpoint/v1/employee
TL;DR:
Use the holy trinity, jo + curl + jq (or fx):
jo value=30 type="Tip 3" targetModule="Target 3" configurationGroup=null name="Configuration Deneme 3" description=null identity="Configuration Deneme 3" | \
curl --json #- \
-X POST \
http://localhost:8080/xx/xxx/xxxx | \
jq
This will cover necessary headers that were missing: no need to explicitly define the Content-Type and Accept headers.
The new curl way with --json
Early March 2022, curl released a new command line parameter --json with version 7.82.0. This allows for a shortcut to send through JSON and eliminating the need to define the Content-Type that you had missing and Accept headers as these are automatically assumed, hence reducing risk of mistakes:
curl --json '{"tool": "curl"}' https://example.com/
But wait... there is more. Instead of defining the json parameter as a string to the curl command line, use the nifty jo CLI tool to define JSON as series of key value pairs and pipe the output through curl. Using jo only to define your JSON, it works this way:
> jo -p value=30 type="Tip 3" targetModule="Target 3" configurationGroup=null name="Configuration Deneme 3" description=null identity="Configuration Deneme 3"
version=0 systemId=3 active=true
{
"value": 30,
"type": "Tip 3",
"targetModule": "Target 3",
"configurationGroup": null,
"name": "Configuration Deneme 3",
"description": null,
"identity": "Configuration Deneme 3",
"version": 0,
"systemId": 3,
"active": true
}
Let's showcase this now with a similar curl command of yours but without extra headers and using jo + jq for nice output:
jo value=30 type="Tip 3" targetModule="Target 3" configurationGroup=null name="Configuration Deneme 3" description=null identity="Configuration Deneme 3" | \
curl --json #- \
-X POST \
http://localhost:8080/xx/xxx/xxxx | \
jq
Example with a free API
Using a free mock API for demonstration:
> jo title="Blog Post" body="lorem ipsum" userId=33 | \
curl --json #- \
-X POST \
https://jsonplaceholder.typicode.com/posts | \
jq
The output has a pretty format thanks to jq:
{
"title": "Blog Post",
"body": "lorem ipsum",
"userId": 33,
"id": 101
}
Use -d option to add payload
curl -X POST \
http://<host>:<port>/<path> \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"foo": "bar",
"lorem": "ipsum"
}'
In addition:
use -X POST to use POST method
use -H 'Accept: application/json' to add accept type header
use -H 'Content-Type: application/json' to add content type header
If you're testing a lot of JSON send/responses against a RESTful interface, you may want to check out the Postman plug-in for Chrome (which allows you to manually define web service tests) and its Node.js-based Newman command-line companion (which allows you to automate tests against "collections" of Postman tests.) Both free and open!
This worked well for me, additionally using BASIC authentication:
curl -v --proxy '' --basic -u Administrator:password -X POST -H "Content-Type: application/json"
--data-binary '{"value":"30","type":"Tip 3","targetModule":"Target 3","configurationGroup":null,"name":"Configuration Deneme 3","description":null,"identity":"Configuration Deneme 3","version":0,"systemId":3,"active":true}'
http://httpbin.org/post
Of course, you should never use BASIC authentication without SSL and a checked certificate.
I ran into this again today, using Cygwin's cURL 7.49.1 for Windows... And when using --data or --data-binary with a JSON argument, cURL got confused and would interpret the {} in the JSON as a URL template. Adding a -g argument to turn off cURL globbing fixed that.
See also Passing a URL with brackets to curl.
You could also put your JSON content in a file and pass it to curl using the --upload-file option via standard input, like this:
echo 'my.awesome.json.function({"do" : "whatever"})' | curl -X POST "http://url" -T -
This worked for me:
curl -H "Content-Type: application/json" -X POST -d #./my_json_body.txt http://192.168.1.1/json
I had the issue of:
curl -X POST http://your-server-end-point -H "Content-Type: application/json"
-d #path-of-your-json-file.json
See, I did everything right. Only one thing - I missed "#" before the JSON file path.
I found one relevant go-to document on Internet - Common Options.
Here is another way to do it, if you have dynamic data to be included.
#!/bin/bash
version=$1
text=$2
branch=$(git rev-parse --abbrev-ref HEAD)
repo_full_name=$(git config --get remote.origin.url | sed 's/.*:\/\/github.com\///;s/.git$//')
token=$(git config --global github.token)
generate_post_data()
{
cat <<EOF
{
"tag_name": "$version",
"target_commitish": "$branch",
"name": "$version",
"body": "$text",
"draft": false,
"prerelease": false
}
EOF
}
echo "Create release $version for repo: $repo_full_name branch: $branch"
curl --data "$(generate_post_data)" "https://api.github.com/repos/$repo_full_name/releases?access_token=$token"
I am using the below format to test with a web server.
use -F 'json data'
Let's assume this JSON dict format:
{
'comment': {
'who':'some_one',
'desc' : 'get it'
}
}
Full example
curl -XPOST your_address/api -F comment='{"who":"some_one", "desc":"get it"}'
This worked for me for on Windows 10:
curl -d "{"""owner""":"""sasdasdasdasd"""}" -H "Content-Type: application/json" -X PUT http://localhost:8080/api/changeowner/CAR4
I made a tool called fetcher for this. It can send requests and format curl snippets:
Here's an example:
Example output:
curl -XGET -H "Accept: application/json" -d "{\"value\":\"30\",\"type\":\"Tip 3\",\"targetModule\":\"Target 3\",\"configurationGroup\":null,\"name\":\"Configuration Deneme 3\",\"description\":null,\"identity\":\"Configuration Deneme 3\",\"version\":0,\"systemId\":3,\"active\":true}" "http://localhost:8080/xx/xxx/xxxx"
For PowerShell I've used:
curl.exe -H "Content-Type: application/json" --data "#content.json" http://localhost:8080/appname/path
Where content.json was the name of the JSON file on my local containing the request, and curl.exe instead of just curl not to use the alias for Invoke-WebRequest.
Or if you want to specify directly the JSON:
curl.exe -H "Content-Type: application/json" --data '{\"username\":\"xyz\",\"password\":\"xyz\"}' http://localhost:8080/appname/path
-H to send something like content-type or an authentication token in the header
-d here adds your data
finally add a site link
Note: Don't forget to add an authentication token (if you have) for authentication credentials
curl -X POST -H 'Content-Type: application/json' -H 'Authorization: Token 2de403987713595a7955a9b4655b9e206d4294b3' -d '{"title":"Post test with curl", "body": "test body"}' http://127.0.0.1:8000/api/v1/feeds/
You can cat the contents of a JSON file to curl via the --data-raw parameter.
curl 'https://api.com/route' -H 'Content-Type: application/json' --data-raw "$(cat ~/.json/payload-2022-03-03.json | grep -v '^\s*//')"
Note: comments in the JSON file are filtered out via grep -v '^\s*//'
You can also pass the data to curl via standard input using grep or cat.
grep -v '^\s*//' ~/.json/payload-2022-03-03.json | curl 'https://api.com/route' -H 'Content-Type: application/json' -d #-
cat ~/.json/payload-2022-03-03.json | grep -v '^\s*//' | curl 'https://api.com/route' -H 'Content-Type: application/json' -d #-
The issue is here:
HTTP/1.1 415 Unsupported Media Type
Server Login can't interpret the Media Type of this request, so it is parsing it as text/html
The media type of any resource is declared in the Content-Type
property of the request header
"accept" ... header will fail this request, so the following is required for any JSON request to be sent i.e. content-type
-H 'content-type: application/json'
Suppose data and URL are something like this
{"email": "admin#admin.com","password": "123456"}
http://localhost:5000/api/login
Then in Linux
curl http://localhost:5000/api/login -H 'content-type: application/json' -d '{"email": "user#admin.com", "password": "123456"}'
In Windows (single quotes around parameters will not work)
curl http://localhost:5000/api/login -H "content-type: application/json" -d "{\"email\": \"user#admin.com\", \"password\": \"123456\"}"
-X POST key is not required when -d {.....} is present in command.
For a PUT request:
-X PUT
Based on Anand Rockzz's answer, here is what I did to this on GitHub Actions. It was a bit tricky due to the EOF tag.
My goal was to send an HTTP call once a Vercel deployment was finished (similar to a webhook).
This real-world example might help other people.
send-webhook-callback-once-deployment-ready:
name: Invoke webhook callback url defined by the customer (Ubuntu 18.04)
runs-on: ubuntu-18.04
needs: await-for-vercel-deployment
steps:
- uses: actions/checkout#v1 # Get last commit pushed - See https://github.com/actions/checkout
- name: Expose GitHub slug/short variables # See https://github.com/rlespinasse/github-slug-action#exposed-github-environment-variables
uses: rlespinasse/github-slug-action#v3.x # See https://github.com/rlespinasse/github-slug-action
- name: Expose git environment variables and call webhook (if provided)
# Workflow overview:
# - Resolves webhook url from customer config file
# - If a webhook url was defined, send a
run: |
MANUAL_TRIGGER_CUSTOMER="${{ github.event.inputs.customer}}"
CUSTOMER_REF_TO_DEPLOY="${MANUAL_TRIGGER_CUSTOMER:-$(cat vercel.json | jq --raw-output '.build.env.NEXT_PUBLIC_CUSTOMER_REF')}"
VERCEL_DEPLOYMENT_COMPLETED_WEBHOOK=$(cat vercel.$CUSTOMER_REF_TO_DEPLOY.staging.json | jq --raw-output '.build.env.VERCEL_DEPLOYMENT_COMPLETED_WEBHOOK')
# Checking if a webhook url is defined
if [ -n "$VERCEL_DEPLOYMENT_COMPLETED_WEBHOOK" ]; then
# Run script that populates git-related variables as ENV variables
echo "Running script populate-git-env.sh"
. ./scripts/populate-git-env.sh
echo "Resolved git variables:"
echo "'GIT_COMMIT_SHA': $GIT_COMMIT_SHA"
echo "'GIT_COMMIT_REF': $GIT_COMMIT_REF"
echo "'GIT_COMMIT_TAGS': $GIT_COMMIT_TAGS"
# Generates JSON using a bash function - See https://stackoverflow.com/a/57369772/2391795
# "End Of File" must be at the beginning of the line with no space/tab before or after - See https://stackoverflow.com/a/12909284/2391795
# But, when executed by GitHub Action, it must be inside the "run" section instead
generate_post_data() {
cat <<EOF
{
"MANUAL_TRIGGER_CUSTOMER": "${MANUAL_TRIGGER_CUSTOMER}",
"CUSTOMER_REF": "${CUSTOMER_REF_TO_DEPLOY}",
"STAGE": "staging",
"GIT_COMMIT_SHA": "${GIT_COMMIT_SHA}",
"GIT_COMMIT_REF": "${GIT_COMMIT_REF}",
"GIT_COMMIT_TAGS": "${GIT_COMMIT_TAGS}",
"GITHUB_REF_SLUG": "${GITHUB_REF_SLUG}",
"GITHUB_HEAD_REF_SLUG": "${GITHUB_HEAD_REF_SLUG}",
"GITHUB_BASE_REF_SLUG": "${GITHUB_BASE_REF_SLUG}",
"GITHUB_EVENT_REF_SLUG": "${GITHUB_EVENT_REF_SLUG}",
"GITHUB_REPOSITORY_SLUG": "${GITHUB_REPOSITORY_SLUG}",
"GITHUB_REF_SLUG_URL": "${GITHUB_REF_SLUG_URL}",
"GITHUB_HEAD_REF_SLUG_URL": "${GITHUB_HEAD_REF_SLUG_URL}",
"GITHUB_BASE_REF_SLUG_URL": "${GITHUB_BASE_REF_SLUG_URL}",
"GITHUB_EVENT_REF_SLUG_URL": "${GITHUB_EVENT_REF_SLUG_URL}",
"GITHUB_REPOSITORY_SLUG_URL": "${GITHUB_REPOSITORY_SLUG_URL}",
"GITHUB_SHA_SHORT": "${GITHUB_SHA_SHORT}"
}
EOF
}
echo "Print generate_post_data():"
echo "$(generate_post_data)"
echo "Calling webhook at '$VERCEL_DEPLOYMENT_COMPLETED_WEBHOOK'"
echo "Sending HTTP request (curl):"
curl POST \
"$VERCEL_DEPLOYMENT_COMPLETED_WEBHOOK" \
-vs \
--header "Accept: application/json" \
--header "Content-type: application/json" \
--data "$(generate_post_data)" \
2>&1 | sed '/^* /d; /bytes data]$/d; s/> //; s/< //'
# XXX See https://stackoverflow.com/a/54225157/2391795
# -vs - add headers (-v) but remove progress bar (-s)
# 2>&1 - combine stdout and stderr into single stdout
# sed - edit response produced by curl using the commands below
# /^* /d - remove lines starting with '* ' (technical info)
# /bytes data]$/d - remove lines ending with 'bytes data]' (technical info)
# s/> // - remove '> ' prefix
# s/< // - remove '< ' prefix
else
echo "No webhook url defined in 'vercel.$CUSTOMER_REF_TO_DEPLOY.staging.json:.build.env.VERCEL_DEPLOYMENT_COMPLETED_WEBHOOK' (found '$VERCEL_DEPLOYMENT_COMPLETED_WEBHOOK')"
fi
--json <data> Sends the specified JSON data in a POST request to the HTTP server.
curl 7.82.0+
# Send a basic JSON object
curl --json '{"name":"xyz","breed":"xyz","age":100}' http://127.0.0.1:3000/cats
# letter #, read the data from a file
curl --json #cat.txt http://127.0.0.1:3000/cats
# letter -, read the data from stdin
echo '{"name":"xyz","breed":"xyz","age":100}' | curl --json #- http://127.0.0.1:3000/cats
curl 7.82.0-
curl -X POST --header "Content-Type: application/json" --data '{"name":"xyz","breed":"xyz","age":100}' http://127.0.0.1:3000/cats
https://curl.se/docs/manpage.html#--json
simple is that
curl -X POST https://localhost:3000/
-H "Content-Type: application/json"
-d '{"productId": 123456, "quantity": 100}'

Azure IoT-Hub Job Query returns to few results

I already successfully scheduled a lot of jobs using the REST API of the Azure IoT-Hub as described in https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-jobs. Namely I scheduled jobs to execute direct methods.
But, when I try to query the status of the scheduled jobs (as described on the same page), I always get only one entry: the status of the first successfully scheduled job. How do I get the status of all jobs?
My query was:
curl -X GET \
https://<iot-hub-name>.azure-devices.net/jobs/v2/query?api-version=2018-06-30 \
-H 'Authorization: SharedAccessSignature <sas-token>' \
-H 'Content-Type: application/json; charset=utf-8' -o response.json
The SAS Token I used above was the same as for scheduling the job. Thus, there is no authentication issue.
The formatted response just contains 1 entry despite that I already scheduled 11 jobs:
[
{
"jobId": "job02",
"queryCondition": "deviceId = simple_thermostat",
"createdTime": "2022-03-02T15:59:27.4093129Z",
"startTime": "2022-03-02T15:20:15Z",
"endTime": "2022-03-02T15:59:34.5969497Z",
"maxExecutionTimeInSeconds": 10000,
"type": "scheduleDeviceMethod",
"cloudToDeviceMethod": {
"methodName": "getMaxMinReport",
"payload": "hello",
"responseTimeoutInSeconds": 300,
"connectTimeoutInSeconds": 0
},
"status": "completed",
"deviceJobStatistics": {
"deviceCount": 0,
"failedCount": 0,
"succeededCount": 0,
"runningCount": 0,
"pendingCount": 0
}
}
]
PS: Getting the status of a single job works as expected. Like using this request:
curl -X GET \
https://<iot-hub-name>.azure-devices.net/jobs/v2/job11?api-version=2018-06-30 \
-H 'Authorization: SharedAccessSignature <sas-token>' \
-H 'Content-Type: application/json; charset=utf-8' -o response.json
But, job11 is never returned in the query above.
As pointed out by Roman Kiss, the continuation token can be found in the header of the first response. To save the header via curl one must specify the option -D. So, the first query must look like:
curl -X GET \
https://<iot-hub-name>.azure-devices.net/jobs/v2/query?api-version=2018-06-30 \
-H 'Authorization: SharedAccessSignature <sas-token>' \
-H 'Content-Type: application/json; charset=utf-8' \
-D response_hdr.txt -o response.json
Then response_hdr.txt will contain a line like this:
x-ms-continuation: eyJzb3VyY2UiOiJkZGIiLCJ0b3RhbFJldHJpZXZlZENvdW50Ijo4LCJjb250aW51YXRpb25Ub2tlbiI6Ilt7XCJ0b2tlblwiOm51bGwsXCJyYW5nZVwiOntcIm1pblwiOlwiMDVDMUU3RkZGRkZGRkFcIixcIm1heFwiOlwiRkZcIn19XSJ9
But, this continuation token must not be specified in the URL as stated in the Microsoft docs. Instead it must be provided in the header of the subsequent query:
curl -X GET \
https://<iot-hub-name>.azure-devices.net/jobs/v2/query?api-version=2018-06-30 \
-H 'Authorization: SharedAccessSignature <sas-token>' \
-H 'Content-Type: application/json; charset=utf-8' \
-H 'x-ms-continuation: <continuation_token_from_previous_query>' \
-D response_hdr.txt -o response.json
This query will deliver a new continuation token. It looks pretty similar, but it is not identical.

How to create new resource from a file via CKAN API with cURL?

The following cURL is from: https://tech.datopian.com/ckan/play-around.html#create-organizations-datasets-and-resources
and lets you add a resource to a datset from a url.
curl -X POST http://ckan:5000/api/3/action/resource_create -H "Authorization: 9c04a69d-79f4-4b4b-b4e1-f2ac31ed961c" -d '{
"package_id": "my-first-dataset",
"url": "https://raw.githubusercontent.com/frictionlessdata/test-data/master/files/csv/100kb.csv",
"description": "This is the best resource ever!" ,
"name": "brand-new-resource"
}'
Was wondering how you could add a resource from a file.
I can share my example request from a Postman collection (hope it helps):
curl --location --request POST 'http://local-ckan/api/3/action/resource_create' \
--header 'Authorization: xxx-yyy-zzz' \
--form 'package_id="dataset-name"' \
--form 'upload=#"/home/tomek/Downloads/example.csv"' \
--form 'name="new-resource-with-file"'
And here's a note on creating resources from my achives while I was dealing with uploading files to CKAN:
API calls are either POST with a JSON body or POST with a multipart/form body. When using multipart/form you can't nest anything (e.g. resources) in the same call so you have to make multiple calls (package_create, resource_create, resource_create, ...). When using JSON you can't upload files as part of the same call so you need to attach any files with separate multipart/form calls e.g. with resource_patch

unable to create schema in MarkLogic database

I used the following syntax from documentation
curl -X POST --anyauth --user admin:admin \
--header "Content-Type:application/json" \
-d '{"view-schema-name": "mySchema"}' \
http://localhost:8002/manage/v2/databases/SQLdata/view-schemas?format=json
your thoughts please! TIA
Error msg -
curl: (3) [globbing] unmatched close brace/bracket in column 9
{"errorResponse":{"statusCode":"415", "status":"Unsupported Media Type", "messag
eCode":"REST-INVALIDMIMETYPE", "message":"REST-INVALIDMIMETYPE: (rest:INVALIDMIM
ETYPE) Content-Type must be one of: 'application/json', 'application/xml', Rece
ived: application/x-www-form-urlencoded"}}
As I mentioned before, the output of your cUrl command will be helpful. But without that, the only error I can imagine from your sample is of the database SQLdata does not exist..