Hello Monks, am trying to parse some json API, Here is the json
curl "https://api.zeptomail.com/v1.1/email" \ -X POST \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -H "Authorization:<SEND_MAIL_TOKEN>" \ -d '{ "bounce_address":"<BOUNCE_ADDRESS>", "from": {"address": "noreply@<DOMAIN>"}, "to": [{"email_address": {"address": "user@domain.com","name": + "John Deo"}}], "subject":"Test Email", "htmlbody":"<div><b> Test email sent successfully. </b></div>" +}'
My Try:
#!/usr/bin/perl use strict; use warnings; use HTTP::Tiny; use JSON; use Data::Dumper; print "Content-type: text/html\n\n"; my $url = "https://api.zeptomail.com/v1.1/email"; my $json = encode_json { bounce_address => 'bounce@email', from => 'noreply@email.com', to => 'receipt@email.com', subject => 'Test Email', htmlbody => '<div><b> Test email sent successfully. </b></div>', }; my $http = HTTP::Tiny->new( default_headers => { Authorization => 'Token', } ); my $response = $http->post( $url => { content => $json, headers => { 'Content-Type' => 'application/json' }, }); if ( $response->{'is_success'} ) { print Dumper( decode_json $response->{'content'} ); } else { print "$response->{'content'} $response->{'reason'}\n"; }
Am getting this Response( ERROR):
{"error":{"code":"TM_3501","details":[{"code":"GE_122","message":"Inva +lid value found","target":"from"}],"message":"Unprocessable Entity"," +request_id":"2d6f.1281848db93b53d5.m1.659b6560-d7c7-11ed-90d9-525400d +4bb1c.1876c4546b6"}}

In reply to Problem parsing json by frank1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.