5

I am trying to generating the usps label with 4x6 but I am facing this issue. Can any one help me out for generating 4x6Label.

Also I tried changing the version from DeliveryConfirmationV3 to DeliveryConfirmationV4 but still it is not generating 4x6Label.

My xml request is passing as

https://secure.shippingapis.com/ShippingAPI.dll?API=DeliveryConfirmationV3&XML=<DeliveryConfirmationV3.0Request USERID="xxxxx" PASSWORD="xxxxxx">
<Option>1</Option>
<ImageParameters>
    <ImageParameter>4X6LABEL</ImageParameter>
</ImageParameters>
<FromName>Mitesh1 Jain1</FromName>
<FromFirm></FromFirm>
<FromAddress1>52 NORMANDY RD</FromAddress1>
<FromAddress2>QWE</FromAddress2>
<FromCity>MARLTON</FromCity>
<FromState>NJ</FromState>
<FromZip5>08053</FromZip5>
<FromZip4></FromZip4>
<ToName>DISCRETE JRC,LLC</ToName>
<ToFirm></ToFirm>
<ToAddress1>110 South 8th Street</ToAddress1>
<ToAddress2>Suite 104</ToAddress2>
<ToCity>Philadelphia</ToCity>
<ToState>PA</ToState>
<ToZip5>15001</ToZip5>
<ToZip4></ToZip4>
<WeightInOunces>1</WeightInOunces>
<ServiceType>Priority</ServiceType>
<POZipCode></POZipCode>
<ImageType>PDF</ImageType>
<LabelDate></LabelDate>
<CustomerRefNo></CustomerRefNo>
<AddressServiceRequested>False</AddressServiceRequested>
<SenderName></SenderName>
<SenderEMail></SenderEMail>
<RecipientName></RecipientName>
<RecipientEMail></RecipientEMail>
</DeliveryConfirmationV3.0Request>

but I am receiving error as

<?xml version="1.0" encoding="utf-8"?>
<Error>
<Number>-2147221202</Number>
<Source>Common:XmlParse</Source>
<Description>The element 'ImageParameters' cannot contain child element 'ImageParameter' because the parent element's content model is text only.</Description>
 <HelpFile/>
 <HelpContext/>

Initially it was working perfectly but after passing

<ImageParameter>4X6LABEL</ImageParameter>

this issue arises

