I am trying to find a way to use the Postful API and I need to post an image in the body of the request. I am trying to use rest-client (but am open to other ways):
The error I get when I post is HTTP status code 422
Basically, I'm clueless and need guidance. :\
class PostfulsController < ApplicationController
require 'rest_client'
def submit
body = "<?xml version='1.0' encoding='UTF-8'?>
<mail>
<documents>
<document>
<template>
<source>gallery</source>
<name>Postcard: Image fit front</name>
</template>
<sections>
<section>
<name>Text</name>
<text>Hello, World!</text>
</section>
<section>
<name>Image</name>
<attachment>#{attachment_id}</attachment>
</section>
</sections>
</document>
</documents>
<addressees>
<addressee>
<name>John Doe</name>
<address>123 Main St</address>
<city>Anytown</city>
<state>AZ</state>
<postal-code>10000</postal-code>
</addressee>
</addressees>
</mail>"
result = RestClient.post 'http://www.postful.com/service/mail',
body, :content_type => 'text/plain'
end
end