Json update custom field using API

Your question may already have an answer on the community forum. Please search for related topics, and then read through the guidelines before creating a new topic.

Here’s an outline with best practices for making your inquiry.

My question:
How to update custom field using API

Details (like screenshots):
I need to update OrganizationalUnit, Personnel Number and JobTitle from CSV file.
I am able to do that for username and display name.

I am using below code and able to populate username and display name but not custom fields.

Please can someone help here

{
“userName”: “{{Match by email}}”,
“displayName”: “{{Internal alias}}”,
“custom_fields”: [
{
“field”: “OrganizationalUnit”,
“value”: “ABC”
},
{
“field”: “PersonnelNumber”,
“value”: “BCD”
},
{
“field”: “JobTitle”,
“value”: “CDE”
}
]
}

image

How I found the problem:
All mentioned above

I’ve already tried:
All mentioned above

Not sure if this is relevant, I put this into the Postman tests tab and defined it as an array. It complained about the quotes. “ instead of ". Once I re-formatted all of the quotes then it took the array ok, and appears to be populated correctly.

var array = [
    {
        "userName": "[email protected]",
        "displayName": "Name",
        "custom_fields": [ 
            {
                "field": "OrganizationalUnit",
                "value": "ABC"
            },
            {
                "field": "PersonnelNumber",
                "value": "BCD"
            },
            {
                "field": "JobTitle",
                "value": "CDE"
            }
        ]
    }
]

console.log(array);

image

Thank you so much for your reply and help.

Is it at all possible that we can write the code without using array? My requirement is to read data from file. I am able to read data for username and display name but not for any of the custom fields.

@gotoavishek

I’m not 100% sure what you are trying to achieve here.
You haven’t actually posted any code, just a snippet of what appears to be JSON.
Do you have any code that you can post that might elaborate on what you are trying to achieve?

Sounds like you have a CSV file that contains the data you want to update.

This is done by giving the CSV file appropriate headers for each column, which are then referenced by data.variableName when run through the collection runner. (I assume here that you are retrieving the CSV information by selecting your data file\CSV though the run settings).

For example…

var userName = data.username
var OU = data.organizationalunit, 
var personnelNo = data.personnelNumber 
var JobTitle = data.jobtitle

Then based on each line of that CSV, you want to send those details to an API?

Which I’m guessing (and this is a complete guess) requires a JSON file like in your example.

On face value, you would just include the variable name as you did for userName and displayName. {{OU}}, {{JobTitle}}, etc.

Thanks again for your reply.

Apologies for not putting my query in detail earlier.

Hope I can make my query clearer this time.

My requirement is to send data from CSV file to API which you have guessed it correctly in your previous response.

In my API I have created few custom fields such as Organization Unit, Personnel Number, job title etc. The fields such as userName and displayName are default in API and it is not part of custom field.

From postman when i am trying to read data for all default and custom field, i am able to read data for default one but not for custom fields. In postman Body i am writing my code in raw segment using json.
{
“userName”: “{{Match by email}}”,
“displayName”: “{{Internal alias}}”,
“custom_fields”: [
{
“field”: “OrganizationalUnit”,
“value”: “{{OrganizationalUnit}}”
},
{
“field”: “PersonnelNumber”,
“value”: “{{Personnelnumber}}”
},
{
“field”: “JobTitle”,
“value”: “{{JobTitle}}”
}
]
}

My excel file header is as below

  • Internal alias
  • Match by email
  • OrganizationalUnit
  • Personnelnumber
  • OrganizationalKey
  • JobTitle

Please let me know if still my query is not clear.

Based on what you are showing, it looks correct.

Have you tried writing those fields to a variable and checking them in the console.log, to ensure they are indeed being populated.

If they are being populated, then I suspect its something to do with the JSON and the way you are mixing objects, values and arrays as its showing square brackets in the response which normally means an array.

However on face value, the JSON looks good to me.

Finally this has worked :slight_smile:

Changed a bit and now it’s reading. Thank you for your all help and support.

{
“userName”: “{{Match by email}}”,
“displayName”: “{{Internal alias}}”,
“urn:ietf:params:scim:schemas:siilo:association:member”: {
“customProfile”: [
{
“field”: “OrganizationalUnit”,
“value”: [“{{OrganizationalUnit}}”]
},
{
“field”: “PersonnelNumber”,
“value”: [“{{Personnelnumber}}”]
},
{
“field”: “JobTitle”,
“value”: [“{{JobTitle}}”]
}
]
}
}

Fair play. I did have a go myself, and it appeared to work with the format as you had it originally.

CSV…

image

Request body

image

Request that was sent.

However, glad its now working.

yeah you are right Mike and that’s the correct solution.

Difference between your json code and mine is the way the custom field was built in and it’s all coz of API. I think i was struggling coz of that.

Anyways that was new for me and had good learning. Thanks again!!!