I'm learning how to use a third party API called Wunderground and I don't know how to request, receive, and use their results which is in a Json format.
If you see their website a developer can sign up for free and receives an API KEY. You can then request weather data in the following URL format.. http://api.wunderground.com/api/KEY/FEATURE/[FEATUREā¦]/[SETTINGā¦]/q/QUERY.FORMAT
So I have tried it in my web browser by typing some parameters and I received a very long Json file with the correct information (I checked). Problem is I don't have the slightest idea of how to create a variable which can make this request, and even if I was able to do that I don't know where should I receive the file and how to get only the results I want (in this case current weather).
You have to use Titanium.Network.HTTPClient to make request.
For code examples related to Json parsing you can use:
Appcelerator: Using JSON to Build a Twitter Client
HTTPClient()
Related
Just started working on an existing project making use of the Exact Online API.
While I was debugging the project I suddenly only started receiving XML results instead of JSON results from the API. I did not change anything about the endpoints being queried I was just running the existing queries trying to figure some things out.
These are the REST API docs: https://start.exactonline.nl/docs/HlpRestAPIResources.aspx
These are the XML docs: https://support.exactonline.com/community/s/knowledge-base#All-All-DNO-Content-xmlsamplecode
Typical REST API endpoints look like this:
https://start.exactonline.be/api/v1/xxxxxx/salesinvoice/SalesInvoices
Typical XML endpoints look like this:
https://start.exactonline.be/docs/XMLDownload.aspx
I also did not change any settings. I only have access to the tokens and api. I don't have access to the account.
This is an example of an endpoint and query where I previously received JSON but am now receiving XML:
https://start.exactonline.be/api/v1/xxxxxx/salesinvoice/SalesInvoices?$filter=InvoiceID eq guid'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx'&$select=InvoiceID
I tried this manually with Postman and also using the existing code from the project.
Is there some setting I am unaware of? Am i querying the wrong way? Maybe there have been some changes to the API I am unaware of that aren't listed in the release notes?
Please provide the request header Accept in your HTTP request that specifies what content format you prefer to receive: application/json. The default of Exact Online APIs is XML (but seldom to never used).
Bottom line is that I'm trying to download my order history data from Lowes.com. I'm assuming there's an API endpoint that can be used but I haven't figured out the method or maybe what parameters need passed to get a successful request.
I looked at using python and scrapy but I don't believe the format of the webpages are going to be easy to parse the data.
I have found references to APIs in some of the javascript code for the website and the mobile app. Some of the relevant urls I've found:
From website -
ORDER_HISTORY_USER: '/wcs/resources/store/%0/member/%1/orderhistory/v1_0' (from function named Conduit on www.lowescdn.com)
From mobile app:
"url": "https://lwssvcs.lowes.com/IntegrationServices/resources/mylowes/user/order/list/v1_0"
"url": "https://lwssvcs.lowes.com/IntegrationServices/resources/mylowes/user/order/instore/v1_0"
So far I've only attempted to use these links via a browser after logging into my account. Assuming I'm on the right path, what method should I use to successfully get the data?
Recently, Iv'e been using the Joi validation library in-order to validate the data which comes in from a request (building a RESTful API).
I was using the .label() method to generate a string response and send it back to the user, but I couldn't find any way to send a JSON response back to the user?
Tried sending a premade JSON inside the string, searching the documentation and the internet of course - couldn't find any mention of it.
Current code example:
textField: Joi.string().required().max(4).label("This example field didn't pass the testing phase, please try again)"),
Any ideas?
If you need to send data in case of error,try .error() method. you can pass error in it.
I'm writing a RESTful web application where I need to provide the service of uploading images for a user. Currently, I have been able to upload an image from my current machine but I need to send it as JSON data over the web through the REST protocol.
In the server, there is a Java application running Jax-RS to manage the RESTful service. I was planning to save the JSON data that contains the image in the server and then provide a URL to the user for him to be able to locate it's image on the server.
Can someone provide some ideas on how can I do this?
If you want to send the image in a JSON object, then the image should be Base64 encoded it, or some other form of encoding. Then on the server side you will need to unmarshal the JSON and then decode back the image. You can get some ideas here on how that can be done.
Optionally, instead of doing all the converting inside the resource method (as in the example linked above), you could write a custom MessageBodyReader, where you can do the unmarshalling and decoding there.
If you decide you don't want to work with JSON, you can go the normal route and use Multipart. Depending on the implementation of JAX-RS you are using, multipart support will be different. You can see some examples (all examples have links to the official documentation)
Jersey example
Resteasy example
CXF example
There are other implementations, but I don't have examples for those. You will need to search for the documentation if you're using an implementation other than listed above.
I have an application which uploads a large file in the XML format and sometimes a zip file. Now I want to have that file transferred to other application via REST API. I am thinking to pass the binary data in to json response.
I have the following questions for my approach.
Is sending binary in json the best approach/practice to do it?
Will this be PUT scenario as receiver application doesn't know about new uploaded file?
If that makes it easier for the second service to consume it, I see no problem with it. You can send it on any format you want, as long as it's accepted and you're setting the Content-Type and Accept headers properly.
You use a PUT only when you're sending a complete replacement of the resource at the target URI. If you know the final URI for that and if a GET to the same URI right after the PUT will retrieve as response the same body you just submitted, it makes sense to use PUT, otherwise, use a POST.