2474471 - File Upload Through ODATA API-1705 release-Onboarding

SAP Knowledge Base Article - Public

2474471 - File Upload Through ODATA API-1705 release-Onboarding

Symptom

A new API to allow import of documents to attach to Onboarding panel.Each Document will be g-zipped and passed in a base64 encoded fromat in API.


All Documents supported in RCM can be imported with exception of HTML Documents.


Customers can pass the Recruiting documents to be used in Onboarding through this API.

 

Environment

  • Applicable To All DataCenters.
  • API
  • Onboarding.

Resolution

Please follow below 12 steps:

1.Panel:

Create a upload option and give form code.

api1.png

 

2. a) Create a test candidate and get the hrdata id of candidate(Test Gopi- b4da3efe-9f23-47a1-87c9-384de3904c17)

   b) Do not upload file .

   c) Documents can be uploaded through API until candidates completed onboarding process.

 

3.Test.PDF File is going to be uploaded through odata API for candidate (Test Gopi).

 

4.First you need to convert a file to gz format  before performing uploading a file:

Converting Test.pdf file to  gz format. Please find below screenshots for reference.

api2.png

api3.png

 Gz file is ready now: (Test.pdf.gz)

api5.JPG

5.Upload a gz file using encoder and as a output you will receive a text file format.

    a.Please find below screenshots how to use base64 encoder:

  1. search base64 in google.

api6.png

b.click on encode(at top) ,upload a file (Test.pdf.gz) and click on encode at bottom(>Encode>).

c.Output will be Test.pdf.Txt(With encoded content)

api7.png

api8.JPG

6.create a odata in service login in superadmin:

api11.png

 

7.a) we need to encode the above odataservice login using base 64 encode and decoder:

ap20.png

b)click on encode and provide below user details, encode it.(>Encode<)

 

 {"UserName":"GopiTrain","Password":"GopiTrain"}

c)Output value will retrive: eyJVc2VyTmFtZSI6IkdvcGlUcmFpbiIsIlBhc3N3b3JkIjoiR29waVRyYWluIn0=

 api21.png

8.Open Postman Tool(Download it from google).

9..Posting the file:My account in dc4 sales demo so url is maintained as below.

a)Token generation using GET Method:

Get method: https://sales-onboarding4.successfactors.com/ONBSALES/odata/v2/ODataAuthentication

In headers provide key as : Authorization

Value as : Basic eyJVc2VyTmFtZSI6IkdvcGlUcmFpbiIsIlBhc3N3b3JkIjoiR29waVRyYWluIn0=                  (Above encoded value is which we received from pt 7©.)

Click on send and token will be generated for authentication:

Token:cf0f7e07-04bf-420a-bd49-9e12063a1126

api25.png

 

b) Posting a file using POST method:

Add below url:

https://sales-onboarding4.successfactors.com/ONBSALES/odata/v2/OnboardeeAttachment

api26.png

 

Click on headers and add below:

Authorization as key

Value is token :cf0f7e07-04bf-420a-bd49-9e12063a1126 which we fetched in step 9(a)

Please find below screenshots for reference:

api30.png

 

Click on body -choose raw and click on json

api31.png

In body enter below details:Please make ensure data is maintained in below format:

[

{

                                "HrDataId" : " b4da3efe-9f23-47a1-87c9-384de3904c17",

                                "AttachmentName" : "TestDoc.pdf",

                                "FormCode" : "Test",

                                "AttachmentContent": “<base-64 encoded g-zipped file content>”

}

]

 

PS: <base-64 encoded g-zipped file content>”-enocded format which we obtained in pt 5© and also in request 4 braces[{}] are mandatory as stated above.

api40.png

c)Click on send and you will receive below response:

[

  {

    "HrDataId": " b4da3efe-9f23-47a1-87c9-384de3904c17",

    "AttachmentId": "7ba925e6-0117-47de-9bc3-fea4c3bbaffb",

    "AttachmentName": "TestDoc.pdf",

    "StatusCode": "200",

    "StatusMessage": "Document successfully Uploaded"

  }

]

 

 

d)Now login and check , for the candidate document will be successfully uploaded.

 

api41.png

10.Downloading a uploaded file using GET Method:

     Fetching all records of candidate using below method:

a)Enter below url :

https://salesonboarding4.successfactors.com/ONBSALES/odata/v2/OnboardeeAttachment?$filter=HrDataId eq guid'b4da3efe-9f23-47a1-87c9-384de3904c17'

api50.png

b)In Header ,enter key as Authorization and value as token .Please find below screenshot:

api51.png

 

c)Click on send and you will receive below response:

 

{

  "odata.metadata": "http://localhost/xp/odata/v3/$metadata#OnboardeeAttachment",

  "value": [

    {

      "HrDataId": " b4da3efe-9f23-47a1-87c9-384de3904c17",

      "AttachmentId": "7ba925e6-0117-47de-9bc3-fea4c3bbaffb",

      "AttachmentName": "documentTwo.txt",

      "FormCode": "Blue",

      "AttachmentContent": "<base-64 encoded g-zip content”,    

      "AttachmentDetails": [

        {

          "Key": "ShowInWorkQueue",

          "Value": "True"

        },

        {

          "Key": "MimeType",

          "Value": "text/plain"

        }

      ]

    }

 You will receive output in decoded format.

 

11.Decoding a file:

Now open motobit in google to decode file:

api60.png

Converting decoded text(received as response in point 10©).

 

Please refer below screenshot:

api70.png

 

12.converting gz to normal file format:

Gzfile(test.pdf.gz) will be the output and extract it to normal pdf .please find below screenshot:

 api80.png

 

13.test.pdf will be retrieved.

 

PS:Using guid we downloaded all documents for a candidate.we can download a single document using attachment id or form code by below api calls.

 

GET ATTACHMENT BY ATTACHMENT ID

REQUEST:

  • URI: https://<Hostname>/<PartnerName>/odata/v2/OnboardeeAttachment(‘<attachment-id>’)
  • METHOD: GET
  • HEADERS: Authorization: <Token obtained from oData Authentication API>
  • PAYLOAD: None

RESPONSE:

{

  "odata.metadata": "http://localhost/xp/odata/v3/$metadata#OnboardeeAttachment",

  "value": [

    {

      "HrDataId": "90a72911-9444-4ad3-9698-035f6a528a16",

      "AttachmentId": "15bc306b-4eaa-4019-b351-6f7eb74bbf3a",

      "AttachmentName": "documentTwo.xls",

      "FormCode": "Blue",

      "AttachmentContent": “<BASE-64 ENCODED G-ZIP CONTENT”>

      "AttachmentDetails": [

        {

          "Key": "ShowInWorkQueue",

          "Value": "True"

        },

 

GET ATTACHMENTS FOR ON ONBOARDEE AND FILTER BY FORM CODE:

 REQUEST:

URI: https://<Hostname>/<PartnerName>/odata/v2/OnboardeeAttachment?$filter=HrDataId eq guid'90a72911-9444-4ad3-9698-035f6a528a16' and FormCode eq 'Blue'

METHOD: GET

HEADERS: Authorization: <Token obtained from oData Authentication API>

RESPONSE: Same as above.

 

 

 

 

 

 

 

Keywords

  • API
  • File Upload
  • Onboarding
  • ODATA API
, KBA , LOD-SF-OBD-API , Webservices & API's , How To

Product

SAP SuccessFactors Onboarding all versions