Currently my code is as

   public Package GetDeliveryConfirmationLabel(Package package)
{
    string labeldate = package.ShipDate.ToShortDateString();
    if (package.ShipDate.ToShortDateString() == DateTime.Now.ToShortDateString()) 
        labeldate = "";
       string url= "https://secure.shippingapis.com/ShippingAPI.dll?API=PriorityMailIntlCertify&XML= <PriorityMailIntlCertifyRequest USERID=\"XXXXX\"> <Option></Option> <Revision>2</Revision> <ImageParameters> <ImageParameter>4X6LABEL</ImageParameter> </ImageParameters> <FromFirstName>Garth</FromFirstName> <FromMiddleInitial>A</FromMiddleInitial> <FromLastName>Brooks</FromLastName> <FromFirm>Garths Firm</FromFirm> <FromAddress1>radlab</FromAddress1> <FromAddress2>6406 Ivy Lane</FromAddress2> <FromUrbanization>Garys Urbanization</FromUrbanization> <FromCity>Greenbelt</FromCity> <FromState>MD</FromState> <FromZip5>20770</FromZip5> <FromZip4>1234</FromZip4> <FromPhone>3019187658</FromPhone> <FromCustomsReference> From Customs Ref.</FromCustomsReference> <ToName></ToName> <ToFirstName>Reza</ToFirstName> <ToLastName>Dianat</ToLastName> <ToFirm>HP</ToFirm> <ToAddress1>HP</ToAddress1> <ToAddress2>5th floor</ToAddress2> <ToAddress3>6406 Flower Lane</ToAddress3> <ToCity>Greenbelt</ToCity> <ToProvince>Md</ToProvince> <ToCountry>Canada</ToCountry> <ToPostalCode>20770</ToPostalCode> <ToPOBoxFlag>N</ToPOBoxFlag> <ToPhone>5555555555</ToPhone> <ToFax>3012929999</ToFax> <ToEmail>b@aol.com</ToEmail> <ToCustomsReference>Import Reference</ToCustomsReference> <NonDeliveryOption>Return</NonDeliveryOption> <Container>MDFLATRATEBOX</Container> <ShippingContents> <ItemDetail> <Description>Description 1</Description> <Quantity>1</Quantity> <Value>1.11</Value> <NetPounds>1</NetPounds> <NetOunces>1</NetOunces> <HSTariffNumber>123456789123</HSTariffNumber> <CountryOfOrigin>Brazil</CountryOfOrigin> </ItemDetail> <ItemDetail> <Description>Description 2</Description> <Quantity>2</Quantity> <Value>2.22</Value> <NetPounds></NetPounds> <NetOunces>2</NetOunces> <HSTariffNumber>234567</HSTariffNumber> <CountryOfOrigin>Switzerland</CountryOfOrigin> </ItemDetail> <ItemDetail> <Description>Description 3</Description> <Quantity>3</Quantity> <Value>3.33</Value> <NetPounds></NetPounds> <NetOunces>3</NetOunces> <HSTariffNumber>123456789123</HSTariffNumber> <CountryOfOrigin>Brazil</CountryOfOrigin> </ItemDetail> <ItemDetail> <Description>Description 4</Description> <Quantity>4</Quantity> <Value>4.44</Value> <NetPounds></NetPounds> <NetOunces>4</NetOunces> <HSTariffNumber>234567234567</HSTariffNumber> <CountryOfOrigin>Switzerland</CountryOfOrigin> </ItemDetail> </ShippingContents> <Insured>N</Insured> <InsuredNumber>90123</InsuredNumber> <InsuredAmount>99.90</InsuredAmount> <GrossPounds>3</GrossPounds> <GrossOunces>8</GrossOunces> <ContentType>Documents</ContentType> <ContentTypeOther>and Other</ContentTypeOther> <Agreement>Y</Agreement> <Comments>PriorityMailIntl Comments</Comments> <LicenseNumber>Lic 123</LicenseNumber> <CertificateNumber>Cert456</CertificateNumber> <InvoiceNumber>Inv890</InvoiceNumber> <ImageType>TIF</ImageType> <ImageLayout>TRIMONEPERFILE</ImageLayout> <CustomerRefNo>Cust Ref123</CustomerRefNo> <POZipCode>20770</POZipCode> <LabelDate></LabelDate> <HoldForManifest>N</HoldForManifest> <EELPFC>802.11B</EELPFC> <CommercialPrice></CommercialPrice> <Size></Size> <Length></Length> <Width></Width> <Height></Height> <Girth></Girth> <ExtraServices> <ExtraService></ExtraService> </ExtraServices> </PriorityMailIntlCertifyRequest>"; 

     string xml = web.DownloadString(url);
    if (xml.Contains("<Error>"))
    {
        int idx1 = xml.IndexOf("<Description>") + 13;
        int idx2 = xml.IndexOf("</Description>");
        int l = xml.Length;
        string errDesc = xml.Substring(idx1, idx2 - idx1);
        package.Error = errDesc;
        //throw new USPSManagerException(errDesc);
    }
    else
    {
         int i1 = xml.IndexOf("<LabelImage>") + "<LabelImage>".Length;
         int i2 = xml.IndexOf("</LabelImage>");
         package.ShippingLabel = Convert.FromBase64String(xml.Substring(i1, i2 - i1));

         XmlDocument xmldoc = new XmlDocument();
         xmldoc.LoadXml(xml);
         XmlNodeList nodeList = xmldoc.GetElementsByTagName("LabelImage");
        string _DeliveryConfirmationNumber = string.Empty;
        foreach (XmlNode node in nodeList)
        {
            _DeliveryConfirmationNumber = node.InnerText;
        }
        package.ReferenceNumber = _DeliveryConfirmationNumber;
    }
    return package;
}   

