This is a public Forum  publicRSS

Topic

    Sanjay Kumar
    REST API CORS IssueAnswered
    Topic posted September 12, 2017 by Sanjay KumarRookie 
    36 Views, 5 Comments
    Title:
    REST API CORS Issue
    Content:

    Hi Team, I am stuck in a situation where I have to create tickets from OSvC-A to another OSvC-B (like parent domain to child domain). I can create tickets using REST API and server side Curl libraries.

    problem is, I am not sure how to upload attachments to another OSvC-B from a client browser when using OSvC-A web portal, my guess is to use Rest API from client browser using javaScript which is not secure but it also shows CORS (cross domain) issue.

    Any ideas to solve the issue would be appreciated

    thank you

    San

    Version:
    17.5

    Best Answer

    Narendra Muttineni

    Hi,

    For this I would suggest you to create your own upload Attachment script in php and pass that attachment along with other fields when you click on Custom Submit button. Once you have the Attachment in controller, by using Webservices, upload that attachment to Incident of OSVC-B.

    To Upload Attachment, please refer the link

    Thanks,

    Narendra

    Answer

     

    • Narendra Muttineni

      Hi Sanjay,

      Can you elaborate your requirement ? From where you want to create Incident ? like browser or Console and in what scenario ?

      Thanks,

      Narendra

    • Sanjay Kumar

      Hi Narendra, thanks for your reply

      Actually it is happening on customer portal only from OSvC-A (OSvC-B doesn't have CP Pages)

      we have two ask pages on OSvC -A , one for tickets to OSvC-A and one for OSvC-B.

      Now, for the ask page for OSvC-B, I have a custom submit button which sends data to controller and controller can fire a call using Curl to OSvC-B and create tickets.

      problem is, I am not able to upload attachments from OSvC-A to OSvC-B using curl php because PHP is server side and cannot upload attachments from a client browser, I can use JavaScript with Rest API but again, it is preventing because of CORs issue

      I can upload attachment to local OSvC-A and then upload using curl to OSvC-B, but not sure if OSvC-A also have any local storage for such purposes.

      Any hints would be appreciated

      thank you

       

       

    • Narendra Muttineni

      Hi,

      For this I would suggest you to create your own upload Attachment script in php and pass that attachment along with other fields when you click on Custom Submit button. Once you have the Attachment in controller, by using Webservices, upload that attachment to Incident of OSVC-B.

      To Upload Attachment, please refer the link

      Thanks,

      Narendra

    • Pramod V

      Or may be you can create a HTML page, capture form elements post submitting in a controller, process them and create records in model.

      ~VIP

    • Sanjay Kumar

      Thanks everyone, I can now process attachments using Rest API, no issues so far.

      I took logic.js, info.yml from OOB input/FileAttachmentUpload widget and built my own widget from it so all validations will remain intact, once an attachment is added, I am using base64 conversion and saving them to local array and sending all attachments along with other data to controller. then firing a PHP Curl REST API to external OSvC-B to save all incident data, gets the incident ID in response and fire another call to save attachments with the returned incident ID.

      ref: http://docs.oracle.com/cloud/latest/servicecs_gs/CXSVC/c_Managing_file_attachments_aa1166814.html#aa1166814

      Cheers

      Sanjay