Post parameter to Rest API - json

I need to post a json data and it's parameter to REST API. I know there might be some issues when using json in cross domain, but I tried using mozilla addon "http requester" and using "php-curl" and getting result in a json format as {"success":false}.
Is there any way to inspect the REST API using json data? If so please provide me some example to pass a json data to a REST API using a parameter.

If you have curl installed, at the command line you can do:
curl -d "{\"success\": false}" http://path/to/api?param=value

Related

Get a github folder it's contents as a json file

if I construct this URL, I can see the contents of the images folder as a json in Firefox.
https://api.github.com/repos/DessoCode/ESP32/contents/Images?ref=main
However, this doesn't seem to be a true json since my parser doesn't parse this. I'm using an ESP32 and Arduino.
The code works with a true json link. (For example: http://arduinojson.org/example.json)
My question is: How do I change the first URL so it has a .json extension?
Thank you so much!
I figured it out, I needed to serialize the input stream first, then I could deserialize it and use the values.
The alternative is to install GitHub CLI gh (through one of the linux_arm64 packages), and use gh api to execute the API call... with -q or --jq <string> to query and select values from the response using jq syntax.
No need to serialize/de serialize.
gh api repos/DessoCode/ESP32/contents/Images?ref=main --jq ".[].path"
Images/robot.bmp
Images/skulltest.bmp
Images/yellow.bmp

Prestashop 1.6 API - POST with json

I'm using Prestashop 1.6.1.1 web service and I need to send POST request with json content. Is there any way to achieve this? When I performed GET request and I added output_format=JSON parameter, I got json as a result. Is there any analogical parameter for input?

Paypal API: NOT json response

I'm trying to execute example from here: https://developer.paypal.com/docs/classic/paypal-payments-pro/gs_PayPalPaymentsPro/
curl -s --insecure https://api-3t.sandbox.paypal.com/nvp -d "USER=platfo_1255077030_biz_api1.gmail.com&PWD=1255077037&SIGNATURE=Abg0gYcQyxQvnf2HDJkKtA-p6pqhA1k-KTYE0Gcy1diujFio4io5Vqjf&METHOD=DoDirectPayment&VERSION=78&PAYMENTACTION=SALE&AMT=5&ACCT=4660997962602322&CREDITCARDTYPE=VISA&CVV2=176&FIRSTNAME=James&LASTNAME=Smith&STREET=FirstStreet&CITY=SanJose&STATE=CA&ZIP=95131&COUNTRYCODE=US&EXPDATE=092015"
Documentation says:
Request method, format Response format
HTTP GET Name/value pairs JSON
But I receives:
TIMESTAMP=2015%2d01%2d30T12%3a14%3a08Z&CORRELATIONID=474de7dae8e82&ACK=Success&VERSION=78&BUILD=15009693&AMT=5%2e00&CURRENCYCODE=USD&AVSCODE=X&CVV2MATCH=M&TRANSACTIONID=93V64243P1844913T
Why? How to get json response?
I tried to set:
VERSION=95
but didn't help.
As document states the paypal NVP api doesn't straight away provide json response.
The way attained to process the response goes like below,
In PHP
parse_str($response,$responseArray);
$jsonResponse = json_encode($responseArray);
helped me to get the array from the response string and in turn converted to json.
Edit : you first need to decode the urlencoded string.
For that
$response = urldecode($response);
Before parsing the response to array.
While I do see the documentation you quoted (from https://developer.paypal.com/docs/classic/paypal-payments-pro/gs_PayPalPaymentsPro/), I think it's flat-out wrong.
I don't believe the classic PayPal APIs support JSON (except Adaptive Payments, which was written later # PayPal & is thus a bit more modern in some ways, including the JSON support).
See https://developer.paypal.com/docs/classic/api/gs_PayPalAPIs/, which describes the headers taht you can use to request JSON from the Adaptive APIs but clarifies that the other classic APIs don't support it.

How set default output type to JSON ins DSS

We have a mobile app using Restkit which would use as WSO2 DSS service as the backend of the app. The service has a database data source. However the developer is complaining that he gets an error that the service is only returning text/plain format. The service has a JSON output type and mapped on a json format. He said that in reskit it does not send the sevice the header content type but it is expecting a json output format. Is there anyway I can set DSS default output type as json output. I've already tried all the solutions in the net but still getting same error.
Normally JSON return handled by httpContentNegotiation parameter on 'axis2.xml' and in 'axis2_client.xml'.
<parameter name="httpContentNegotiation">true</parameter>
So simply you can set content request header with
Accept:application/json
ex:
curl -v -H "Accept:application/json" 'your_path'
If you are using restkit make sure to add a custom header to http request. You need to set the Accept header as mentioned above. Please find this link.

How to use JSON response from server to send POST request with parameters from JSON (jmeter)

I have some specific scenario for retrieving Access Token from API using jmeter.
I need to implement following test case and have no idea how to implement this (I am new in jmeter):
Send GET request to server.
Server will return following response: {"RequestToken":"81d1fcd6146d41f69a966a2c083382c7","Expires":3600}
After that I need to send POST request to server with parameter of "RequestToken" from step #2.
Thanks!
Answer of Dmitri T really helped me! Thanks a lot!
If your response {"RequestToken":"81d1fcd6146d41f69a966a2c083382c7","Expires":3600} is the full one you can add a Regular Expression Extractor Post Processor to GET request configured as follows:
Reference Name: anything meaningful, i.e. token
Regular Expression: {"RequestToken":"(.+?)","Expires":3600}
Template: $1$
After that you can refer to extracted value as ${token} or ${__V(token)} in POST request.
If you need to deal with more complex JSON structures I would recommend using JSON Path Extractor available via JMeter Plugin. It allows fetching data from JSON responses in more "intelligent" way as big JSON entities cannot be easily parsed via regular expressions.
In this case relevant JSON Path query will look like $.RequestToken.
See Using the XPath Extractor in JMeter guide for more details (scroll down to Parsing JSON).
Hope this helps.