Java Rest Client - Need to add local Variable in URL - rest

Rest client.
Can I add a local variable for value into URL string for a Rest client ?
Example
URL testurl = new URL("http://X.X.X.X:7001/lab2.local.rest1/api/v1/status/database?rxnum=1111");
The above works if I provide literal value for rxnum (i.e. 1111).
But I need rest client to utilize value of a local variable. exam
int rxvalue = 1111;
URL testurl = new URL("http://X.X.X.X:7001/lab2.local.rest1/api/v1/status/database?rxnum=+(rxvalue)+");
this doesn't work, obvious my URL string is incorrect. What is correct syntax to allow URL string to use value of local variable rxvalue?
thanks in advance

URL testurl = new URL("http://X.X.X.X:7001/lab2.local.rest1/api/v1/status/database?rxnum=" +rxvalue);
Simple String concatenation.

You are not building the URL string correctly. It is always a good idea to log url/print to be sure that you are creating the correct url. The problem lies in the way you are trying to concatenate the rxvalue, here is the correction in your code :
String urlString = "http://X.X.X.X:7001/lab2.local.rest1/api/v1/status/database?rxnum=" + rxvalue;
URL testurlWithString = new URL(urlString);
System.out.println(testurlWithString);

Related

URL interpolation using Uri class

I'm having an issue with the Uri class, the code below used to work before the updates but now, the issue is that it uses a String instead of a Uri URL, I've been trying to update this interpolation to the newest standard with no success. This URL is simply getting data from Firebase with tokens from users that are signed in.
final response = await http.get("$_url.json?auth=$_token");
I already managed parse the main part of the url:
Uri _url = Uri.parse("https://my-project.firebaseio.com/example");
The final result used to be something like this:
https://my-project.firebaseio.com/example.json?auth=xLwOQ2GEQxPp0h0QD1foHgSyXR52
How do I interpolate this URL properly since I have one value that isn't static? (_token)
You should use the Uri.https constructor to create the Uri you then use with get.
For example
var uri = Uri.https('my-project.firebaseio.com', '/example', queryParameters: {'auth': _token})
See Uri.http documentation

Invalid_request_parameter (create and sending envelopes)

I'm trying to use a service of DocuSign API in an abap project. I want to send a document to a specific email so it can be signed. But im getting the following error:
"errorCode": "INVALID_REQUEST_PARAMETER",## "message": "The request contained at least one invalid parameter. Query parameter 'from_date' must be set to a valid DateTime, or 'envelope_ids' or 'transaction_ids' must be specified.
I tried the following:
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = l_url (https://demo.docusign.net/restapi/v2/accounts/XXXXXX')
proxy_host = co_proxy_host
proxy_service = co_proxy_service
IMPORTING
client = lo_http_client
lo_http_client->request->set_method( method = 'POST').
CALL METHOD lo_http_client->request->set_header_field
EXPORTING
name = 'Accept'
value = 'application/json'.
CALL METHOD lo_http_client->request->set_header_field
EXPORTING
name = 'X-DocuSign-Authentication'
value = get_auth_header( ). (json auth header)
CALL METHOD lo_http_client->request->set_cdata
EXPORTING
data = create_body( ).
This is my body:
CONCATENATE
`{`
`"emailSubject": "DocuSign REST API Quickstart Sample",`
`"emailBlurb": "Shows how to create and send an envelope from a document.",`
`"recipients": {`
`"signers": [{`
`"email": "test#email",`
`"name": "test",`
`"recipientId": "1",`
`"routingOrder": "1"`
`}]`
`},`
`"documents": [{`
`"documentId": "1",`
`"name": "test.pdf",`
`"documentBase64":` `"` l_encoded_doc `"`
`}],`
`"status": "sent"`
`}` INTO re_data.
The api request to get the Baseurl is working fine. (I know the error is quite specific what the problem is, but i cant find any sources on the docusign api documentation that one of the mentioned parameters should be added to the request)
Thank you in regards
The error message seems to indicate that you're Posting to an endpoint that requires certain query string parameters -- but you're not specifying them as expected in the query string. I'd suggest you check the DocuSign API documentation for the operation you are using, to determine what query string parameters it requires, and then ensure that you're including those parameters in your request URL.
If you can't figure this out using the documentation, then I'd suggest that you update your post to clarify exactly what URL (endpoint) you are using for the request, including any querystring parameters you're specifying in the URL. You can put fake values for things like Account ID, of course -- we just need to see the endpoint you are calling, and what qs params you're sending.
To create an envelope, use
https://demo.docusign.net/restapi/v2/accounts/XXXXXX/envelopes
instead of
https://demo.docusign.net/restapi/v2/accounts/XXXXXX
Thank you for all the answers, i found the mistake. Creating the request wasn´t the problem. I was using the wrong "sending"-method -_-.
now its working :)
lo_rest_client->post( EXPORTING io_entity = lo_request_entity ).

