Org level JSc Resource file , data not returned

I am trying to store a json data in a jsc resource file as a org level resource , but when i am trying to get data in proxy it is not being returned.

sample data in resourcefile :

context.setVariable("samplePayload" ,{ "customVal": { "customVal1": "customVal2", "customval3": "customVal4", "customVal5": { "sample1": "value1", "sample2": {} } } }

POST curl :

curl -X POST \ 'https://api.enterprise.apigee.com/v1/o/test-org/e/test/resourcefiles?name=orgConfig.js&type=jsc' \ -H 'accept: application/json' \ -H 'cache-control: no-cache' \ -H 'content-type: application/octet-stream' \ -H 'postman-token: f86d0cbf-76eb-d929-94a9-47fe35826a8c' \ -d 'context.setVariable("samplePayload" ,{ "customVal": { "customVal1": "customVal2", "customval3": "customVal4", "customVal5": { "sample1": "value1", "sample2": {} } } }'

GET curl :

curl -X GET \ https://api.enterprise.apigee.com/v1/o/test-org/e/test/resourcefiles/orgConfig.js \ -H 'accept: application/json' \ -H 'cache-control: no-cache' \ -H 'content-type: application/octet-stream' \ -H 'postman-token: 93c2ad40-19af-39b9-6d1d-e61eb1edc2a1'

Response :

{ "resourceFile": [] }

0 4 122
4 REPLIES 4

Your question is not answerable with the level of detail you've provided.

Show your JS policy configuration, please.

Also specify the NAME(S) of the resources in your org.

As you describe what is going on, try to be as specific as you can.

Hi @Dino,

Please find more details the java script content that i was trying to add is just one line of setting JSON object in context which is available for all proxies:

Js File data :

context.setVariable("samplePayload" ,{ "customVal": { "customVal1": "customVal2", "customval3": "customVal4", "customVal5": { "sample1": "value1", "sample2": {} } } })

POST Curl call (This was missed in previous comment)

"curl -X POST \ 'https://api.enterprise.apigee.com/v1/o/sample-org/resourcefiles?name=orgConfig.js&type=jsc' \ -H 'accept: application/json' \ -H 'cache-control: no-cache' \ -H 'content-type: application/octet-stream' \ -H 'postman-token: 0a9e494c-31f9-8d96-3fe3-9e7965b74aa5' \ -d 'context.setVariable("samplePayload" ,{ "customVal": { "customVal1": "customVal2", "customval3": "customVal4", "customVal5": { "sample1": "value1", "sample2": {} } } })'"

Once run the curl to create the org level jsc resource , and then try to retrieve it , i get below response :

GET call :

"https://api.enterprise.apigee.com//v1/o/sample-org/resourcefiles"

{ "resourceFile": [ { "name": "orgConfig.js", "type": "jsc" } ] }

GET call for resource file :

"https://api.enterprise.apigee.com//v1/o/sample-org/resourcefiles/orgConfig.js"

Response :

{ "resourceFile": [] }

I don't have any resources currently in my org .

This is the first resource file I am trying to create:

Please let me know if you need more details.

Hi @Dino-at-Google, Can you check this ?

The GET call must include the resource type in the url path.

Try this:

GET :mgmtserver /v1 /o /:org /e /:env /resourcefiles /jsc /orgConfig.js

Also, in your JS, I think you want the stringified version:

var samplePayload = { ... } ;
context.setVariable("samplePayload" , JSON.stringify(samplePayload));