Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Params with a "null" value are not included in request. #495

Closed
ssylvia opened this issue Mar 27, 2019 · 4 comments
Closed

Params with a "null" value are not included in request. #495

ssylvia opened this issue Mar 27, 2019 · 4 comments

Comments

@ssylvia
Copy link
Member

ssylvia commented Mar 27, 2019

I'm using the updateItem method to set the itemDetails and itemData on a Story Map. If a user clicks "Unpublish", we need to remove this itemData. This should be able to be accomplished with the following:

updateItem({
  authentication: this.userSession,
  item: this.itemDetails,
  params: {
    // Clear item data
    text: null,
  },
})

However, the text: null is never included as a param in the request.

Currently, I have to make a second request if I want to update the itemDetails and remove the itemData at the same time:

addItemJsonData({
  authentication: this.userSession,
  id: this.itemId,
  data: null,
});
@jgravois
Copy link
Contributor

right now to send a parameter with an empty key you need to pass "".

https://github.com/Esri/arcgis-rest-js/blob/master/packages/arcgis-rest-request/src/utils/process-params.ts#L62-L65

would that work for you in this scenario?

@jgravois
Copy link
Contributor

jgravois commented Mar 27, 2019

i did a little testing and i was not able to reproduce the behavior you described.

for me, this syntax results in an error

addItemJsonData({
  authentication,
  id,
  data: null,
});

{"error":{"code":400,"messageCode":"CONT_0057","message":"Invalid JSON in 'text' parameter.","details":[]}}

i just opened #496 with a tweak that resolves the error, but does not get to the root of your problem.

with those changes:

  1. data: null causes the parameter to be dropped entirely (which is consistent with the rest of the library).
  2. data: "" ensures an empty param is passed.

I assume the second option is what you want. Unfortunately, the Portal API appears to ignore &text=&, even if you send the additional parameter below.

addItemJsonData({
  authentication,
  id,
  data: "",
  params: { clearEmptyFields: true } 
});

because of the hair pulling i did in #474, i can safely say that clearEmptyFields is only honored by string fields. you can pass a "," to clear tags but i don't know of another way to clear item data (other than passing {}).

@ssylvia
Copy link
Member Author

ssylvia commented Mar 28, 2019

Thanks @jgravois. I was originally testing by looking at the output in AGO Assistant. With further investigation on my end, it looks like passing null is not what I want as you suspected. I reached out to few members of the Portal API team and they were unaware of a method to actually clear the itemData once it's been added.

The empty text string is probably what we want. I'll submit an issue with the Portal API team to get this added. I'll close this issue for now.

@ssylvia ssylvia closed this as completed Mar 28, 2019
@jgravois
Copy link
Contributor

I was originally testing by looking at the output in AGO Assistant.

i feel you there. i've been tricked doing that too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants