am trying to create a web interface to interact with OVH's telephony API ovh telephony api using the official JAVA wrapper OVH java wrapper.
I am trying to use a GET endpoint with parameters. this is the endpoint:
GET /telephony/{billingAccount}/line/{serviceName}/statistics
Parameters:
timeframe: string;
type : string
This is how I am doing the call:
api.get("/telephony/{myBuildingAccount}/line/{myServiceNumber}/statistics", "timeframe=daily&type=maxDelay", true);
But I am getting an error 400 bad signature.
Could someone help me with this ?
The API of the java wrapper specifies that the api.get method receives as the second parameter (in the three parameters version of api.get) the GET body; but you are passing a string containing the URL parameters:
api.get("/telephony/{ACCT}/line/{NUM}/statistics", "timeframe=daily&type=maxDelay", true);
Since the request you need does not require a body and does require the parameters in the URL, you need to use the following invocation:
api.get("/telephony/{ACCT}/line/{NUM}/statistics?timeframe=daily&type=maxDelay", true);
Pay attention that {ACCT} and {NUM} must be replaced by the actual account and service number values in that first string. Also, notice the parameters are appended directly into the string URL.
Hope this helps.
Related
I need to send a dynamic number of POST parameter values to an endpoint (there could be 1 or there could be 50). All of them will have the same key value.
Is this possible? I can't seem to figure out how to create a RequestBody that encompasses something like this, even when I try to construct it in plain text.
I have the list of strings prepared for it, but I just don't know how to create this kind of thing. The endpoint works in PostMan when I input a lot of post form parameters with the same key value, so the endpoint is setup properly for it. I'm just not sure if Retrofit supports this kind of thing, and I cannot seem to find any info around it.
I'm currently working with Java instead of Kotlin. Thoughts?
You can also pass multiple field parameter to your request like this:
#FormUrlEncoded
#POST("/oauth/access_token")
Call<YourResponseObject> sendData(
#FieldMap Map<String, String> params
);
The map can take variable number of args.
So you can pass data like:
/*
map = { "field1_key"="value1", "field2_key"="value2", "field3_key"="value3", ...}
*/
retrofit().create(YourInterface.class).sendData(mapOfFields)
p.s: retrofit() is a method that returns a Retrofit instance to work with.
I'm trying to set parameters inside my EventInput object, in order to send it inside my QueryInput and detect the Intent. I'm using DialogFlow V2Beta1 API for Java version com.google.cloud:google-cloud-dialogflow:0.85.0-alpha. I'm aware of the json expected format based on
Custom Events documentation, but all method available didn't work for me. Related question for other languages didn't awnser it either: set parameters in EventInput in Dialogflow V2 API. I'm losing something about protobuf pattern?
My parameters are the following:
I've already tried the below code, but it doesn't work, the response from server always asks "What is the location_user?", meaning that the parameter is missing. On DialogFlow V2 happens the same issue.
queryInput = QueryInput.newBuilder()
.setEvent(
EventInput.newBuilder()
.setName("REVISION")
.setParameters(
Struct.newBuilder()
.putFields("location_user",
Value.newBuilder()
.setStringValue("Campinas")
.build())
.build()
)
.setLanguageCode(config.getLanguage()
)
)
.build();
output json:
name: "REVISION"
parameters {
fields {
key: "location_user"
value {
string_value: "Campinas"
}
}
}
language_code: "pt-BR"
Your code seems to be correct.
The problem is in your Intent configuration.
from dialogflow docs:
To reference an event parameter in the parameter table or a response,
use the following format: #event-name.parameter-name.
In your example: put #REVISION.location_user in Value column in Parameters table.
I've checked your code and it works, please find my Intent configuration below
sample intent
Hi I am new Rest and was developing API where in request parameters i get comes from client and it is different each time. I will then have to call another API. I want to write one method to get JSON data from 3rd party API. I checked online and all examples were same. I am using Unirest follpwing is what I have done
HttpResponse<JsonNode> response = Unirest.get("https://api.stackexchange.com/2.2/questions").
header("accept", "application/json").
queryString("order","desc").
queryString("sort", "creation").
queryString("filter", "default").
queryString("site", "stackoverflow").
asJson();
Currently I have written all the queryString values.
Is there a way I can dynamically do this like put it in a map and give it to the method.
Yes, you can pass it a Map (Java source). The method signature is
public HttpRequest queryString(Map<String, Object> parameters)
How can one specify a custom object as a parameter for the web-service's method when invoking through SOAP message?
Say I have this code:
SOAPElement operation = body.addChildElement("MyMethod", "", trgNamespace);
SOAPElement value = operation.addChildElement("arg0");
value.addTextNode("i need to send here a custom object not a string")
request.saveChanges();
The addTextNode sends a string whereas I need to send my own object as a parameter for invocation.
You have to serialize your object to transfer it over the line. Serialization is often done using XML or JSON, see the following link for details: http://en.wikipedia.org/wiki/Serialization
That should get you on the right path.
Maybe try higher level and use wsdl-based stubs generator for java? It's Axis wsdl to java
I could think of another approach
You can send that custom object as a binary data (I assume your object is serialize-able). Then encode that data in say Base64 encoding.
There is similar problem asked earlier. Plz check out this link. This seems most relevant to your problem.
Another link mentioned in the above posting gives nice overview of handling these type of problems in general.
I'm trying to read the query arguments of the URL in client side Java code, but I can't figure out how to find the current URL in Java.
When I tried using httpServletRequest as recommended in this question, it says that it cannot be resolved and it doesn't offer adding an import statement.
I'm using Google Web Toolkit with Google App Engine.
Look at Window.Location:
public static class Window.Location
This class provides access to the browser's location's object. The location object contains information about the current URL and methods to manipulate it. Location is a very simple wrapper, so not all browser quirks are hidden from the user.
There are a number of methods to retrieve info about the URL, including one to get the whole thing (getHref()) or get the constituent components (e.g. getProtocol(), getHost(), getHostName(), etc).
Since you say you want to read the query arguments, you probably want one of these:
static java.lang.String getQueryString()
Gets the URL's query string.
static java.lang.String getParameter(java.lang.String name)
Gets the URL's parameter of the specified name
static java.util.Map<java.lang.String,java.util.List<java.lang.String>> getParameterMap()
Returns a Map of the URL query parameters for the host page; since changing the map would not change the window's location, the map returned is immutable.