Terminal tells there is an issue with perl script - html

I started facing issue with one of our perl script which was working fine till last month. Can someone help me with this?
malformed JSON string, neither array, object, number, string or atom, at character offset 0
(before "<!doctype html><html...") at ad_lib.pm line 985.
and below is my line
my $response = from_json(qx{$BASE_HASH{CURL} -X GET -H "Content-Type: application/json" -H "Authorization:Basic $encoded" "https://localhost:9090/nwrestapi/v2/global/protectiongroups/" -k -1 2>/dev/null});
encode is used as below
my %BASE_HASH = ();
read_config(\%BASE_HASH);
my $encoded = MIME::Base64::encode($BASE_HASH{NW_USER} . ":" . $BASE_HASH{NW_PW});

It looks like the response you're getting from your HTTP request used to be a JSON string and is now an HTML document.
from_json is trying to decode it as a JSON string but failing because what it finds is neither an array, object, number, string, or atom: it's HTML.
So the problem is more likely with your external service (the one you're talking to) than with the Perl script you're using. Which also might explain why it started failing all of a sudden.

Seems to be the newer version of application has little advanced version of SSL and it is unable to decode the username/password. Instead of $encoded i have passed the chunked/decoded value to the file and scripts are working fine.
Only difference i found with old and new version when executing the script is SSL version.
on system with old app version: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
On system with new app version: TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
Need to figure out whats wrong with $encoded and how to pass on the values, may be quotes etc.

Related

drupal 7 services rest not returning json

I have created a webservice successfully and I can call it , but it returns XML always. I tried adding .json at the end of the url and 'accept: application/json' header, but when I call these, it returns blank with a 200 response.
The configuration done (admin/structure/services) is:
edit tab: created a rest service with "path to endpoint" = loginapi & debug enabled
server tab: response formatters & parsing are all checked (including json)
resources tab: everything under user is checked without any alias
domain.com/loginapi/user/login --> this works perfect & I can login and returns xml, adding .json (login.json) returns nothing
How can I make this work please? I've went through all docs & examples, but none work for me
thanks
Check your server configuration is as follow: Services API
Then validate your endpoint with curl -H "Accept: application/json" -i https://your.domain/endpoint. Return header should have Content-Type: application/json
To return JSON from Drupal, check the drupal_json_output function (It sets the HTTP Content-Type header for you). Pro Tip: If your endpoint is defined through hook_menu, you can add 'delivery callback' => 'drupal_json_output' to your menu item to tell Drupal that your page callback's return value should be converted to output.
However, this doesn't work if your menu item has an 'access callback'. For some technical reason inside of Drupal core, a 3 gets returned instead of a 403 status if the access check fails. I wish I could remember how I solved that when I first figured it out half a year ago :-(

Newman CLI treating strings in CSV differently from POSTMAN - parsing failure

Newman Version (can be found via newman -v): 4.2.2
OS details (type, version, and architecture): Windows 10 Pro Version 1803 Running all files locally, but hitting internal API
Are you using Newman as a library, or via the CLI? CLI
Did you encounter this recently, or has this bug always been there: This is a new collection
Expected behaviour: I need to use a CSV file to import data into the response body of POST requests. All values MUST be strings. My CSV works correctly in POSTMAN, but fails with error: Invalid closing quote at line 2; found """ instead of delimiter "," in NEWMAN.
Command / script used to run Newman: newman run allPatients.postman_collection.json -e New_QA.postman_environment.json -d 2.csv
Sample collection, and auxiliary files (minus the sensitive details):
In POSTMAN, when I run the requests, all values are strings and must be surrounded by doubled quotes. I use a CSV file that looks like this:
"bin","pcn","group_id","member_id","last_name","first_name","dob","sex","pharmacy_npi","prescriber_npi"
"""012353""","""01920000""","""TESTD 273444""","""Z9699879901""","""Covg""","""MC""","""19500101""","""2""","""1427091255""","""1134165194"""
When I run the same CSV data file in NEWMAN, I get the error above. I have tried a few options I've seen on this forum without any luck such as using Escape syntax for double quotes such as:
"/"text/""
The only things I've tried that have not failed pre-run with an error like above include removing the double-quotes entirely or replacing them with single-quotes. When I do this, I get 400 Bad Request, which I suspect is due to me sending invalid data-types.
Please close this issue. It was the result of human error.
I was able to fix this by correctly using the syntax suggested elsewhere.
"bin","pcn","group_id","member_id","last_name","first_name","dob","sex","pharmacy_npi","prescriber_npi"
"\"012353\"","\"01920000\"","\"TESTD 273444\"","\"Z9699879901\"","\"Covg\"","\"MC\"","\"19500101\"","\"2\"","
\"1427091255\"","\"1134165194\""

HTTP request error from running Postman Collection tests with Newman?

I've been using the new commandline for Postman, Newman, and have been attempting to run Collection tests that work fine when I pass them through the packaged app Jetpacks add-on, but do not run properly in the commandline. Although the json Collection file that I am passing does contain the proper header declarations, I don't have any other clues at this point, so I suspect that this may be an HTTP header issue. But I am not sure exactly what is wrong, as I am rather new to using Postman.
The tests that I'm trying to run are on some calls to an ASP.Net web API, very simple server response-checking one-line javascript tests like the ones in this tutorial.
A sample line that I enter into the console:
$ newman -c collectionfile.json -e environmentfile.json -n 5
achieves such a result:
RequestError: [token] terminated. Error: undefined
Any suggestions/help would be appreciated.
I ran into this problem as well and spent quite a few hours trying to figure it out. Eventually I realized that an address such as "www.google.com" will work in the chrome plugin UI, but not in Newman. For it to work in Newman, the address must be "https://www.google.com". Also, make sure that you have your data file (if you are using variables like {{url}}) set up correctly. You can use "-d dataFile.json" to define a data file. More information on that here.

How to do a REST api call (PUT method with JSON) in C#?

I'm using Jenkins as an continuous integration tool. I'm using the Jira plugin for it so it can update the issues in Jira. But there is something missing there, you can't update the description of the version with it. I decided to do it anyway, using Jira REST api.
I found a very easy way to do it with curl, in one line :
curl -i -u user:password -H "Content-Type: application/json" -X PUT --data '{"name":"V55"}' http://jira/rest/api/latest/version/10107
As you can see, there are 2 parameters I need to get before calling it (the data and the url), and this is where things get complicated.
I can get the data with Jenkins easily, the problem is about the url. The version (in the example, 10107) is a string you need to retrieve using a GET request, and then parse the result (it's JSON). Once again, really easy in curl :
curl -i -u user:password -H "Content-Type: application/json" -X GET http://jira/rest/api/latest/project/SBX
So basically, what I need is to parse the result to get the version, and then call my PUT.
And I can't manage to do that. I've tried in ANT, I manage to parse the JSON, but it won't let me call my curl line because of the quotes. I tried with groovy script in ANT, but it fails to load the groovy library. (And I already spent 4 days on it)
Now I want to do it in C# (knowing i'm not familiar with webservices), but every time I find an example of how to do it, something goes wrong. Sometimes it doesn't have authentication, and sometimes visual studio is making jokes.
I followed this tutorial which is really clear: http://channel9.msdn.com/shows/Endpoint/endpointtv-Screencast-Consuming-REST-services-with-HttpClient/ but when I replace httpclient.post with httpclient.put, it shows me what it expects as arguments, and when I write the ; to finish the line, VS2012 underlines it in red saying "Microsoft.http.HttpClient" doesn't contain a definition for 'Put'.
TL;DR :
I'm looking for an easy way to implement a PUT request on a REST service with data in JSON. Be it in ANT or in C#. Thanks.
Edit :
This is what my code is looking like right now :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RestSharp;
namespace jira_rest_api_test
{
class Program
{
static void Main(string[] args)
{
RestClient Client = new RestClient
{
BaseUrl = "http://jira/rest/api/latest/",
Authenticator = new HttpBasicAuthenticator("user", "password")
};
RestRequest request = new RestRequest("version/10107", Method.PUT);
request.AddHeader("Accept", "application/json");
request.AddHeader("Content-Type", "application/json; charset=utf-8");
request.RequestFormat = DataFormat.Json;
request.AddBody("{\"name\":\"v23\"}");
var response = Client.Execute(request);
Console.WriteLine(request.JsonSerializer.ContentType);
Console.WriteLine(request.Resource);
Console.WriteLine(request.Parameters.Count);
Console.WriteLine(response.Content);
}
}
}
And this is the error I get:
{"errorMessages":["Can not instantiate value of type [simple type, class com.atlassian.jira.rest.v2.issue.version.VersionBean] from JSON String; no single-String constructor/factory method"]}

Correct JSON Feeds context within Drupal

I'm trying to access Crunchbase data via their API using JSON, and import into a Drupal site.
I'm using this URL: http://api.crunchbase.com/v/1/company/facebook.js?api_key=tw8xtspmfdsce6q5acwdzwwh
Which I can successfully see the results of at: http://jsonviewer.stack.hu/
But when I configure the Feeds JSON Path Parser module what "context" should I use to access the information?
I've tried:
$
$.
$..
.
..
$*
$.*
$..*
But they all return an empty results "context: " - as if no data has been accessed. Any thoughts?
My JSON string lacked any "context" as well. This worked for me...
$.[*]