SAP Knowledge Base Article - Public

2474471 - File Upload Through ODATA API and attach to Onboarding Panel - Onboarding 1.0

Symptom

  • An API to allow import of documents to be attached to an Onboarding panel. Each document will be g-zipped and passed in a base64 encoded format in API.
  • All Documents supported in Recruiting can be imported with exception of HTML Documents.
  • Customers can pass the Recruiting documents to be used in Onboarding through this API.

 Image/data in this KBA is from SAP internal systems, sample data, or demo systems. Any resemblance to real data is purely coincidental.

Environment

SAP SuccessFactors Onboarding 1.0

Resolution

Please follow below 12 steps:

  1. Panel: Create a upload option and give form code.

    api1.png

  2. Create a test candidate:
    a) 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. But first, you need to convert a file to gz format  before performing uploading a file:

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

    api2.png


    api3.png


    b) 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.

    Please find below screenshots how to use base64 encoder:

    a) Search base64 in google.

    api6.png


    b) Cclick 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) Cick 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 the url: (Sample 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 sure 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: (sample) 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 '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"

            }

          ]

        }



    d) You will receive the 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 guide we downloaded all documents for a candidate. We can download a single document using attachment ID or form code by below api calls.

  1. 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"

            },

  2. 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, Documents, Onboarding Panels, ONB 1.0, OBD , KBA , LOD-SF-OBD-API , Webservices & API's , How To

Product

SAP SuccessFactors Onboarding all versions