Inserting data with OData in atom format - odata

Odata is a new thing for me and I'm trying getting in deep with it. So I'm trying insert data using OData protocol in atom format and using a rest client. So I've created the following http Post request:
POST /HelloOdata/library.xsodata/books HTTP/1.1
Host: coe-he-55:8010
Authorization: Basic xxxxxxxxxxxxxxxxxxxxx
DataServiceVersion: 1.0
MaxDataServiceVersion: 2.0
accept: application/atom+xml
Content-Type: application/atom+xml
Cache-Control: no-cache
Postman-Token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
<?xml version="1.0" encoding="utf-8"?>
<Entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns="http://www.w3.org/2005/Atom">
<title type="text">books</title>
<author>
<name />
</author>
<link href="books('Test_post')/Author" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Author" title="Author" type="application/atom+xml;type=entry"/>
<category term="HelloOdata.library.booksType"
scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<content type="application/xml">
<m:properties>
<d:title>Test_post</d:title>
<d:ISBN>ISBN_POST</d:ISBN>
<d:editions>2</d:editions>
</m:properties>
</content>
</Entry>
and as a response I've got: The serialized resource has an missing value for member 'title'.
Well my table books has only three properties which are title, ISBN and editions precisely those one I'm trying insert through this statement. So, do you have any idea what can be wrong in it?
Thank you
Pablo

I've found where the error was.
Unbelievably the right xml request is:
POST /HelloOdata/library.xsodata/books HTTP/1.1
Host: coe-he-55:8010
Authorization: Basic xxxxxxxxxxxxxxxxxxxxx
DataServiceVersion: 1.0
MaxDataServiceVersion: 2.0
accept: application/atom+xml
Content-Type: application/atom+xml
Cache-Control: no-cache
Postman-Token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
<?xml version="1.0" encoding="utf-8"?>
<entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns="http://www.w3.org/2005/Atom">
<title type="text">books</title>
<author>
<name />
</author>
<category term="HelloOdata.library.booksType"
scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<content type="application/xml">
<m:properties>
<d:title>Test_post</d:title>
<d:ISBN>ISBN_POST</d:ISBN>
<d:editions>2</d:editions>
</m:properties>
</content>
</entry>
well I also had to get off with this part:
<link href="books('Test_post')/Author" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Author" title="Author" type="application/atom+xml;type=entry"/>
but this was an attempt after the first one, because the real problem was the tag
<Entry>
write with E and not
<entry>
Once I changed it, the Http request works well.
I saw this example of insertion of data with OData on the official website guideline:
http://www.odata.org/documentation/odata-version-2-0/operations and there the tag entry was written with capital letter.
Thank you!
Pablo

Related

Issues Formatting a SOAP API with Savon gem

