So long story short, I am creating a java application for android and i need to access the USDA's "food data central" api. It is a REST api and I am using Retrofit to make my calls to the API. I am trying to figure out their example call to their API in the documentation but I am very new to this API stuff so I am a little lost.
They have this listed as their "Example Call"
curl -H "Content-Type:application/json"
-X POST
-d '{"generalSearchInput":"Cheddar cheese"}'
https://DEMO_KEY#api.nal.usda.gov/fdc/v1/search
I know the -X means it is a post command to the API and I believe the -d contains the request parameters but I am completely lost as to what the first line means. Also do you think the last line is the header? or the header and the endpoint. Thank you so much for looking.
Here is the link to the documentation page
What you have there is a http call being made by a tool called curl. It's just a way to make http requests via the command line. The last line is the endpoint.
Here are a few resources to get you started with curl:
The doc page for curl: https://curl.haxx.se/docs/manpage.html
Curl explained in video format: https://www.youtube.com/watch?v=7XUibDYw4mc
The first line sets the header Content-Type to the value application/json.
POST is the http method.
{"generalSearchInput":"Cheddar cheese"} is the body of the request
The last line is the URL containing a placeholder for the API key.
A raw request would look like
POST /fdc/v1/search HTTP/1.1
Authorization: Basic REVNT19LRVk6
User-Agent: curl/7.29.0
Host: localhost
Accept: */*
Content-Type:application/json
Content-Length: 39
{"generalSearchInput":"Cheddar cheese"}
Related
Summary : I am working on embedding Power BI reports in a ISV application and when i try to call api endpoint to get embedding details of the report it responds with 400 Bad Request . I am directly calling Power BI APIs without use of SDK as microsoft hasn't officially released PowerBI SDK for Java based application . Also , for debugging I used another .net application which uses PowerBI SDK to make the same API call against same workspace and it works without issues.
All other API endpoints like 'list all workspaces','get workspace details',' list all dashboards' in a workspace ' and even 'list all reports in workspace' respond as requested without issues, but the API endpoint listed here :
Power BI get report embedding details using 'workspace_id' and 'report_id'
responds with 400 Bad request with seemingly right credentials and request.
Interfacing Application Context :
The ISV application is built on Spring boot framework(Java) and Angular 2 framework .
Currently,I couldn't find official Microsoft Power BI SDK for Java based application , because of which i am directly referencing APIs from the Power BI API reference doc
ISV application has all necessary permissions to access the APIs listed here :
https://learn.microsoft.com/en-us/power-bi/developer/power-bi-permissions
The application is able to generate token,make authenticated request and get response from power bi for all other api endpoints which are used in the application .
Issue and Debugging
Debugging :
This is the request that PowerBI .NET SDK makes and which works against get report API :
GET https://api.powerbi.com/v1.0/myorg/groups/d864b33b-74dd-4683-9cfd-91c712039147/reports/d618f04d-0b9d-483b-8f9c-cb1210d14595 HTTP/1.1
Authorization: Bearer auth-token
User-Agent: FxVersion/4.7.2117.0 Windows_7_Enterprise/6.1.7601 Microsoft.PowerBI.Api.V2.PowerBIClient/2.0.2.17225
Host: api.powerbi.com
This is the request that my application makes directly referencing API endpoint which returns 400 :
GET https://api.powerbi.com/v1.0/myorg/groups/d864b33b-74dd-4683-9cfd-91c712039147/reports/d618f04d-0b9d-483b-8f9c-cb1210d14595 HTTP/1.1
cache-control: no-cache
Postman-Token: some-token
Authorization: Bearer auth-token
User-Agent: PostmanRuntime/7.1.1
Accept: /
Host: api.powerbi.com
This is due to Accept HTTP header. Microsoft`s REST Method does not support it.
Try:
curl -XGET
"https://api.powerbi.com/v1.0/myorg/groups/{groupId}/reports/{reportId}" -i -H
"Authorization: Bearer {token}" -H "Accept:"
-H "Accept:" will disable this HTTP header. (By default curl sends Accept: * / *)
I am getting a 403 response from the Power BI rest API and I am not sure why.
Here is the request I am making in cURL format(my actual web app is in Java):
curl -X GET -H "Authorization: Bearer accessToken" -H "Cache-Control: no-cache" 'https://api.powerbi.com/beta/myorg/dashboards'
I have given all Power BI Service permissions on my app in the azure management portal.
Do I need to replace 'myorg' with an actual org name? If so where would I find my org name? What am I doing wrong? This request seems to work for me in Aipary.io so I think it has something to do with my app not the request.
I have tried this request with both an admin account and a regular user and I get 403 responses for both of them.
I have also tried removing the Power BI Service permissions from the app with my admin account and then adding them again. That didn't work.
It seems to be that the 403 response was caused by the request in cURL missing some required parameters. The 403 response should show the error information that might be ignore.
Per my experience, I recommand you can try to use the GUI tool Postman in Chrome for requesting the APIs like cURL.
For checking the issue, you can follow the toturial https://powerbi.microsoft.com/en-us/documentation/powerbi-developer-authenticate-a-web-app/ to make sure the request required parameters correct.
However, according to your description for the issue, I can't locate the problem whether the prepare steps cause. So I suggest you can try to review the complete toturial https://powerbi.microsoft.com/en-us/documentation/powerbi-developer-steps-to-create-a-power-bi-app/ to be sure the every step is correct.
Hope it helps. Any concern, please feel free to let me know.
I hardly try to send a PUT request whit HttpsURLConnection but I cant make it and I don’t even get a response code, so now I want to do that whit Apache.
Here the question.
How can I send this request
curl -s -uedoweb-admin:admin -F"data=#/home/raul/test/t1/6376990.pdf;type=application/pdf" -XPUT api.localhost/resource/frl:6376979/data
and here the trace: http://pastebin.com/jJmungAy
in Java with the Apache lib.
I used Java Hipster to create my Rest API. I want to use this Rest API in my Java code (I'm developing an Android application). But I don't understand how authenticate me to use my Rest API !
As example, my api is blabla/api/getUser. With Firebug I tried to understand how call my API. I simulate a HTTP request POST with parameters ?id=x and my token in the header (token I got from the request to login from the browser). It's okay, it works, I have my information.
But now, in my java code, I can't send the same HTTP request because I don't know the token. How can I get it ? How can I log me as admin ?
I know : login for admin, password for admin and the URL of my API and parameters I have to send.
Thank's !
OAUTH2
POST
URL:
http://localhost:8080/oauth/token
in the header:
Authorization: eg. 'BASIC Y2xpZW50aWQ6Y2xpZW50c2VjcmV0'
BASE 64 encoding the client details (source: www.base64encode.org/)
Y2xpZW50aWQ6Y2xpZW50c2VjcmV0 == clientid:clientsecret
in the body:
username
password
grant_type
scope
curl -X POST -vu clientid:clientsecret http://localhost:8080/oauth/token -H "Accept: application/json" -d "username=admin&password=admin&grant_type=password&scope=read"
edit:
in android look at retrofit by square
I'm really new to APIs and POST or PUT or DELETE. I'm also new to running APIs using POST or other.
I have given a document which says
Function :- Add new Item
URI :- qtp/qtps
ACTION :- POST
REQUEST :- <n1:qtp xmlns:n1="http://www.mac.com/qts/xml/ns/qtm/qtpManagement"><name>rosa qtp 3</name><ipAddress>171.68.121.232</ipAddress><macAddress>10:0t:24:03:r7:57</macAddress><description>this is rosa qtp </description></n1:qtp>
I have absolutely no idea how to proceed further, But I know that by executing the request I need to Add a new Item in the application server, I tried something with browser myself but it did not work.
Can someone show me how can I work with this or explain me more about this or at-least give me a clue
One of the most useful tools for testing and debugging HTTP requests, in my experience, is cURL (http://curl.haxx.se/).
cURL is actually the under-the-hood library used for HTTP requests by a majority of PHP apps; the command-line version lets you do virtually anything that HTTP can do, and get great debugging data.
In the scenario you describe above, after downloading and installing cURL you'd likely use a command like:
curl --header "Content-Type: application/xml" --data '<XML YOU WANT TO SEND>' -X POST <URL TO WHICH DATA SHOULD BE SENT>
It's not clear from your question what the destination host+url is, but using the specific sample data you provide this would probably look like:
curl --header "Content-Type: application/xml" --data '<n1:qtp xmlns:n1="http://www.mac.com/qts/xml/ns/qtm/qtpManagement"><name>rosa qtp 3</name><ipAddress>171.68.121.232</ipAddress><macAddress>10:0t:24:03:r7:57</macAddress><description>this is rosa qtp </description></n1:qtp>' -X POST http://www.mac.com/qtp/qtps
Install a firebug plugin for that. You can use SOA client.