Starring a repository with the github API

I'm trying to star a repository using the GithubAPI. This is done via a PUT request to /user/starred/:owner/:repo. I attempted to implement this feature in python using the requests library, but it isn't working. Here is a minimum working example:
The constant are defined as GITHUB_API = api.github.com, GITHUB_USER = the username of the owner of the repo to be starred, and GITHUB_REPO = the name of the repo to be starred
url = urljoin(GITHUB_API, (user + '/starred/' + GITHUB_USER + '/' + GITHUB_REPO))
r = requests.put(url,auth=(user,password))
print r.text
This code results in an error that reads:
{"message":"Not Found","documentation_url":"https://developer.github.com/v3"}
I think that I'm missing something fundamental about the process of issuing a PUT request.
The problem here is the parameters you pass to urljoin(). The first parameter is supposed to be an absolute URL, while the second parameter is a relative URL. urljoin() then creates an absolute URL from that.
Also, "user" in this case is supposed to be a literal part of the URL, and not the username.
In this case, I would forgo the urljoin()-function completely, and instead use simple string substitution:
url = 'https://api.github.com/user/starred/{owner}/{repo}'.format(
owner=GITHUB_USER,
repo=GITHUB_REPO
)

Optional slash in url of restfull controller

Is there a way to dynamically add a slash to your rest url?
e.g. I want to be able to generate the following rest urls in one resource.
rest/blogpost/1
rest/blogpost/1/allInfo
given the resource below, i can achieve my first url. But is there a way to make the second url with /allInfo (optional in same lResource).
lResource = $resource("../rest/blogpost/:blogId", {
Or do I need a second resource like this?
lResource = $resource("../rest/blogpost/:blogId/allInfo", {
The problem with the second $resource is that allInfo isn't optional
If you make your second argument optional using the : you can make it to work.
var lResource = $resource("rest/blogpost/:blogId/:allInfo");
lResource.query({});
lResource.query({blogId:123});
lResource.query({blogId:123,allInfo:'allInfo'});
See my fiddle http://jsfiddle.net/cmyworld/NnHr4/1/ ( See Console log)

Intuit - first connection

I have a question about Intuit API. I want to connect for the first time with this API. I'm using .NET SDK. I'm going througt this tutorial: http://goo.gl/PzIzoa . I don't know what i have to pass in arguments issuerId and subject (Step 1.b). I left them empty for the first try and I'm catching InvalidTokenException.
What arguments I have to pass to make it work?
Edit:
Thanks for your help, now I'm connecting via your web app.
Now I want to connect using my application. I wrote this code:
string certificateFile = "C:\\OpenSSL-Win32\\bin\\testapp1.crt";
string password = "xxx";
X509Certificate2 certificate = new X509Certificate2(certificateFile, password);
string consumerKey = "xxx";
string consumerSecret = "xxx";
string issuerId = "";
string subject = "";
SamlRequestValidator val = new SamlRequestValidator(certificate, consumerKey, consumerSecret, issuerId, subject);
After calling SamlRequestValidator constructor I'm catching InvalidTokenException. What am I doing wrong? What I have to do to make it work?
Please take a look at the following link.
https://developer.intuit.com/docs/0020_customeraccountdata/007_firstrequest
You can use apiexplorer tool to test these API calls without using devkit.
(It will ensure that your OAuth keys are working fine)
https://developer.intuit.com/apiexplorer?apiname=CustomerAccountData
You can refer the following .Net sample app as well.
https://developer.intuit.com/docs/0020_customeraccountdata/devkits/285.net_sample_app_for_cad_services
Let me know if you get any issue related to this process.
Thanks