API Connect

API Connect

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.


#API Connect
#Applicationintegration
#APIConnect
 View Only
  • 1.  How to pass context varaiblr to a policy

    Posted 21 days ago

    Hi Teams,

    I want to know about how I can used my Context variable my which is set in gateway script 
    var apim = require('apim')
    var body = apim.getvariable('message.body');
    var bankId = body.item(0).getElementsByTagName("bankId").item(0).textContent;
    var serviceId = body.item(0).getElementsByTagName("serviceId").item(0).textContent;
    apim.setvariable("serviceId",serviceId); 

    I want to be used seviceId value on assembly rate-limite


    I have tried this $(serviceId) and also this serviceId it didn't work. 

    Please suggested how can I used it.

    Thank you,



    ------------------------------
    Shah Wajahat
    ------------------------------


  • 2.  RE: How to pass context varaiblr to a policy

    Posted 19 days ago

    Dear Team:

    Please update



    ------------------------------
    Shah Wajahat
    ------------------------------



  • 3.  RE: How to pass context varaiblr to a policy

    Posted 19 days ago

    In the product plan, go to source and try make a plan like the one below:

    default-plan:
        title: Default Plan
        description: Default Plan
        assembly-rate-limits:
          test:
            - value: 3/3minute
              hard-limit: true
              cache-only: false
              is-client: true
              use-api-name: false
              use-app-id: false
              use-client-id: false
              dynamic-value: $(context.serviceId)

    change the values of calls/minute as of your needs, and then in the ratelimit node in the API, use the plan-named option, then in rate limit name put the name of the assembly, in this case "test".

    Hope my help is useful.



    ------------------------------
    Diogo Lourenco
    ------------------------------



  • 4.  RE: How to pass context varaiblr to a policy

    Posted 19 days ago

    Hi Diogo Lourenc>
    Thank you for your response. The issue is that I am not using a subscription for this API, and the calls are being made without a client_id. I have created multiple rate limit objects in the DataPower assembly.

    i want to use this object dynamically for example serviceId CCMSRQ001 Used this CCMSRQ001ratelimit object.



    ------------------------------
    Shah Wajahat
    ------------------------------



  • 5.  RE: How to pass context varaiblr to a policy

    Posted 19 days ago

    what you can try is make a gateway script that checks the value of that serviceId and stores it in a context variable, then make a switch that depending of the context variable value goes to different rate limits node, each node using one of the assembly plans you have configured.

    Just an idea.



    ------------------------------
    Diogo Lourenco
    ------------------------------



  • 6.  RE: How to pass context varaiblr to a policy

    Posted 19 days ago

    Hi Diogo Lourenco
     I just want to use my context variable value in

    highlighted on image i don't want to be used switch because in future there is multiple object 



    ------------------------------
    Shah Wajahat
    ------------------------------



  • 7.  RE: How to pass context varaiblr to a policy

    Posted 16 days ago
    In IBM API Connect (APIC), you can use Gateway Script variables inside policies such as Rate Limit, but only if you store the value in a context variable that APIC makes available to the assembly.
     
    var apim = require('apim')
    var body = apim.getvariable('message.body');
    var bankId = body.item(0).getElementsByTagName("bankId").item(0).textContent;
    var serviceId = body.item(0).getElementsByTagName("serviceId").item(0).textContent;
    apim.setvariable("serviceId", serviceId);
     
    This correctly stores the variable into the context.
     
    apim.setvariable('context.serviceId', serviceId);using the context. prefix is best practice
     
    Open the Rate Limit policy → Advanced section → Configure "Rate Limit By".
     
    Use custom key then use the context variable like this: $(context.serviceId) or if you stored it without prefix:$(serviceId)
    Rate Limit Policy
     
    Rate Type: per Consumer / per Key (depending on your use case)
     
    Rate Limit Key:
    $(context.serviceId) This makes the rate limit apply per serviceId, meaning each serviceId gets its own bucket.
     
    Make sure the GatewayScript policy is placed above the Rate Limit policy in the assembly flow.
     
    For XML body
     
    Note that message.body is a DOM Node, so your use of getElementsByTagName() is correct.


    ------------------------------
    karthik kumar
    ------------------------------



  • 8.  RE: How to pass context varaiblr to a policy

    Posted 16 days ago

    Hi karthik kumar

    I updated my gatewayscript code as you requested show in below 

    var apim - require('apim')
    var body - apin.getvariable('message.body');
    var bankId - body.item(0).getElementsByTagNane("bankId").item(0).textContent;
    var serviceld - body.item(0).getElementsByTagName("serviceId").item(0).textContent;
    apim.setvariable('context.serviceId' ,serviceld);

    apim.setvariable("body",body);

    I am using the gatewayscript before the ratelimit policy as show in screenshot

    But I get an error

    I am passing my context value like this


    I have defined the rate limit object in DataPower.



    ------------------------------
    Shah Wajahat
    ------------------------------



  • 9.  RE: How to pass context varaiblr to a policy

    Posted 16 days ago
    That error does not come from your GatewayScript.The error is not related to context variables, even if serviceId was empty, you would NOT get this error.
    This error appears before execution when APIC validates the rate-limit configuration. It comes from API Connect / DataPower when the rate-limit policy is deployed.
    Your API assembly references a Rate Limit object by name
    But the DataPower gateway (Stg-Int01) does NOT have that Rate Limit object defined.

    Common Error :
    Creating the rate-limit in Sandbox or API Manager drafts, but not publishing it to the real gateway.
    Each gateway needs its own copy..
    Even though you created the rate-limit object somewhere, it is not deployed to that gateway.

    You must:
     
    1. Go to API Manager → Drafts → Gateway Services
                 Find the gateway:Stg-Int01
    2. Open it → Rate Limits tab
                 Check if your rate-limit object (the one used in assembly) exists.
                 If it is missing:
                        Click Add
                       Create a rate limit with the SAME NAME used in the API assembly.


    ------------------------------
    karthik kumar
    ------------------------------



  • 10.  RE: How to pass context varaiblr to a policy

    Posted 15 days ago

    Hi karthik kumar,

    I have already created rate limit object in gateway stg01 with as you see in my screenshot above.

    but when we use this CCMSRQ001
    but when pass context variable it gives an error show as above.



    ------------------------------
    Shah Wajahat
    ------------------------------



  • 11.  RE: How to pass context varaiblr to a policy

    Posted 14 days ago
    APIC does not share rate-limit objects across domains.
    Even though you created a rate-limit on gateway stg01, the error shows that the API assembly is using Source = gateway-named and Rate limit name = CCMSRQ001.
    This means the DataPower gateway (Stg-Int01) must contain a rate-limit object with that exact name.
    APIC is reporting that the gateway cannot find CCMSRQ001 under its own Rate Limits.
    Please verify the following:
    • Open API Manager → Drafts → Gateway Services → Stg-Int01 → Rate Limits
    • Ensure a rate-limit exists with the exact name CCMSRQ001 (case-sensitive).
    • Make sure it is published to the gateway (not only saved as a draft).
    • Confirm it's created in the same gateway domain where your API runs.
    • Double-check for any naming differences (spaces, case, typos).
    Most common causes
    1. The rate-limit exists, but the NAME is not an exact match
    Check:
    • No lowercase vs uppercase differences
    • No trailing spaces
    • No version-number added accidentally
    • No hidden characters

    2. The rate-limit was created on the wrong gateway

    You must create it under:
    API Manager → Drafts → Gateway Services → Stg-Int01 → Rate Limits
    Many people create it under:
    • Sandbox gateway or another environment (dev/stg/uat/prod)
    • Catalog settings (catalog-named) instead of gateway-named
    • But for gateway-named, it MUST be under Stg-Int01.
    3. The rate-limit was created but never PUBLISHED to the gateway
    • Draft objects do not count.
    • If the rate-limit is still in "draft" status, the gateway does not have it yet.You must:
      • Save
      • Publish / Push to Stg-Int01
    4. The gateway domain mismatch
    • If your API is running in a domain (for example: prod, sandbox, stg-int01-dp), the rate-limit must be created in the same domain.


    ------------------------------
    karthik kumar
    ------------------------------