cURL - URL containing parameters - url

I am trying to post a file to webservice with curl and with a content type of "multipart/form-data" and can't get it working. I guess my my problem is that I have parameters in the url.
../fileuploader.ws?aId=579&eId=226
curl -u user:password -F -binary-data=#test.pdf "http://localhost/fileuploader.ws?aId=579&eId=226"
I am getting error that my request is missing parameters aId and eId. I have also tried with single quotes with the same result. All the topics and discussions says that using quotes should work, but it seems like using quotes with url doesn't have effect.

The behavior depends on your shell envt. Try to escape & with \& with/without the quotes (single or double)

Related

Microsoft Graph REST API to UPDATE Microsoft Planner Tasks?

I think this might be a simple quote escape issue, but can’t figure it out.
I am trying to update a microsoft planner task using CURL with REST API. I can CREATE tasks (from a custom application called FileMaker to Microsoft Planner using Microsoft Graph API) without issue, but when I try to UPDATE a planner task, I get an error that "The If-Match header must be specified for this kind of request." But I am including the If-Match header, just might not be entering it correctly.
The URL is:
"https://graph.microsoft.com/v1.0/planner/tasks/" & $microsoftplannerTaskID
The CURLOPTIONS, I am entering within FileMaker is ...
"-X PATCH " &
" -H "Authorization: Bearer " & $$userToken & """ &
" -H "Content-Type: application/json"" &
" -H "If-Match: " & $microsoftPlannerTasketag & """ &
" -d #$PlannerTaskDetails"
ENDS UP LOOKING LIKE THIS …
-X PATCH -H "Authorization: Bearer wEXu<>k_QQY" -H "Content-Type: application/json" -H "If-Match: W/"JzEtVGFzayAgQEBAQEBAQBAQEBARCc="" -d #$PlannerTaskDetails
When I CREATE the task initially, the response show …
"#odata.etag":"W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc=""
Which I am using in the cURL header above. BUT … I am stripping the W/ and the quotes. The W/ means it is a “weak”, and I assume we don’t include that in the PATCH header, but I did try adding it anyway with no success.
Here is Microsoft’s UPDATE PLANNERTASK reference …
https://learn.microsoft.com/en-us/graph/api/plannertask-update?view=graph-rest-1.0&tabs=http
I can update tasks using POSTMAN without issue, but I dont know what their header looks like when it sends the request.
I can get it to work in Postman and in there I have entered for the Plan ETag variable this …
W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc="
I notice in postman the header shows etag is
W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc="
And the body returns as
"#odata.etag": "W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc="",
It’s got to be a simple syntax issue with my curloption variable, but I can’t figure it out.
I also tried removing the W/ in the If-Match header, so it looks like this:
-H "If-Match: "JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc=""
And the extra quotes in the If-Match header, so it looks like this:
-H "If-Match: JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc="
All of these result in the same “if-match” error.
One interesting thing …if I change the If-Match to include a slash in front of the quotes
-H "If-Match: "JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc=""
I get an error 10 “requested data is missing” in Filemaker’s script debugger and no response from the insert from url statement. Makes sense though, since it is reading this as “if-match: ”
And same thing if I add the W/ back in
-H "If-Match: W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc=""
Gives me error 10 as well
If you have any thoughts, I would greatly appreciate your help!!
Try this:
"-X PATCH " &
"-H " & quote("Authorization: Bearer " & $$userToken) &
"-H " & quote("Content-Type: application/json") &
"-H " & quote("If-Match: W/" & quote($microsoftPlannerTasketag)) &
"-d #$PlannerTaskDetails"

Is this Calendly.com URL Valid?

