Unable to invoke Rally LBAPI WS from ruby rest-client program. Any - ruby

I have been able to query rally analytics API using DHC(Dev HTTP Client) with the following POST request
http://rally1.rallydev.com/analytics/v2.0/service/rally/workspace/1234/artifact/snapshot/query.js&API_Key=key123
and body
{
"find": {
"ObjectID": 4321
}
}
Is there any way I can do this from Ruby? I have using 'rest-client' but am only getting errors endlessly (400, 403, ....)
Has anyone been able to do this ?
Is this possible using curl?

It's possible using both curl and ruby. You need to set a ZSESSIONID header value equal to your API Key. Curl example here (randomized Workspace OID and API Key):
curl -X POST \
'https://rally1.rallydev.com/analytics/v2.0/service/rally/workspace/12345678910/artifact/snapshot/query' \
-H 'content-type: application/json' \
-H 'accept: application/json' \
-H 'ZSESSIONID: _m31qjdm43Ou74h0cACk28zgBUOPm50Xtna2PhQ2L22' \
--data '{"find":{"FormattedID": "DE9", "__At": "current"},"fields":true,"start":0,"pagesize":10,"removeUnauthorizedSnapshots":true}' \
--compressed
It is fairly straightforward to do in Ruby also. The following Gists:
Rally Lookback Connection Helper
Rally Lookback Query Example
Contain a Ruby connection helper for connecting to Rally's Lookback API. The second Gist contains an example of using the connection helper along with a hash representing a find query object. The Ruby example uses httpclient gem as opposed to rest-client gem, but the concept is the same.

Has this API changed ? We had a change in our username recently and since then, running the Query example returns {"_rallyAPIMajor":"2","_rallyAPIMinor":"0","Errors":["Not Found"],"Warnings":[]}
for all the queries.

Related

How to know if graphql returned an error when using curl?

HTTP GraphQl calls always return 200 - even if the response doesn't suite the request.
I'm trying to do a graphql call and understand if there's an error, like using $? and --fail but it doesn't help because of the always 200 response.
Even if graphql's output isn't according to input and contains error arrays, curl only cares about the http code, which is always 200.
Is there a way for curl to understand a graphql error? Like some kind of built in mechanism in to compare requested input to actual input and understand there's an error?
Perhaps I'm barking on the wrong tree here and should use some command line tool more dedicated to graphql? Thanks.
curl doesn't know anything in particular about GraphQL. You can pipe the output of curl to grep to check for the presence of errors and draw conclusions based on that as necessary.
ex:
curl --request POST \
--header 'content-type: application/json' \
--url http://localhost:4000/ \
--data 'your query data'| grep "errors"

Google People API - get contact details (batch)

Using Google People API, one can get a contact detail by its ID.
"https://people.googleapis.com/v1/" + id + "?key=" + <KEY> + "&personFields=addresses,clientData,emailAddresses,names,organizations,phoneNumbers,birthdays",
Is it possible to get such details in batch? I have a list of 100 contact ids and I want them to get at once as it'd be much faster.
In your situation, how about using the method of "Method: people.getBatchGet"? When this method is used, the 200 resource names (maximum number) can be retrieved by one API call. When this is used for your situation, it becomes as follows.
Sample curl command:
curl \
'https://people.googleapis.com/v1/people:batchGet?personFields=addresses%2CclientData%2CemailAddresses%2Cnames%2Corganizations%2CphoneNumbers%2Cbirthdays&resourceNames=people%2Fsample1&resourceNames=people%2Fsample2&resourceNames=people%2Fsample3' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--compressed
In above case, the unencoded endpoint is https://people.googleapis.com/v1/people:batchGet?personFields=addresses,clientData,emailAddresses,names,organizations,phoneNumbers,birthdays&resourceNames=people/sample1&resourceNames=people/sample2&resourceNames=people/sample3.
Also, you can test this with "Try this API". Ref
Reference:
Method: people.getBatchGet

Load GeoJSON file into Apache CouchDB

I am working on Windows10 and tried to load a geojson file into my couchdb via the "curl" command and a POST request in the cmd which looks like that:
C:\Program Files\cURL\bin>curl -d #path-to-my-data\data.geojson -H "Content-type: application/json" -X POST http://127.0.0.1:5984/_utils/database.html?-dbName-
and then I get the following error:
{"error":"method_not_allowed","reason":"Only GET,HEAD allowed"}
On http://couchdb-13.readthedocs.org/en/latest/api-basics/ it is said, that "If you use the an unsupported HTTP request type with a URL that does not support the specified type, a 405 error will be returned, listing the supported HTTP methods."
When I try that with a PUT request, I get the same error.
I validated the json with jsonlint so this should not be the problem.
I tried several tutorials like "Three Steps to CouchDB Heaven …" or "Export & Import a Database with CouchDB" but none of them seems to work.
So I am not sure, where the problem is. Do I need to make changes in my geojson file, or something else?
thanks for your help
The needed curl command just looks like that:
curl -H "Content-Type: application/json" -X POST http://localhost:5984/db -d #C:\Users\Name\Desktop\data.geojson

Ruby GET request with headers and data?

This is a cUrl command I want to do in Ruby
curl --get 'https://api.twitter.com/1.1/statuses/user_timeline.json' --data 'screen_name=example' --header 'Authorization: OAuth oauth_consumer_key="example", oauth_version="1.0"' --verbose
So far I only know how to GET requests using Net::HTTP but these don't have headers and data like the cUrl command above.
It would be great if someone could tell me how to GET in Ruby with headers and data.
If you don't mind using additional GEMS, try UniRest

How do I send multiple payloads at once to SendGrid's API in Ruby?

From following their API docs, the curl command to interact with their API should look something like this:
curl -X POST https://api.sendgrid.com/apiv2/reseller.manage.json \
-d api_user=reseller#company.com \
-d api_key=XXXXXXXX \
-d user=reseller_customer#company.com \
-d password=customernewpassword \
-d confirm_password=customernewpassword \
-d method=password
How do I write that in Ruby?
You'll want to look at the RestClient gem. It makes it easy to send requests like this.
https://github.com/rest-client/rest-client
You could use the SendGrid API by using ruby to curl the url. If you aren't constrained to using curl, you should take a look at the official ruby gem though https://github.com/sendgrid/sendgrid-ruby
Use the Sendgrid SMTP API, there are code examples in their docs; see here for example, https://sendgrid.com/docs/Integrate/Code_Examples/ruby.html.

Resources