I was terrified this day would come.. dealing with SOAP API's...
This is a whole new realm for me, Ive done some digging with the SAVON gem but i cant seem to structure my call..
Essentially what I am trying to do is the following:
Step 1: Call the API to retrieve the LatestCallerVersion (API Version)
Step 2: Take the LatestCallerVersion and send a second request to the validation API to see if my customers are in a valid service area.
This is what I've come up with (but it crashes and burns hard)
caller_client = Savon.client(
wsdl: 'https://alarmadmin.alarm.com/webservices/CustomerManagement.asmx?WSDL '\
)
caller_response = caller_client.call(
:authentication,
message: {
user: 'xxxxxx',
password: 'xxxxxx',
two_factor_device_id: 'xxxxxx'
},
:body,
message: {
:get_latest_caller_version
}
)
Here is the SOAP request & response Doc for the GetLatestCaller call
POST /webservices/CustomerManagement.asmx HTTP/1.1
Host: alarmadmin.alarm.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:Header>
<Authentication xmlns="http://www.alarm.com/WebServices">
<User>string</User>
<Password>string</Password>
<TwoFactorDeviceId>string</TwoFactorDeviceId>
</Authentication>
</soap12:Header>
<soap12:Body>
<GetLatestCallerVersion xmlns="http://www.alarm.com/WebServices" />
</soap12:Body>
</soap12:Envelope>
HTTP/1.1 200 OK
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>
<GetLatestCallerVersionResponse xmlns="http://www.alarm.com/WebServices">
<GetLatestCallerVersionResult>int</GetLatestCallerVersionResult>
</GetLatestCallerVersionResponse>
</soap12:Body>
</soap12:Envelope>
Here is the CheckCaller_V2 request & Response
POST /webservices/Validate.asmx HTTP/1.1
Host: alarmadmin.alarm.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:Header>
<Authentication xmlns="http://www.alarm.com/WebServices">
<User>string</User>
<Password>string</Password>
<TwoFactorDeviceId>string</TwoFactorDeviceId>
</Authentication>
</soap12:Header>
<soap12:Body>
<CheckCoverage_v2 xmlns="http://www.alarm.com/WebServices">
<input>
<Address>
<Street1>string</Street1>
<Street2>string</Street2>
<SubCity>string</SubCity>
<City>string</City>
<SubState>string</SubState>
<State>string</State>
<Zip>string</Zip>
<CountryId>Canada</CountryId>
</Address>
<Network>Gsm</Network>
<Generation>FourG</Generation>
<CallerVersion>returned from GetLatestCaller call</CallerVersion>
</input>
</CheckCoverage_v2>
</soap12:Body>
</soap12:Envelope>
HTTP/1.1 200 OK
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>
<CheckCoverage_v2Response xmlns="http://www.alarm.com/WebServices">
<CheckCoverage_v2Result>NotChecked or FullCoverage or MostlyCovered or NoCoverage or Error or BadZip or PartialCoverage or NotSupported or NotOffered</CheckCoverage_v2Result>
</CheckCoverage_v2Response>
</soap12:Body>
</soap12:Envelope>
I am brand new to SOAP Any assistance here would be greatly appreciated. Please let me know if anything further is needed.
kindly use SOAP UI to check for the Request definition. On loading the the WSDL file in SOAP UI, I am able to get the following.
After that it becomes relatively easy to follow along. It seems all the operations has the same header, so I will go and create a client that looks like
caller_client = Savon.client(
wsdl: 'https://alarmadmin.alarm.com/webservices/CustomerManagement.asmx?WSDL',
env_namespace: :soapenv,
namespace_identifier: :web,
soap_header: {
'web:Authentication': {
'web:User': 'xxxx',
'web:Password': 'xxxxx',
'web:TwoFactorDeviceId': 'xxx'
}
})
And after that calling the individual operation becomes
caller_client.call(:get_latest_caller_version)
If you want to list all the possible operations, you can use
caller_client.operations
If you want to pass message to individual operation, use the following format
caller_client.call(:get_modem_serial_from_iccid, message: { iccid: 'xxxx' })

Insert into Google Merchant data feed using Content API

I'm trying to insert some data into my merchant account data feed using the Content API. Using the code below, I've been given a "POST requests require a Content-length header. That’s all we know." error, but I've set the content length, so I'm really confused.
One theory I have is that it doesn't know where to put these requests, under my merchant account ID, I have two data feeds, and I'm not sure how to set it to enter into a given data feed.
The XML is stolen from here: https://developers.google.com/shopping-content/batch-operations
#feed = '<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom"
xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/"
xmlns:g="http://base.google.com/ns/1.0"
xmlns:batch="http://schemas.google.com/gdata/batch">
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:sc="http://schemas.google.com/structuredcontent/2009"
xmlns:scp="http://schemas.google.com/structuredcontent/2009/products"
xmlns:app="http://www.w3.org/2007/app">
<batch:operation type="INSERT"/>
<title>Switch 1</title>
<content type="text">A new item available...</content>
<link rel="alternate" type="text/html" href="http://www.example.com/sku123"/>
<sc:id>SKU123</sc:id>
<sc:content_language>en</sc:content_language>
<sc:target_country>US</sc:target_country>
<scp:google_product_category>Electronics > Networking > Hubs &
Switches</scp:google_product_category>
<scp:condition>new</scp:condition>
<scp:price unit="USD">25</scp:price>
<scp:availability>in stock</scp:availability>
</entry>
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:sc="http://schemas.google.com/structuredcontent/2009"
xmlns:scp="http://schemas.google.com/structuredcontent/2009/products"
xmlns:app="http://www.w3.org/2007/app">
<batch:operation type="INSERT"/>
<title>Switch 2</title>
<content type="text">Another item available...</content>
<link rel="alternate" type="text/html" href="http://www.example.com/sku124"/>
<sc:id>SKU124</sc:id>
<sc:content_language>en</sc:content_language>
<sc:target_country>US</sc:target_country>
<scp:google_product_category>Electronics > Networking > Hubs &
Switches</scp:google_product_category>
<scp:condition>new</scp:condition>
<scp:price unit="USD">50</scp:price>
<scp:availability>in stock</scp:availability>
</entry>
</feed>'
http = HTTPClient.new
#output = http.post('https://content.googleapis.com/content/v1/<myMerchantID>/items/products/schema/batch', {},"content"=> #feed, "Content-length"=>#feed.length.to_s, "GData-Version"=> "1", "Authorization" => "AuthSub token=myToken", "Content-Type"=> "application/atom+xml")
Are you Authenticating prior to your post?
https://developers.google.com/shopping-content/getting-started/authentication

