API Quickbooks не может загрузить вложение - PullRequest
0 голосов
/ 22 сентября 2019

Я пытаюсь загрузить PDF-файл на Quickbooks, используя Intuit api и C #.

Я использую код, указанный здесь http://developer.qbapi.com/Add-an-attachment-using-AttachableRef.aspx

Но я не могу загрузитьлюбой файл, также я не получаю никакой ошибки.

Вот что я пробовал

    public ActionResult CallUpload()
    {
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
        List<OidcScopes> scopes = new List<OidcScopes>();
        scopes.Add(OidcScopes.Accounting);


        OAuth2RequestValidator oauthValidator = new OAuth2RequestValidator("access_token_value");
        // Create a ServiceContext with Auth tokens and realmId
        ServiceContext serviceContext = new ServiceContext(realmIdValue, IntuitServicesType.QBO, oauthValidator);
        serviceContext.IppConfiguration.MinorVersion.Qbo = "30";
        serviceContext.IppConfiguration.BaseUrl.Qbo = "https://quickbooks.api.intuit.com/";
        serviceContext.IppConfiguration.Message.Request.SerializationFormat = Intuit.Ipp.Core.Configuration.SerializationFormat.Json;



        serviceContext.IppConfiguration.Message.Response.CompressionFormat = CompressionFormat.GZip;
        AttachableUploadDownloadAddTestUsingoAuth(serviceContext);
        return View();
    }        
   public void AttachableUploadDownloadAddTestUsingoAuth(ServiceContext qboContextoAuth)
    {


        string imagePath = string.Concat(AppDomain.CurrentDomain.BaseDirectory, "\\", "Uploads\\SalesOrderFiles\\testing.pdf");

        System.IO.FileInfo file = new System.IO.FileInfo(imagePath);
        Intuit.Ipp.Data.Attachable attachable = CreateAttachableUpload(qboContextoAuth);
        using (System.IO.FileStream fs = file.OpenRead())
        {
            //attachable.ContentType = "image/jpeg";
            attachable.ContentType = "application/pdf";
            attachable.FileName = file.Name;
            attachable =Upload(qboContextoAuth, attachable, fs);
        }



    }

    public static Intuit.Ipp.Data.Attachable Upload(ServiceContext context, Intuit.Ipp.Data.Attachable attachable, System.IO.Stream stream)
    {
        //Initializing the Dataservice object with ServiceContext
        DataService service = new DataService(context);

        Intuit.Ipp.Data.Attachable uploaded = service.Upload(attachable, stream);
        return uploaded;
    }


    public static Intuit.Ipp.Data.Attachable CreateAttachableUpload(ServiceContext context)
    {
        Intuit.Ipp.Data.Attachable attachable = new Intuit.Ipp.Data.Attachable();

        attachable.Lat = "25.293112341223";
        attachable.Long = "-21.3253249834";
        attachable.PlaceName = "Fake Place";
        attachable.Note = "Attachable note " + Guid.NewGuid().ToString("N").Substring(0, 5);
        attachable.Tag = "Attachable tag " + Guid.NewGuid().ToString("N").Substring(0, 5);

        //For attaching to Invoice or Bill or any Txn entity, Uncomment and replace the Id and type of the Txn in below code
        Intuit.Ipp.Data.AttachableRef[] attachments = new Intuit.Ipp.Data.AttachableRef[1];
        Intuit.Ipp.Data.AttachableRef ar = new Intuit.Ipp.Data.AttachableRef();
        ar.EntityRef = new Intuit.Ipp.Data.ReferenceType();
        ar.EntityRef.type = Intuit.Ipp.Data.objectNameEnumType.Invoice.ToString();
        ar.EntityRef.name = Intuit.Ipp.Data.objectNameEnumType.Invoice.ToString();
        ar.EntityRef.Value = "3535"; //Add the Id of your invoice here
        ////ar.EntityRef.type = objectNameEnumType.Bill.ToString();
        ////ar.EntityRef.name = objectNameEnumType.Bill.ToString();
        ////ar.EntityRef.Value = "1484";
        attachments[0] = ar;
        attachable.AttachableRef = attachments;

        return attachable;
    }

Я не могу понять, что не так в приведенном выше коде, так как я тожеЯ не получаю никаких ошибок и не вижу никаких файлов в списке вложений на быстрых книгах.

Я получаю возвращенный результат как Null при вызове service.Upload здесь

 Intuit.Ipp.Data.Attachable uploaded = service.Upload(attachable, stream);

Я вижу Stream в порядке и attachable данные также передаются правильно.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...