How to get all custom attributes of app without knowing the name

I have a requirement to retrieve all the custom attributes of an app and send it to backend.

Now, when I say ALL, i don't know the attribute name. I am wondering how can I achieve it? I believe i need a javascript. Any suggestion will help.

0 5 618
5 REPLIES 5

Nope, you don't necessarily need JavaScript. You could do it with ExtractVariables.

Supposing you want to transmit all those params as an XML fragment in a header, you could see these results:

$ curl -i -H apikey:$APIKEY https://$ORG-$ENV.apigee.net/appattributes-1/t1
HTTP/1.1 200 OK
Date: Fri, 12 Oct 2018 18:36:59 GMT
Content-Type: application/json
Content-Length: 23
Connection: keep-alive
attrs-in-xml-form: <Attributes><Attribute><Name>DisplayName</Name><Value>AttributesApp</Value></Attribute><Attribute><Name>Notes</Name><Value/></Attribute><Attribute><Name>attr2</Name><Value>value2</Value></Attribute><Attribute><Name>custom-attr-1</Name><Value>value1</Value></Attribute></Attributes>


{
    "status" : "ok"
}

If you're not happy with all the angle brackets, you can use XMLToJSON to get them in JSON form.

$ curl -i -H apikey:$APIKEY https://$ORG-$ENV.apigee.net/appattributes-1/t2
HTTP/1.1 200 OK
Date: Fri, 12 Oct 2018 18:37:02 GMT
Content-Type: application/json
Content-Length: 23
Connection: keep-alive
attrs-json: {"Attribute":[{"Value":"AttributesApp","Name":"DisplayName"},{"Value":{},"Name":"Notes"},{"Value":"value2","Name":"attr2"},{"Value":"value1","Name":"custom-attr-1"}]}


{
    "status" : "ok"
}

If you don't like either of those options, a JavaScript would help you format the attributes into a string that is more appealing. For example, you could transform the name and value members into a regular JS hash. It would look like:

{
 "DisplayName":"AttributesApp",
 "Notes": {}, 
 "attr2":"value2",
 "custom-attr-1":"value1"
}

Please find attached the API Proxy that produces the first two forms. To use it you will need to create an API Product that contains this proxy, and then create an App authorized for the product. Pass the credential (consumer key) for that app as the apikey.

apiproxy-app-attributes.zip

Hi @Dino-at-Google

Sorry, my question was not quite clear about my requirement.

In my proxy, after access token validation, I need to get all the custom attributes of the app and send them as header parameters as key-value.

Right now, I have stored one custom attribute with JSON object. then in my Javascript, i loop through the JSON and send the values in the header.

But I don't want JSON object approach, I want to store the values as separate attributes in the app. Also, I don't want javascript.

Wondering is there a way.

"I want to shape a header in a particular way, and I want to do it without javascript".

Well, that's not possible. if you constrain the problem that way, no. There is no way.

You can do it if you relax either of those constraints.

You can shape your header in any way you like with JavaScript . Just build on the example I provided above.

Any reason why you don't want to use JavaScript?

No particular reason, in general, it is suggested to avoid JS policy, isn't it? Maybe I am wrong.

"it is suggested" ? By whom? I don't know where you got that idea.