cannot get RTMP URL and stream key

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

Import custom Atom feed in PowerPivot

Question: I have created a sample xml document containing data conforming to the atom 1.0 schema. When I import the contents of this file (for testing purposes) in PowerPivot, it creates columns for each atom element in each entry, instead of creating a column per content element. Why is this?
Background: A customer wants to import data from a web service which provides a feed that uses a custom XML schema that is not supported by PowerPivot. The service provides the ability for the caller to supply an XSLT template that will be applied to the feed. I am hoping to be able to transform this feed into a valid atom feed thereby allowing the customer to import data into PowerPivot.
Sample atom xml:
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns="http://www.w3.org/2005/Atom"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<title type="text">My Data Feed</title>
<id>http://temp/feed</id>
<updated>2012-12-13T00:00:00Z</updated>
<entry>
<id>http://temp/feed/1</id>
<title type="text">Title</title>
<author>
<name>Author</name>
</author>
<updated>2012-12-13T00:00:00Z</updated>
<content type="application/xml">
<d:Name>John Smith</d:Name>
<d:Address>Address</d:Address>
<d:Zip>1234</d:Zip>
</content>
</entry>
</feed>
When imported into PowerPivot (selecting "From Data Feeds", clicking "Browse" and pointing out the xml file), it looks like this:
I was excpecting three columns: Name, Address and Zip. If I change "Include Atom Elements" from Auto to False in the connection configuration, no columns are imported.
It seems I was just missing the m:properties element. Final result - also includes examples of null attributes and data types:
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns="http://www.w3.org/2005/Atom"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<title type="text">My Data Feed</title>
<id>http://temp/feed</id>
<updated>2012-12-13T00:00:00Z</updated>
<entry>
<id>http://temp/feed/1</id>
<title type="text">Title</title>
<author>
<name>Author</name>
</author>
<updated>2012-12-13T00:00:00Z</updated>
<content type="application/xml">
<!-- attributes placed under the properties element -->
<m:properties>
<d:Name>John Smith</d:Name>
<d:Address>Address</d:Address>
<d:Zip m:type="Edm.Int32">1234</d:Zip>
<d:Comment m:null="true" />
</m:properties>
</content>
</entry>
</feed>

Making a SOAP / XML request from Rails

I have an xml object xml:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<GetLocations xmlns="http://clients.mindbodyonline.com/api/0_5_1">
<Request>
<SourceCredentials>
<SourceName>{SourceName}</SourceName>
<Password>{Password}</Password>
<SiteIDs>
<int>{SiteID}</int>
</SiteIDs>
</SourceCredentials>
<XMLDetail>Bare</XMLDetail>
<PageSize>10</PageSize>
<CurrentPageIndex>0</CurrentPageIndex>
<Fields>
<string>Locations.Name</string>
<string>Locations.City</string>
</Fields>
</Request>
</GetLocations>
</soapenv:Body>
</soapenv:Envelope>
and am trying to copy this request I found in an example:
POST https://clients.mindbodyonline.com/api/0_5_1/SiteService.asmx HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "http://clients.mindbodyonline.com/api/0_5_1/GetLocations"
Host: clients.mindbodyonline.com
Content-Length: 795
But I do not know how to include things like SOAPAction in my request using something like RestClient.
How do you include such parameters, or is there a different way to make this type of request?
Check out the example code they have written in ruby here.
You can use savon gem to do the request, you can have a look at this code sample that shows how to do that.

Resources