I'm developing a web aplication which interacts with google docs through api.
As Zend_Gdata doesn't have methods to change the sharing permitions of documents I need to use the POST method as the following:
POST /feeds/default/private/full/resource_id/acl HTTP/1.1
Host: docs.google.com
GData-Version: 3.0
Authorization: <your authorization header here>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gAcl='http://schemas.google.com/acl/2007'>
<category scheme='http://schemas.google.com/g/2005#kind'
term='http://schemas.google.com/acl/2007#accessRule'/>
<gAcl:role value='writer'/>
<gAcl:scope type='user' value='new_writer#example.com'/>
</entry>
Where exactly do I do this? Does php has a POST function? Should I use curl to do it? and how?
Thanks in advance
PHP can everything.
$url = "http://docs.google.com/feeds/default/private/full/resource_id/acl";
$headers = array("GData-Version: 3.0",
"Authorization: <your authorization header here>");
$body = "<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:gAcl='http://schemas.google.com/acl/2007'>
<category scheme='http://schemas.google.com/g/2005#kind'
term='http://schemas.google.com/acl/2007#accessRule'/>
<gAcl:role value='writer'/>
<gAcl:scope type='user' value='new_writer#example.com'/>
</entry>";
// main options
curl_setopt($this->curl, CURLOPT_URL, $url);
curl_setopt($this->curl, CURLOPT_POST, true);
curl_setopt($this->curl, CURLOPT_HTTPHEADER, $headers);
if (!empty($body)) curl_setopt($this->curl, CURLOPT_POSTFIELDS, $body);
$response = curl_exec($this->curl);
http://www.php.net/manual/en/book.curl.php
Related
I'm trying to send a SOAP request to the Loqate services following their API documentation found here.
The documentation says the SOAP end point is
https://api.addressy.com/Capture/Interactive/Find/v1.1/wsdlnew.ws
and the sample request is:
<?xml version="1.0" encoding="utf-8" ?>
<soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Find
xmlns="http://api.addressy.com/">
<Key>AA11-AA11-AA11-AA11</Key>
<Text>wr5 3da</Text>
<IsMiddleware>True</IsMiddleware>
<Container>GB|RM|ENG|3DA-WR5</Container>
<Origin>52.182,-2.222</Origin>
<Countries>GB,US,CA</Countries>
<Limit>10</Limit>
<Language />
<Bias />
<Filters />
<GeoFence />
</Find>
</soap:Body>
</soap:Envelope>
So I load up Postman and make these steps, following the Postman guide from their blog.
When I send the request, I just get back this page . I'm not sure why it's not working.
How can I make a SOAP request to this API? What am I missing?
That's not the service endpoint, it's an address where you can get the WSDL. Inside that WSDL you will find the service endpoint:
<soap:address location="http://services.postcodeanywhere.co.uk/Capture/Interactive/Find/v1.10/soapnew.ws"/>
Send your request there. The endpoint is over http, but the https seems to be working on the same address: https://services.postcodeanywhere.co.uk/Capture/Interactive/Find/v1.10/soapnew.ws
One other thing. If you want a more specific client than Postman, you could try SoapUI.
I'm stuck with making correct HTTP request to web server (running under PHP).
I need to send POST request with property json and some value, for example { "employee_id":191, "date":"2015-08-11", "time":"14:26:00" }.
It's working if I make a request from Postman or cURL for example, the request will look something like this
POST /DeliveryDetails/ HTTP/1.1
Host: 192.168.0.100:80
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
json=%7B+%22employee_id%22%3A191%2C+%22date%22%3A%222015-08-11%22%2C+%22time%22%3A%2214%3A26%3A00%22+%7D
Also I can send with conntent type multipart/form-data
POST /DeliveryDetails/ HTTP/1.1
Host: 192.168.0.100:80
Cache-Control: no-cache
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="json"
{ "employee_id":191, "date":"2015-08-11", "time":"14:26:00" }
----WebKitFormBoundary7MA4YWxkTrZu0gW
or with cURL
curl -d "json={ \"employee_id\":191, \"date\":\"2015-08-11\", \"time\":\"14:26:00\" }" http://192.168.0.100:80/DeliveryDetails/
But when I'm trying to make request from Mule ESB it's not working since the request is incorrect.
The flow looks like this
<sub-flow name="my-flow">
<logger message="Request: #[payload]" level="INFO" doc:name="Log request"/>
<http:request config-ref="request-HTTP" path="/DeliveryDetails/" method="POST" doc:name="HTTP call" />
<object-to-string-transformer doc:name="Object to String"/>
<logger message="Response: #[payload]" level="INFO" doc:name="Log response"/>
</sub-flow>
#[payload] contains the value { "employee_id":191, "date":"2015-08-11", "time":"14:26:00" }
and if I do it like this the body would simply contain it (without additional information like Content-Type, I think thats the problem).
I have tried to add query-param
<http:request-builder >
<http:query-param paramName="json" value="#[payload]" />
</http:request-builder>
or use message-properties-transformer
<message-properties-transformer doc:name="Message Properties">
<add-message-property key="json" value="#[payload]"/>
</message-properties-transformer>
but the result is still the same.
EDIT
The HTTP configuration look like this
<http:request-config name="request-HTTP"
host="192.168.0.100"
port="80"
doc:name="HTTP Request Configuration" />
Also tried to set Content-Type with
<set-property propertyName="Content-Type" value="application/x-www-form-urlencoded" doc:name="Property"/>
and
<http:request-builder>
<http:query-param paramName="json" value="#[payload]"/>
<http:header headerName="Content-Type" value="application/x-www-form-urlencoded"/>
</http:request-builder>
However the body I'm receiving is still just payload, without other properties for example json= or Content-Disposition: form-data; name="json"
Since the payload is just the JSON data, that's what will be sent in most scenarios. Your curl example sets the "json=" part to the body. So there are a couple of options here:
Modify the payload to add the body you want as you do with curl and set the Content-Type to application/x-www-form-urlencoded.
Send multipart content by adding the data as an attachment. In your case try:
<sub-flow name="my-flow">
<logger message="Request: #[payload]" level="INFO" doc:name="Log request"/>
<set-attachment attachmentName="json" value="#[payload]" contentType="application/json"/>
<http:request config-ref="request-HTTP" path="/DeliveryDetails" method="POST" doc:name="HTTP call" />
<object-to-string-transformer doc:name="Object to String"/>
<logger message="Response: #[payload]" level="INFO" doc:name="Log response"/>
</sub-flow>
Set the payload to be a map containing a key "json" with the payload as value. This should make Mule send a form request without you setting the Content-Type explicitly to application/x-www-form-urlencoded.
HTH.
You need to put path="/DeliveryDetails"
You can follow the following config :-
<http:request-config name="HTTP_Request_Configuration" host="192.168.0.100" port="80" doc:name="HTTP Request Configuration"/>
and in the Mule flow or sub flow and set the Content-Type as follows:-
<set-property propertyName="Content-Type" value="application/json" doc:name="Property"/>
<http:request config-ref="HTTP_Request_Configuration" path="/DeliveryDetails" method="POST" doc:name="HTTP call" />
<logger message="Input JSON message ****** #['\n'+ message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
You can configure the Content-Type here as per your requirement
You can also refer here :- How do I force the HTTP Request Connector to use a certain Content-Type?
I’ve been through every step mentioned here https://developers.google.com/google-apps/spreadsheets/#changing_contents_of_a_cell using the protocol and submitting the requests, right now, with POSTMAN before doing an actual script.
On the step of editing a cell via PUT i get a 403 Forbidden with the error "If-Match or If-None-Match header or entry etag attribute required”.
Right now my request URL is:
PUT https://spreadsheets.google.com/feeds/cells/MY_SPREADSHEET_ID/od6/private/full/R1C1?v=3.0
Headers:
Authorization Bearer {my access token}
Content-Type application/atom+xml
Raw
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:gs="http://schemas.google.com/spreadsheets/2006">
<id>https://spreadsheets.google.com/feeds/cells/MY_SPREADSHEET_ID/od6/private/full/R1C1</id>
<link rel="edit" type="application/atom+xml"
href="https://spreadsheets.google.com/feeds/cells/MY_SPREADSHIT_ID/od6/private/full/R1C1"/>
<gs:cell row="1" col="1" inputValue="hello"/>
</entry>
Any ideas please?
ps.: if I remove the ?v=3.0 there will be another error demanding the version
You should add the header If-Match:*
It should work out of the box that way, however, more on subject can be found on http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
I am developing code using the youtube API for live streaming. What I have done
I have registered a project in google and gotten client_id, client_secret, and
developer ID
I have done OAuth 2.0 and gotten the code and exchanged it to AUTH_TOKEN
I can create a live event by posting to domain gdata.youtube.com
with request
/feeds/api/users/default/live/events
with header
Authorization: Bearer AUTH_TOKEN
GData-Version: 2
Content-Type: application/atom+xml
X-GData-Key: key=DEV_ID
with content
<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns='http://www.w3.org/2005/Atom'
xmlns:media='http://search.yahoo.com/mrss/'
xmlns:yt='http://gdata.youtube.com/schemas/2007'>
<title>Test</title>
<summary>Test gogogogo!</summary>
<content type='application/atom+xml'>
<entry>
<yt:private/>
<yt:cdn name='primary'>
<media:content yt:format='18'/>
<media:content yt:format='19'/>
</yt:cdn>
</entry>
</content>
<yt:when start='2013-07-05T22:00:00.000Z'/>
</entry>
This returns HTTP code : 201 and my live event is created, but the returned data
does not include STREAM KEY AND RTMP URL. I need these data to start my live
event automatically.
the return data
<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns='http://www.w3.org/2005/Atom'
xmlns:app='http://www.w3.org/2007/app'
xmlns:media='http://search.yahoo.com/mrss/'
xmlns:gd='http://schemas.google.com/g/2005'
xmlns:yt='http://gdata.youtube.com/schemas/2007'
gd:etag='W/"CkEHR347eCp7I2A9WhFQEE0."'>
<id>tag:youtube.com,2008:live:event:XXXXXXXXXXXXXXXXXXXX</id>
<published>2013-07-05T05:03:56.000Z</published>
<updated>2013-07-05T05:03:56.000Z</updated>
<app:edited>2013-07-05T05:03:56.000Z</app:edited>
<category scheme='http://schemas.google.com/g/2005#kind'
term='http://gdata.youtube.com/schemas/2007#liveEvent'/>
<title>Test</title>
<summary>Test gogogogo!</summary>
<content type='application/atom+xml'
src='http://gdata.youtube.com/feeds/api/users/XXXXXXX/live/videos/XXXXXXXXX'/>
<link rel='self' type='application/atom+xml'
href='http://gdata.youtube.com/feeds/api/users/XXXXXXXXXXXXXXX/live/events/XXXXXXXXXXXXXXXXXX'/>
<link rel='edit' type='application/atom+xml'
href='http://gdata.youtube.com/feeds/api/users/XXXXXX/live/events/XXXXXXXXXXXXXXXXXXXXXX'/>
<author>
<name>XXXXXX</name>
<uri>http://gdata.youtube.com/feeds/api/users/XXXXXXXXXX</uri>
<yt:userId>XXXXXXXXXXXXX</yt:userId>
</author>
<media:group>
<media:description type='plain'>Test gogogogo!</media:description>
<media:title type='plain'>Test</media:title>
</media:group>
<yt:status>pending</yt:status>
<yt:when start='2013-07-05T22:00:00.000Z'/>
</entry>
If I manually login youtube and click on my create live event, I can see my
stream key and RTMP URL there. And I can use they to start streaming manually
So my problem is: how can I get STREAM KEY and RTMP URL automatically (by API
request)?
----EDIT----
based on https://developers.google.com/youtube/2.0/developers_guide_protocol_managing_live_events
it said that when I success create/adding an event, youtube will returns url like this
<yt:cdn name='primary'>
<media:content yt:format='19' yt:name='yt-live_SpQXZYILnN0_35'
url='rtmp://rtmp1.youtube.com/videolive?...'/>
</yt:cdn>
but in my case, my returned data doesn't include this line
After do some research, I solved it by sending this request
/feeds/api/users/default/live/events?inline=true
and the youtube returns me RTMP server URL
Thanks all
I want to make a request to a SOAP Web Service but I don't want to install any gems.
Is there any way to just make the request using plain XML?
I think it's trivial but there might be something I've missed, because all implementations/tutorials were using a gem.
I think that the SOAP response, can be handled also as a XML response right?
The request is this:
POST /services/tickets/issuer.asmx HTTP/1.1
Host: demo.demo.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<Tick xmlns="http://demo.com/test/test">
<Request>
<Username>string</Username>
<Password>string</Password>
<AcquirerId>int</AcquirerId>
<RequestType>string</RequestType>
<ExpirePreauth>unsignedByte</ExpirePreauth>
<BitPerSec>int</BitPerSec>
<Office>string</Office>
</Request>
</Tick>
</soap12:Body>
</soap12:Envelope>
You could do this:
def post_xml(path, xml)
host = "http://demo.demo.com"
http = Net::HTTP.new(host)
resp = http.post(path, xml, { 'Content-Type' => 'application/soap+xml; charset=utf-8' })
return resp.body
end
The XML response would be returned by this method.