cancel
Showing results for 
Search instead for 
Did you mean: 

How to write sap sdk requestBuilder for successfactors odata navigation with filter

former_member25214
Participant
0 Kudos

Hi Coomunity,

I'm trying to query successfactors OData APIs using SAP SDK, I want to filter user based on userid and fetch firstname and lastname of the user. Below is my code i wrote but it seems I'm not doing it the right way. It would be great i someone can help me on this.

Any documentation would be great, I was following the tutorials provided on saphanaacademy on youtube.

// SUCCESSFACTORS INEGRATION POC APIs
  // ---------------------------------------------------------------
  const {
    PerPersonal,
    PerPerson,
    PerEmail
  } = require("./generated/sfo-data-service");

  const getCandidates = ({
    req
  }) => {
    return new Promise(async (resolve, reject) => {
      try {
        console.log(req);
        const result = PerPersonal.requestBuilder()
          .getAll()
          .select(
            PerPersonal.FIRST_NAME,
            PerPersonal.LAST_NAME,
            PerPersonal.PERSON_NAV
            .select(
              PerPerson.DATE_OF_BIRTH,
              PerPerson.PERSON_ID,
            ))
          .execute({
            destinationName: "sfapi"
          });
        console.log(result)
        resolve(result);
      } catch (error) {
        reject(error);
      }

    })

  };

  app.get("/admin/action/successfactors/user/get", async (req, res) => {
    try {
      const results = await getCandidates(req);

      return res.type("application/json").status(200).send(JSON.stringify(results))
    } catch (e) {
      return res.type("text/plain").status(500).send(`ERROR: ${e.toString()}`)
    }
  });
  // SUCCESSFACTORS INEGRATION
  // ----------------------------------------------------------------


Response : [
    {
        "firstName": "Евгения",
        "lastName": "Павлова",
        "personNav": {
            "dateOfBirth": "1954-02-13T00:00:00.000Z",
            "personId": "771"
        }
    },
    {
        "firstName": "Анастасия",
        "lastName": "Мухина",
        "personNav": {
            "dateOfBirth": "1990-08-18T00:00:00.000Z",
            "personId": "772"
        }
    },
    {
        "firstName": "Александр",
        "lastName": "Купанов",
        "personNav": {
            "dateOfBirth": "1958-01-12T00:00:00.000Z",
            "personId": "773"
        }
    }

]


I want to filter the user based on its personId , so that I can get Names and date of birth.

I tried to access UserID but it shows below error,

ERROR: Error: get request to https://apisalesdemo4.successfactors.com/odata/v2 failed! [COE0003]Bad property expression: PerPerson/userId; PerPerson/userId is not viewable
{"code":"COE_BAD_PROPERTY_EXPRESSION","message":{"lang":"en-US","value":"[COE0003]Bad property expression: PerPerson/userId; PerPerson/userId is not viewable"}

Accepted Solutions (1)

Accepted Solutions (1)

Junjie
Advisor
Advisor

Hi prakritidevverma ,

thank you for approaching us.

In general, it is always helpful, if you can provide more details like:

1. What's the current issue of your code snippets? Is there any error occurred? If yes, could you please provide the stack trace? If no, what did you get from the request? What's the expected behaviour?

2. Which successfactors API are you using?

I found some issues in your code, please try the following example:

const result = PerPersonal.requestBuilder()
          .getAll()
          .select(
            PerPersonal.FIRST_NAME,
            PerPersonal.LAST_NAME
          )
          .filter(
            PerPerson.PERSON_ID.equals('771')
          )
          .execute({
            destinationName: "sfapi"
          });

Find more details:

Please find more tutorials here.

Also, here you can find the official documentation.

former_member25214
Participant
0 Kudos

Hi dsfas ,

Thanks for instant reply and resources as well. I have updated the my post, let me know if still missing something.

Junjie
Advisor
Advisor

Hi prakritidevverma ,

I'm a bit confused.

I see your response with 3 people, but you also showed me the error message.

Since you also wanted to use a filter, if you just want to know how to apply a filter, then I'll give you an example below:

await PerPersonal.requestBuilder().getAll().select(
  PerPersonal.FIRST_NAME,
  PerPersonal.LAST_NAME,
  PerPersonal.PERSON_NAV
    .select(
      PerPerson.DATE_OF_BIRTH,
      PerPerson.PERSON_ID,
    )
  )
  .filter(
    PerPersonal.PERSON_NAV.filter(
      PerPerson.PERSON_ID.equals(123)
    )
  )
  .execute(destination);

Please note, for odata v2, it's only possible to filter on the 1 to 1 navigation property.

former_member25214
Participant
0 Kudos

Thanks for snippet code. This was what I was looking for.

Answers (0)