I am using webhooks for the first time with calendly.com. I would like to create a subscription as described here. When I get to doing this
curl --header "X-TOKEN: <your_token>" --data "url=https://blah.foo/bar&events[]=invitee.created" https://calendly.com/api/v1/hooks
I am concerned that the url is not in a valid format. I tried replacing the & with a ? as in here
curl --header "X-TOKEN: <your_token>" --data "url=https://blah.foo/bar?events[]=invitee.created" https://calendly.com/api/v1/hooks
but I receive this error
{"events":{"events":["can't be blank]}}
Likewise, I try to leave the & and everything after it blank and it give the same error as above.
But using a url with the & and everything in it gives a 404 not found error. Can a url even have the format they are saying is required?
But using a url with the & and everything in it gives a 404 not found error.
The URL part in the following is just the https://blah.foo/bar part before the & character.
curl --header "X-TOKEN: <your_token>" --data "url=https://blah.foo/bar&events[]=invitee.created" https://calendly.com/api/v1/hooks
The events[]=invitee.created part is a separate parameter and value. It’s not part of the url.
See the Create A Webhook Subscription page in the calendy docs:
So the URL is the site that runs your webhook; you don’t send the events parameter/value back to that site—instead you’re sending both the url param and events param to the calendly API endpoint at https://calendly.com/api/v1/hooks. The calendly backend presumably then calls to https://mywebsite.com/webhooks/invitee_created or https://blah.foo/bar whatever url you’ve given it—but without the events parameter, which is for calendly’s internal use.

insert multiple values with tags into influxdb

I'm trying to collect smartctl metrics and push them into influxdb. I'm having difficulty adding tags for values being pushed in so that the tags and values are in the right place.
If I do this:
curl -POST 'http://localhost:8086/write?db=test' --data-binary 'smartctl Raw_Read_Error_Rate=19243395i,Spin_Up_Time=0i,Start_Stop_Count=149i,Reallocated_Sector_Ct=25i,Seek_Error_Rate=4735843653i,Power_On_Hours=41286i,Spin_Retry_Count=0i,Power_Cycle_Count=150i,End_to_End_Error=0i,Reported_Uncorrect=0i,Command_Timeout=12885098501i,High_Fly_Writes=0i,Airflow_Temperature_Cel=29i,G_Sense_Error_Rate=0i,Power_Off_Retract_Count=145i,Load_Cycle_Count=25668i,Temperature_Celsius=29i,Hardware_ECC_Recovered=19243395i,Current_Pending_Sector=0i,Offline_Uncorrectable=0i,UDMA_CRC_Error_Count=0i 1472412282915653274'
There are no tags:
SHOW TAG KEYS FROM "smartctl" (empty result)
How do I add tags to that same curl command so that I get something like:
host=foo,disk_name="Seagate Blah"
Adding some clarification:
If I use a comma (and set a value), then they are all tags, not fields:
curl -POST 'http://localhost:8086/write?db=test' --data-binary 'smartctl,Raw_Read_Error_Rate=19243395i,Spin_Up_Time=0i,Start_Stop_Count=149i,Reallocated_Sector_Ct=25i,Seek_Error_Rate=4735843653i,Power_On_Hours=41286i,Spin_Retry_Count=0i,Power_Cycle_Count=150i,End_to_End_Error=0i,Reported_Uncorrect=0i,Command_Timeout=12885098501i,High_Fly_Writes=0i,Airflow_Temperature_Cel=29i,G_Sense_Error_Rate=0i,Power_Off_Retract_Count=145i,Load_Cycle_Count=25668i,Temperature_Celsius=29i,Hardware_ECC_Recovered=19243395i,Current_Pending_Sector=0i,Offline_Uncorrectable=0i,UDMA_CRC_Error_Count=0i value=0 1472412282915653274'
(side note: I also don't see what I would set as a value for "smartctl"?)
What I need is to set all of the above as a field, but with tags so I can determine the host they are reporting from. So I can do something like:
select Temperature_Celsius from smartctl where host=foo
Put your tags just after measurement name, separated with comma, full line protocol definition is like that:
measurement,tag1=foo,tag2=bar value_a=1,value_b=2 timestamp
So in your case:
curl -POST 'http://localhost:8086/write?db=test' --data-binary 'smartctl,host=foo,disk_name="Seagate Blah" Raw_Read_Error_Rate=19243395i,Spin_Up_Time=0i,Start_Stop_Count=149i,Reallocated_Sector_Ct=25i,Seek_Error_Rate=4735843653i,Power_On_Hours=41286i,Spin_Retry_Count=0i,Power_Cycle_Count=150i,End_to_End_Error=0i,Reported_Uncorrect=0i,Command_Timeout=12885098501i,High_Fly_Writes=0i,Airflow_Temperature_Cel=29i,G_Sense_Error_Rate=0i,Power_Off_Retract_Count=145i,Load_Cycle_Count=25668i,Temperature_Celsius=29i,Hardware_ECC_Recovered=19243395i,Current_Pending_Sector=0i,Offline_Uncorrectable=0i,UDMA_CRC_Error_Count=0i 1472412282915653274'
See also: https://docs.influxdata.com/influxdb/v1.6/write_protocols/line_protocol_tutorial/
You have an space after measurement 'smartctl' instead of ','. Try:
curl -POST 'http://localhost:8086/write?db=test' --data-binary 'smartctl,Raw_Read_Error_Rate=19 value=0.64 1472412282915653274'
Documentation indicates :
The HTTP API is the primary means of putting data into InfluxDB. To write data send a POST request to the /write endpoint. The example below writes a single point to the mydb database. The data consist of the measurement cpu_load_short, the tag keys host and region with the tag values server01 and us-west, the field key value with a field value of 0.64, and the timestamp 1434055562000000000.
curl -i -XPOST 'http://localhost:8086/write?db=mydb' --data-binary 'cpu_load_short,host=server01,region=us-west value=0.64 1434055562000000000'

Amazon Web Service Signature issue

I am trying to fetch product related data from Amazon Product API using this URL mentioned here:
http://docs.aws.amazon.com/AWSECommerceService/latest/DG/ItemLookup.html
Item Lookup URL:
http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=[AWS_Access_Key_ID]&Operation=ItemLookup&ItemId=B00008OE6I&Timestamp=[YYYY-MM-DDThh:mm:ssZ]&Signature=[Request_Signature]
I have entered required details/parameters in URL but I am unable to understand where to get this Signature from or how to generate this signature? Any help would be appreciated.
The easiest and fastest way would be using one of AWS SDKs. You can find the full list here: https://aws.amazon.com/tools/
When you use the SDK you just supply your access key and secret key. The libraries handle preparing the signature.
Well, there's no point in doing this by yourself in Ruby, once it has a SDK, but an explanation about signature process may be useful for some people.
Signature is the way AWS authenticates API requests. It is passed as a query string parameter on your HTTP request and is validated against your own request content and you credentials on server-side.
There are 2 versions of it: 2 and 4, explained here and here. Version 2 is not supported on newer regions (China and Frankfurt).
In version 2, which I'm more familiar with, the signature is generated based on a string with this format:
HTTPVerb + "\n" + ValueOfHostHeaderInLowercase + "\n" + HTTPRequestURI
+ "\n" + CanonicalizedQueryString
The CanonicalizedQueryString is your query string, with parameters sorted (UTF-8 byte order) by paramater names and with parameter values url-encoded.
Then you calculate an HMAC of that string, using your AWS secret key, and SHA256 or SHA1 as the hash algorithm (depending on which one you have specified on query string parameter SignatureMethod), and encode it to base64. The result of all this will be the value of the Signature parameter.
I will try to walk you through a CloudWatch request, generated manually with bash tools.
Let's say you want to list you CloudWatch metrics. The request (without the signature) would be like the following.
http://monitoring.amazonaws.com/?AWSAccessKeyId=AVUKYAMNIIGWALNMA6IG&Action=ListMetrics&SignatureMethod=HmacSHA1&SignatureVersion=2&Timestamp=2015-08-20T22%3A40%3A00.000Z&Version=2010-08-01
So, your string to sign would be:
GET
monitoring.amazonaws.com
/
AWSAccessKeyId=AVUKYAMNIIGWALNMA6IG&Action=ListMetrics&SignatureMethod=HmacSHA1&SignatureVersion=2&Timestamp=2015-08-20T22%3A40%3A00.000Z&Version=2010-08-01
Well, let's put it in a variable and do all the magic (hmac + base64)
#!/bin/bash
# your secret key
key='ry+SyjvXLvi4lYie/QfZYnxYOBQDggf01DTUxFSK'
# using 'read' to assign the signing string
# to a variable for readability reasons
read -r -d '' payload <<EOF
GET
monitoring.amazonaws.com
/
AWSAccessKeyId=AVUKYAMNIIGWALNMA6IG\
&Action=ListMetrics\
&SignatureMethod=HmacSHA1\
&SignatureVersion=2&\
Timestamp=2015-08-20T22%3A40%3A00.000Z\
&Version=2010-08-01
EOF
echo -n "$payload" | openssl dgst -sha256 -hmac $key -binary | openssl enc -base64
Then, after all this, you will end up with something like this:
xrIYF8wO0C8YOQgcdpq6MoJpBWzXEWxuTBAAoqYoGWM=
This is your signature, and finally, you just need to url-encoded it and append it to your request as one more query-string parameter.
&Signature=xrIYF8wO0C8YOQgcdpq6MoJpBWzXEWxuTBAAoqYoGWM%3D
Hopefully, if you did everything correctly (putting the sign string together, generating the hash and encoding it), your request will be accepted and, if you have enough permission, executed.
So, as you can see, it's something not worth to do by yourself. Use the SDK. ;)
Thank You guys for your response. But I have finally figured out my problem and my solution was in this gem:
https://github.com/jugend/amazon-ecs
This is what I was actually looking for and it finally helped me achieve what I was trying to. Posting it over here so people can find a better solution.

How to make jmeter convert |(pipe) to %7C automatically?

I am getting following error whenever Jmeter gets a | (pipe) symbol in the URL since the "pipe" symbol is not allowed in URL. Is there any way to convert the |(pipes) in URL to %7C automatically?
Response code: Non HTTP response code: java.net.URISyntaxException
Assuming the pipe is in an existing parameter try the following:
Check "Encode?" box in "Send Parameters with the Request" input of HTTP Request
Wrap your variable in __urlEncode function as ${__urlencode(queryTerm)}
Use Beanshell Pre Processor as a child of HTTP Request with the following code:
vars.put("queryTerm", URLEncoder.encode(vars.get("queryTerm")));
This should convert the pipes automatically.
Got the instructions from here: Jmeter - Configure Keywords with spaces using CSV File Configuration

Resources