how to send parameters using curl X post in Dockercontainer - docker

I am running a Dockercontainer. My Falcon app.py looks like:
import falcon
class Workers:
def on_post(self, expedice, celkem_pracovniku, req, resp):
output = str(
{
"expedice": expedice,
"celkem_pracovniku": celkem_pracovniku
}
)
resp.text = output
resp.status = falcon.HTTP_OK
app = application = falcon.API()
app.add_route("/pozice_skladApi/v1/pracovnici", Workers())
I am running a docker image on port 8082:80, but I dont now how can I run the /pozice_skladApi/v1/pracovnici exactly. I try:
curl -X POST http://localhost:8082/pozice_skladApi/v1/pracovnici -d "knihy-praha" 10 but I got {"title": "500 Internal Server Error"}. What I do wrong, please?

The problem was in the on_post function. Correct form is:
def on_post(self, req, resp):
try:
data = req.media
except:
raise falcon.HTTPBadRequest(description="Missing post data.")
expedice = data.get("expedice")
celkem_pracovniku = data.get("celkem_pracovniku")
Then you can use following command in the terminal: curl -X POST -H "Content-Type: application/json" -d '{"expedice": "knihy-praha", "celkem_pracovniku": 10}' http://localhost:8082/pozice_skladApi/v1/pracovnici

Related

Creating an issue with JIRA API `Anonymous users do not have permission to create issues in this project. Please try logging in first.`

I have a simple request that I am sending to a JIRA server
curl \
-D- \
-u 'api_key_label:api_key' \
-X POST \
--data '{"fields": {"project":{"key": "my_proj"}, "issuetype": {"name": "Bug"}}}' \
-H "Content-Type: application/json" \
https://my_instance/rest/api/2/issue/
When I send the request I get the response
{"errorMessages":[],"errors":{"project":"Anonymous users do not have permission to create issues in this project. Please try logging in first."}}%
If anyone has any experience with this I would appreciate some advice. Is the -u parameter supposed to base64 encoded?
Python
import requests
from requests.auth import HTTPBasicAuth
import json
data = json.dumps({"fields": {"project":{"key": "VER"},"summary": "summary": {"name": "Bug"}}})
url = 'https://my_instance:8080/rest/api/2/issue/'
headers = {
'Content-Type': 'application/json'
}
response = requests.post(url,auth=('email_accoount','api_key'),data=data,headers=headers)

How to frame the rest assured script for a post request based on CURL

I need to convert the below curl command into rest-assured POST request.
Can someone help me out
curl -ks --http1.0 -X POST "$server?format=pdf&tid=TD1" --cookie "INTERSET_SESSION=$access_token" -H 'content-type: multipart/form-data' -F 'template=#../templates/dashboard.hbs' -o output.pdf
The parameter template=#../templates/dashboard.hbs holds a file.
Check if the below helps
{
RequestSpecification req = RestAssured.given();
req.header("Content-Type", "multipart/form-data");
req.header("Cookie", "INTERSET_SESSION=ABCD");
req.multiPart("file2", new File("template=#../templates/dashboard.hbs"));
Response resp = req.post("$server?format=pdf&tid=TD1");
}

Curl request in Ruby for Facebook Api

I'm trying to make a curl call with curb gem equivalent to:
curl \
-F 'name=My new CA' \
-F 'subtype=CUSTOM' \
-F 'description=People who bought from my website' \
-F 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/v2.5/act_<AD_ACCOUNT_ID>/customaudiences
So far my code looks like:
cr = Curl::Easy.http_post("https://graph.facebook.com/v2.5/act_XXXXXXXXXXXXXXX/customaudiences?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") do |curl|
curl.headers['name']='My new CA'
curl.headers['subtype']='CUSTOM'
curl.headers['description']='People who bought from my website'
curl.headers['access_token']='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
end
pp cr.body_str
However, as a response I get this:
=> "{\"error\":{\"message\":\"(#100) Missing parameter(s): subtype\",\"type\":\"OAuthException\",\"code\":100,\"fbtrace_id\":\"BOd\\/mmhQkkP\"}}"
Could someone explain me what am I doing wrong?
Thank you!
You can also just use a system call like this:
name = "something"
url = "http://www.example.com"
result = `curl -F 'name=#{name}' #{url}`
result will hold the output of your system call. For more sophisticated http requests, you probably want to take a look at faraday (https://github.com/lostisland/faraday)

MALFORMED_REQUEST on PayPal execute payment

I've lost almost two whole days trying to solve PayPal related issues.
I'm trying to execute a payment after user's approval, but I'm getting MALFORMED_REQUEST everytime I send the Curl request.
def execute
# Get the access_token
token = get_paypal_token(false)
payer_id = params[:PayerID]
payment_id = params[:paymentId]
# Creating the data object
stringJson = {:payer_id => "#{payer_id}"}
# You can see that I hard-coded the payer_id to ensure the JSON is correct
curlString = `curl -v -H "Authorization: Bearer #{token}" -H "Content-Type: application/json" -d '{"payer_id" : "QULQSFESGMCX2"}' https://api.sandbox.paypal.com/v1/payments/payment/#{payment_id}/execute/`
end
And the response is:
"{\"name\":\"MALFORMED_REQUEST\",\"message\":\"The request JSON is not well formed.\",\"information_link\":\"https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST\",\"debug_id\":\"6431589715660\"}"
Looks like you are running it from windows. I tried your command from my windows and my test server receiving the json as '{payer_id. It is happening because of your single quote.
I have changed the single quotes into double and it is working fine here with me.
-d "{\"payer_id\" : \"QULQSFESGMCX2\"}"
You can run the curl command from the console and see what happens, after that you can push it inside your ruby script code.

post file using ruby curl easy.http_put (data)

I have a task to send a file using HTTP PUT in ruby.
In Command prompt i am able to get success response using the following command.
curl -X PUT -vN https://myexample.com/blah/myaccount --insecure -H "Connection: keep-alive" -H "Content-Type: audio/wav" -H "Content-Transfer-Encoding: base64" -d #/myfile.wav
While trying to send the request using Curl::Easy in ruby. I get a error response code stating something wrong with audio.
c = Curl::Easy.new("https://myexample.com/blah/myaccount")
c.timeout = 30
c.ssl_verify_host = false
c.http_put ( "Content-Transfer-Encoding=base64;Connection=keep-alive;Content-Type=audio%2fwav;#{File.read(/myfile.wav)}")

Resources