I had updated the above code but I m getting issue as

enter image description here

Console

enter image description here

  • 1
    the error message contains the hint "content model is text only" which would mean that the image parameters have to be included either as attributes or as the content of the tag, like `` or like `4X6LABEL`. do you have an xsd or a documentation for that Api, where this should be explained? – Cee McSharpface Aug 21 '17 at 19:20
  • @dlatikay I had reviewed https://www.usps.com/business/web-tools-apis/international-shipping-label-api.htm#_Toc486418876 and added image parameter –  Aug 21 '17 at 19:22
  • Now I saw it too, you are right, its in their sample exactly as you have it. Looks like some API version conflict. – Cee McSharpface Aug 21 '17 at 19:25
  • you need to specify `2` as of january 2011... should go right below the `` tag. this is probably some kind of marker that tells the host to apply a newer version of the schema. – Cee McSharpface Aug 21 '17 at 19:29
  • @dlatikay I have added that but i m getting error as The element 'DeliveryConfirmationV3.0Request' has invalid child element 'Revision'. List of possible elements expected: 'ImageParameters'. –  Aug 21 '17 at 19:32
  • none of the samples ever uses that parameter. sorry, out of ideas. the only thing I could do was upvote the question, maybe someone with more experience on that V3 can weigh in. findings: https://www.usps.com/business/web-tools-apis/delivery-confirmation-domestic-shipping-label-api.pdf, http://remoteinternetsolutions.com/programming/usps-xml-api/ – Cee McSharpface Aug 21 '17 at 19:43
  • 1
    Why do you have `API=DeliveryConfirmationV3`? I'm not at all familiar with the topic, but when I searched for the topic I found the following: https://www.usps.com/business/web-tools-apis/evs-label-api.htm#_Toc487532684 and it only mentions `API=eVS` and `API=eVSCertify`. Can you add a documentation link that mentions the `API=DeliveryConfirmationV3` thing? – grek40 Aug 28 '17 at 07:21
  • 1
    Just reviewed your comment from Aug 21. There you refer to a documentation for `API=PriorityMailIntl` - so don't expect it to work without using this API ;) – grek40 Aug 28 '17 at 07:31
  • @grek40 I had updated my question and had send the full code which is currentlt creating the usps label. Now in case if I need to use the API=PriorityMailIntl then what and whoch changes I need to do? Can you please help me out –  Aug 30 '17 at 20:45
  • Citing myself: *"I'm not at all familiar with the topic"*. Just make sure to follow a single source of documentation, use the API that it refers to and use the documented xml nodes. If you start mixing API 1 with attributes from API 2, you are bound to run into problems. – grek40 Aug 30 '17 at 21:49
  • @grek40 I had updated the question with passing with PriorityMailIntl but now i am getting error at package.ShippingLabel = Convert.FromBase64String(xml.Substring(i1, i2 - i1)); –  Aug 31 '17 at 11:34
  • You should consider removing your UserID here and in the other question... as far as I can tell, this is confidential information and USPS requires you not to share it. Contact a moderator to get rid of this information in the question revision history too. – grek40 Aug 31 '17 at 13:14

1 Answers1

0

Regarding the original problem:

The 4X6LABEL is not available for the DeliveryConfirmationV3 API. To use this option, chose an API that supports it. (you have to decide between PriorityMailIntl and eVS among others, depending on your need)

Your updated code:

You specifiy <ImageType>TIF</ImageType> for whatever reason, but it seems like you try to use the returned data as PDF. Try to save and open them as TIF to test your current results and try to change the requested ImageType to PDF in order to get your probably desired result.

grek40
  • 13,113
  • 1
  • 24
  • 50