MuleSoft has provided out of the box REST APIs to push message to Anypoint MQ – right now it only support JSON request while calling the APIs

For this we have to make 2 REST call to push message to MQ

First Call to get access token

REST POST –  https://mq-us-east-1.anypoint.mulesoft.com/api/v1/authorize

Copy client id and secret from Anypoint platform – (to know more how to copy)

Create REST call in postman

Set Key Headers

  • Accept – application/json
  • Content-Type – application/x-www-form-urlencoded

Set Query Parameter

  • client_id – <id>
  • client_secret – <secret>
  • grant_type – client_credentials

Once request is sent then we can see access_token in response – validity of access token is for some minutes only and after sometime we have to again regenerate for new calls

Second call – to push message to Anypoint MQ and for this we have to create the URL like –

https://mq-us-east-1.anypoint.mulesoft.com/api/v1/organizations/<orgId>/environments/<envId>/destinations/<MQname>/messages/<Messageid>

  • orgId and envId – we can get from earlier call response
  • MQname – name of the MQ on which we want to send message
  • MessageId – Message id

e.g.

https://mq-us-east-1.anypoint.mulesoft.com/api/v1/organizations/45df43534-4983-88cc-daac630eb357/environments/33sfdf56-95db-4983-88cc-23423sdfsdf/destinations/MyQueue/messages/56

Copy the access token from last call and add it as Bearer Token in Authorization

Add same http header as before

Now make a request to push message after setting up the Body

And we see the successful response and same message is now available in MQ

Please note – while send a message body the JSON structure should be like this

{
“body”:”My message payload”
}

So the content of body element should be of string so in this case if we have to pass JSON structure then we have to remove all the new line character from JSON String and add escape sequence – \

e.g.

{
“body”:”{\”Hello\”:\”World\”}”
}

One Thought to “Anypoint MQ REST APIs”

  1. Thanks for such a valuable informative post on mule soft. By going through it most of my ongoing doubts regarding mule soft have been cleared. Looking forward for more of such informative posts.
    For more details on Mule soft Training In Hyderabad, please vist https://www.kellytechno.com/Hyderabad/Course/MuleSoft-Training-In-Hyderabad

Leave a Comment