Anypoint MQ REST APIs

 

MuleSoft has provided out of the box Anypoint MQ 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

Anypoint MQ REST APIs

 

Set Query Parameter

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

Anypoint MQ REST APIs

 

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

Anypoint MQ REST APIs

 

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

Anypoint MQ REST APIs

 

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\"}"
}
  
Thank you for taking out time to read the above post. Hope you found it useful. In case of any questions, feel free to comment below. Also, if you are keen on knowing about a specific topic, happy to explore your recommendations as well.
 
For any latest updates or posts on our website, you can follow us on LinkedIn. Look forward to connecting with you there.


Share this:
Subscribe
Notify of
guest
4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Mulesoft Training In Hyderabad

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

mulesoft training online

nice post

Dennis Hardjo
Dennis Hardjo
7 months ago

Can you specify these AMQ-related endpoints in MuleSoft Exchange definitions and or as Design Center resources during RAML/OAS modelling ??

SAP FICO Training in Hyderabad
SAP FICO Training in Hyderabad
6 months ago

I’m so happy to have read this blog. Thank you for sharing, sir.