I am new to azure iot. and i am trying to create shared access policies in azure iot hub using its rest api.
https://management.azure.com/subscriptions/{subscription-Id}/resourceGroups/{group-name}/providers/Microsoft.Devices/IotHubs/{hub-name}?api-version=2016-02-03");
and my java code is
String policyold = "{\"tags\" : {}, \"location\": \"East Asia\",\"properties\" : \"authorizationPolicies\" : [{\"name\" : \"policy-namw\", \"primaryKey\" : \"{mykey}\" ,\"secondaryKey\" : \"secondary-key\" ,\"permissions\" :[\"ServiceConnect\" ,\"RegistryRead\" ,\"RegistryWrite\" ,\"DeviceConnect\"]}],\"eventHubEndpoints\" : { \"events\" : {\"messageRetentionInDays\":\"2\"}}}";
StringEntity input1 = new StringEntity(policyold);
input1.setContentType("application/json");
input1.setContentEncoding("UTF8");
put.setEntity(input1);
put.setHeader("Authorization", token);
HttpResponse r2 = httpclient2.execute(put);
System.out.println(r2.getStatusLine());
String content2 = EntityUtils.toString(r2.getEntity());
org.json.JSONObject recvObj2 = new org.json.JSONObject(content2);
but i am facing the followiing error.
HTTP/1.1 400 Bad Request {"error":{"code":"InvalidRequestContent","message":"The request content was invalid and could not be deserialized: 'Error converting value \"authorizationPolicies\" to type 'System.Collections.Generic.Dictionary`2[System.String,Newtonsoft.Json.Linq.JToken]'. Path 'properties', line 1, position 76.'."}}
Moreover i am using this tutorial.https://msdn.microsoft.com/en-us/library/mt589015.aspx
Can any one help me in solving this?
According to the offical document Common error codes for Azure IoTHub, the error code 400 means "The body of the request is not valid; for example, it cannot be parsed, or the object cannot be validated.".
I checked the policyold string value in your code, then I found the json string missed the required elements Sku name & Units. Please carefully see the table of the elements below the end of the Json request content.
An Azure IoTHub can own multiple shared access policies.
So if creating shared access policy while creating new IoTHub, please use the REST API Create a new IoT Hub, else use the REST API Update metadata on an existing IoT Hub to add a new one for an existing IoTHub.
Related
I have a problem when trying to retrieve data from Manage Price Quote Details (PriceQuoteServicesRQ) 4.10 Sabre SOAP API.
I generated Java classes using the WSDL from Sabre website (https://developer.sabre.com/docs/soap_apis/air/fulfill/manage_price_quote_details/resources).
I am constructing my request object in a following way:
ReservationTypeShort reservation = new ReservationTypeShort();
reservation.setValue("YEZUYS");
PriceQuoteInfoSearchParameters info = new PriceQuoteInfoSearchParameters();
info.setReservation(reservation);
PriceQuoteSearchParameters searchParameters = new PriceQuoteSearchParameters();
searchParameters.getPriceQuoteInfo().add(info);
searchParameters.setResultType(StringResultType.S);
GetPriceQuoteRQ req = new GetPriceQuoteRQ();
req.setSearchParameters(searchParameters);
req.setVersion("4.1.0");
I pretty-printed the object and this is what I got:
"priceQuoteInfo" : [ {
"reservation" : {
"value" : "YEZUYS",
"createDate" : null
},
"status" : [ ],
"type" : null,
"priceQuote" : [ ],
"travelItinerary" : null
} ],
So according to their documentation:
I am supplying all fields that are necessary, however it still doesn't work for me.
Did anybody else had the same problem? What am I missing/what am I doing wrong?
This is the error message I am getting:
XML request schema validation failed: PriceQuoteInfo element is not complete. One of the following fields: Status, Type, PriceQuote, TravelItinerary should be used. Please amend your request and try again.
What I have tried so far?
I asked Sabre Support for help, but they responded with a message that basically says "it works on my end".
I intercepted the XML body:
<ns5:GetPriceQuoteRQ version="4.1.0">
<ns5:SearchParameters resultType="S">
<ns5:PriceQuoteInfo>
<ns5:Reservation>YEZUYS</ns5:Reservation>
</ns5:PriceQuoteInfo>
</ns5:SearchParameters>
</ns5:GetPriceQuoteRQ>
I was missing an empty element <PriceQuote/> in my request.
It can be added by doing:
PriceQuoteInfoSearchParameters info = new PriceQuoteInfoSearchParameters();
info.setReservation(reservation);
info.getPriceQuote().add(new PriceQuoteSearch());
So according to their documentation I am supplying all fields that are necessary [...]
By documentation do you mean the WSDL or some human readable documentation (like PDF, DOCX, web pages, etc)? According to the error message you get, your SOAP request isn't valid. Sabre Support responding with "it works on my end" is another way of saying that you are not doing something correctly on your end. You need to troubleshoot your request.
From what I see, the error message is saying Status, Type, PriceQuote, and TravelItinerary but you are sending status, type, priceQuote, and travelItinerary. XML is case sensitive, and it's possible the service field names are too, so this might be the first thing to check.
Then, two of your fields (type and travelItinerary) are null. Also, priceQuote is empty. Is that OK? This is the next thing to check.
The object you pretty-printed shows a JSON format. Is this actually the format you are sending on the wire to the service? SOAP wants XML, not JSON. You also mention you generated the code from the WSDL. Using what framework or library? Does the generated code send XML?
Like I said, you need to troubleshoot the call:
download SoapUI
feed the WSDL file to SoapUI so that it can generate sample requests for you
fill in those request with real data and make calls to the web service until you get back a successful and expected response
using the same parameters from 3) in your code, perform the same call using your code
use SoapUI's monitoring tools to intercept the request at 4) and inspect the SOAP message you are sending
check the request you are making with your code against the successful request you got by using SoapUI directly
correct any differences until your request made by code is like the one send from SoapUI and it returns a successful and expected response.
how can I access a custom header from a server response when using TransferManager ?
we have a custom header added in the response from our server, from the client side we use multi part upload with default transfer manager
any suggestion how in how i could hook up it ?
so basically i want to pass over the response from the return response.getAwsResponse(); found in the class: AmazonS3Client on the method
private <X, Y extends AmazonWebServiceRequest> X invoke(Request<Y> request,
HttpResponseHandler<AmazonWebServiceResponse<X>> responseHandler,
String bucket, String key, boolean isAdditionalHeadRequestToFindRegion) {
that response will have the HTTP response from the server containing the custom heather which I'm after, basically is a unique Id send back when the file was 100% completed so than i can manipulate it.
I need to pass over this custom header from the response to the very beginning where I use the transfer manager and the upload.waitForCompletion(),
also i don't want to edit the amazon's,
so does anyone know if there is an interface or some other object which provides me access to it ?
After some debug into the framework I strongly believe that there is no way to have access to the http response when using the TransferManager
for what we are trying to do we need to send an unique id from the server to the client when the file upload is completed and assembled
** therefore if you don't mind in do not use the beauty of the TransferManager you could write "your own TransferMananger" than you will have full control, but again on the client side we don't really want to add custom code but have a standard and simple approach (but that is for my scenario), if you decide to do it manually it can be done I have already tried and works !
So as a alternative we though in send from the server via the eTag, which is not great but will do the job and will keep the client side simple and clean
Any suggestion in how to send this value back in a better way ?
Upload up = tm.upload(bucketName, file.getName(), file);
UploadResult result = (UploadResult) ((UploadImpl) up).getMonitor().getFuture().get();
String uniqueIdFromServer = result.getETag();
I am working on Google Sheets <-> Salesforce integration and developing it in Salesforce programming language - Apex on Force.com platform.
Currently I am attempting to connect to Google Sheets API. I am using Service Account Key, so Salesforce can pull the data from Google Sheets without the requirement for manual authorisation every time it sends out a query.
I am at the point where I set up the Service Account Key and I am successfully sending a request to it to obtain the access_code.
Then I am attempting to query the API, using the following class:
/****** API CALLOUT *******/
public static HttpResponse googleSheetsCallout (){
//the below line provides a string containing access token to google
string accessCode = getAccessToken();
//I found this endpoint structure online, this may be why my script
//isn't working. However, I am struggling to find the alternative.
string endpoint = 'https://sheets.googleapis.com/v4/spreadsheets/params=[SPREADSHEET ID GOES HERE]/values/[RANGE GOES HERE]?access_token=';
httpRequest req = new httpRequest();
req.setEndpoint(endpoint+accessCode);
req.setMethod('GET');
req.setTimeout(120000);
httpResponse res = new http().send(req);
System.debug ('res is ' +res);
return res;
}
When I run the function this is what the log returns:
|CALLOUT_RESPONSE|[71]|System.HttpResponse[Status=Forbidden, StatusCode=403]
|USER_DEBUG|[72]|DEBUG|res is System.HttpResponse[Status=Forbidden, StatusCode=403]
I enabled Google Sheets access in the google developer console menu, and what's interesting is when loking at the console it appears that Google notices API requests being sent out (they are appearing on the activity chart).
I solved it, and the issue was not the code itself.
The problem was sharing my sheet. To allow read/edit access to your sheet from the service account it must be shared with the Service Account ID email address, the same way it's shared with any other user. If this isn't done the script will produce 403 error.
Hi My code for the same is
// Initialize Web Service
HandlerResolver handlerResolver=new AwsHandlerResolver(credentials.getAWSSecretKey());
AWSECommerceService service = new AWSECommerceService();
service.setHandlerResolver(handlerResolver);
// Create Web Service Connection
AWSECommerceServicePortType port = service.getAWSECommerceServicePort();
// Add Parameters for the Item Lookup
ItemLookupRequest itemLookup = new ItemLookupRequest();
itemLookup.setIdType("ASIN");
itemLookup.getItemId().add("B000RE216U");
// Wrap Request in Lookup Body
ItemLookup lookup = new ItemLookup();
lookup.setAWSAccessKeyId(credentials.getAWSAccessKeyId());
lookup.getRequest().add(itemLookup);
ItemLookupResponse response = port.itemLookup(lookup);
System.out.println("response: " + response.toString());
I keep getting the error cannot convert from Void to AWSECommerceService in the beginning. I have the AWSHandlerResolver file and codec jar installed and configured.
Error Message:
Exception in thread "main" javax.xml.ws.WebServiceException: {http://webservices.amazon.com/AWSECommerceService/2010-11-01}AWSECommerceService is not a valid service. Valid services are: {http://webservices.amazon.com/AWSECommerceService/2011-08-01}AWSECommerceService
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:223)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:168)
at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:96)
at javax.xml.ws.Service.<init>(Service.java:77)
at com.ECS.client.jax.AWSECommerceService.<init>(AWSECommerceService.java:46)
I have been searching online. I might have to change target namespace for AWSECommerceService. But cannot find how. Please help me
You are using the wrong namespace (actually, the wrong version of WS) for your Webservice client and its port.
Go to AWSECommerceService and AWSECommerceServicePortType classes and replace all namespaces which look like http://webservices.amazon.com/AWSECommerceService/2010-11-01 with http://webservices.amazon.com/AWSECommerceService/2013-08-01.
In a Google App Engine for Java web app, I am trying to use the low level api to invoke an XML RPC ...After looking at the docs, I figured out the following code to connect using low level API-the reason why I want to use Low Level API is so that I can set the timeout value myself--
String mrtime="120";
java.lang.Double maxresponsetime;
maxresponsetime = Double.valueOf(mrtime).doubleValue();
HTTPRequest req= new HTTPRequest(url, HTTPMethod.GET, disallowTruncate().setDeadline(maxresponsetime));
HTTPResponse response= com.google.appengine.api.urlfetch.URLFetchServiceFactory.getURLFetchService().fetch(req);
String line="";
String resp="";
resp=new String(response.getContent(), "UTF-8");
The above code is suitable for a scenario where the remote URL is accessed by GAE...However I have to also send an XML message containing name of function as well as input parameters (these are stored in variable named 'message')... How do I send that message to the remote URL, and after that obtain the response?
You should post the call method and parameters instead of GET. The method name and parameters go as XML.
See this http://xmlrpc.scripting.com/spec.html