Paypal API: NOT json response - json

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.

Related

Map entire Webhook Response in Marketo Webhook

I have a web-hook that calls an API that returns a single plain text response. The response isn't formatted in JSON or xml because the response is a single piece of data, not a map or array. I see plenty of examples of how to extract a field from a JSON response and store it in a marketo token but no example of how to store the whole response payload. Here is a sample response from the API:
alsdfjasdhfalksdhfalksdjalksdk
Note that the response is not anything like this:
{
"field":"alsdfjasdhfalksdhfalksdjalksdk"
}
Maybe some Marketo expert has done this and could share. I'd appreciate it, thanks.
Marketo's parsing of XML and JSON is limited, to say the least--so your webhook does need to declare some sort of key-value pair so the response can be mapped. Given what you're describing, you could likely just hardcode in the surrounding JSON with the right MIME type and be fine.
Basically, Marketo can only handle the following for JSON webhook responses:
Key-value pair
Key can only be defined by placement (no XPath or similar--you'd be stuck with field[1] or similar)
Ideally no nesting, as Marketo doesn't do a great job of reading nested data--largely for the reason mentioned above

Jmeter JSON Format Post Processor breaks Token retrieval

I am working with Jmeter and i want to format the JSON results. So i installed JSON Format Post Processor and added it to the root of the project.
It works correctly, it formats the JSon response for easy readability. However there is also a request with requires Token authentication. It does not work with the JSON Format Post Processor.
Example:
Correct coin retrieval without JSON Format Post Processor:
{"access_token":"Secret","expires_in":3600,"token_type":"Bearer"}
And with:
{
"access_token": "Secret",
"expires_in": 3600,
"token_type": "Bearer"
}
I use a regulair extractor to extract the token: access_token":"([a-zA-Z0-9.\-\_]*)
This seems to break in combination with the formatter. No valid token access is denied in all requests
Is there an easy way around this? It seems i can either use Jmeter JSON Format Post Processor for my complete project, or not at all.
Anyone know how i deal with this?
If it is possible, apply JSON Format Post Processor after regex extractor. This could help.
For easier access to data in JSON format you can use JSON Path Extractor or SmartMeter's Boundary Body Extractor
To extract JSON data the best option is native JSON Extractor:
http://jmeter.apache.org/usermanual/component_reference.html#JSON_Extractor
Regarding your precise issue, a better regexp would be:
access_token":"([^"]+?)"
It seems that you have optional white space after :
Regular expression:
access_token":(\s*)"([a-zA-Z0-9.\-\_]*)
Template change to use $2$

Is there any online tool that can be POST requested with json payload to be pretty printed?

There are plenty of online json viewers. Yet if there are any that may be POST requested with json payload so that incoming json string might be pretty printed? Not just copy/paste as usual?
Use https://webhook.site/. It provides a unique json receiver for you that shows your http requests.
Here's two sites you can try for your requests:
https://www.hurl.it
http://gurujsonrpc.appspot.com
Here is the link which i use to parse the json data i get from services.
All you have to do is to copy the json and paste in it, it will give you a very clear preview of the data.
json parser

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.

Using Rest assured to validate saved JSON response

I have a question regarding REST Assured. - https://code.google.com/p/rest-assured/wiki/Usage
I understand that I can use REST assured to make HTTP calls(.get .put etc.) and validate the response using when() etc. I would like to validate JSON responses that I have already saved in the database, instead of Calling the web service realtime and validating it's response.
Can I use REST-assured to Load a JSON response as a String and validate it?
Yes you can use Rest Assured's JsonPath project independently of Rest Assured (see getting started page). Once you have it in classpath you can do something like this:
JsonPath jsonPath = new JsonPath(<your json as string>);
String title = jsonPath.getString("x.y.title");